1 package polyglot.frontend; 2 3 import java.io.*; 4 import polyglot.ast.*; 5 import polyglot.util.*; 6 import polyglot.frontend.Compiler; 7 import polyglot.main.Report; 8 9 13 public class ParserPass extends AbstractPass 14 { 15 Job job; 16 Compiler compiler; 17 18 public ParserPass(Pass.ID id, Compiler compiler, Job job) { 19 super(id); 20 this.compiler = compiler; 21 this.job = job; 22 } 23 24 public boolean run() { 25 ErrorQueue eq = compiler.errorQueue(); 26 FileSource source = (FileSource) job.source(); 27 28 try { 29 Reader reader = source.open(); 30 31 Parser p = compiler.sourceExtension().parser(reader, source, eq); 32 33 if (Report.should_report(Report.frontend, 2)) 34 Report.report(2, "Using parser " + p); 35 36 Node ast = p.parse(); 37 38 source.close(); 39 40 if (ast != null) { 41 job.ast(ast); 42 return true; 43 } 44 45 return false; 46 } 47 catch (IOException e) { 48 eq.enqueue(ErrorInfo.IO_ERROR, e.getMessage()); 49 return false; 50 } 51 } 52 53 public String toString() { 54 return id + "(" + job.source() + ")"; 55 } 56 } 57 | Popular Tags |