forked from jasder/antlr
cleaned up a bit so that TestToolSyntaxErrors works. added some cast checks and some bailout upon error before semantic processing
[git-p4: depot-paths = "//depot/code/antlr4/main/": change = 9483]
This commit is contained in:
parent
e00fa44996
commit
0bf1aca47f
|
@ -286,6 +286,8 @@ public class Tool {
|
|||
if ( g.ast!=null && internalOption_PrintGrammarTree ) System.out.println(g.ast.toStringTree());
|
||||
//g.ast.inspect();
|
||||
|
||||
if ( errMgr.getNumErrors()>0 ) return;
|
||||
|
||||
// MAKE SURE GRAMMAR IS SEMANTICALLY CORRECT (FILL IN GRAMMAR OBJECT)
|
||||
SemanticPipeline sem = new SemanticPipeline(g);
|
||||
sem.process();
|
||||
|
@ -368,12 +370,13 @@ public class Tool {
|
|||
ToolANTLRParser p = new ToolANTLRParser(tokens, this);
|
||||
p.setTreeAdaptor(adaptor);
|
||||
ParserRuleReturnScope r = p.grammarSpec();
|
||||
GrammarRootAST root = (GrammarRootAST)r.getTree();
|
||||
GrammarAST root = (GrammarAST)r.getTree();
|
||||
if ( root instanceof GrammarRootAST) {
|
||||
root.hasErrors = p.getNumberOfSyntaxErrors()>0;
|
||||
root.tokens = tokens;
|
||||
((GrammarRootAST)root).hasErrors = p.getNumberOfSyntaxErrors()>0;
|
||||
((GrammarRootAST)root).tokens = tokens;
|
||||
return ((GrammarRootAST)root);
|
||||
}
|
||||
return root;
|
||||
return null;
|
||||
}
|
||||
catch (RecognitionException re) {
|
||||
// TODO: do we gen errors now?
|
||||
|
|
|
@ -198,6 +198,8 @@ public class Grammar implements AttributeResolver {
|
|||
in.name = fileName;
|
||||
|
||||
this.ast = tool.load(in);
|
||||
if ( ast==null ) return;
|
||||
|
||||
// ensure each node has pointer to surrounding grammar
|
||||
final Grammar thiz = this;
|
||||
TreeVisitor v = new TreeVisitor(new GrammarASTAdaptor());
|
||||
|
|
Loading…
Reference in New Issue