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());
|
if ( g.ast!=null && internalOption_PrintGrammarTree ) System.out.println(g.ast.toStringTree());
|
||||||
//g.ast.inspect();
|
//g.ast.inspect();
|
||||||
|
|
||||||
|
if ( errMgr.getNumErrors()>0 ) return;
|
||||||
|
|
||||||
// MAKE SURE GRAMMAR IS SEMANTICALLY CORRECT (FILL IN GRAMMAR OBJECT)
|
// MAKE SURE GRAMMAR IS SEMANTICALLY CORRECT (FILL IN GRAMMAR OBJECT)
|
||||||
SemanticPipeline sem = new SemanticPipeline(g);
|
SemanticPipeline sem = new SemanticPipeline(g);
|
||||||
sem.process();
|
sem.process();
|
||||||
|
@ -368,12 +370,13 @@ public class Tool {
|
||||||
ToolANTLRParser p = new ToolANTLRParser(tokens, this);
|
ToolANTLRParser p = new ToolANTLRParser(tokens, this);
|
||||||
p.setTreeAdaptor(adaptor);
|
p.setTreeAdaptor(adaptor);
|
||||||
ParserRuleReturnScope r = p.grammarSpec();
|
ParserRuleReturnScope r = p.grammarSpec();
|
||||||
GrammarRootAST root = (GrammarRootAST)r.getTree();
|
GrammarAST root = (GrammarAST)r.getTree();
|
||||||
if ( root instanceof GrammarRootAST) {
|
if ( root instanceof GrammarRootAST) {
|
||||||
root.hasErrors = p.getNumberOfSyntaxErrors()>0;
|
((GrammarRootAST)root).hasErrors = p.getNumberOfSyntaxErrors()>0;
|
||||||
root.tokens = tokens;
|
((GrammarRootAST)root).tokens = tokens;
|
||||||
|
return ((GrammarRootAST)root);
|
||||||
}
|
}
|
||||||
return root;
|
return null;
|
||||||
}
|
}
|
||||||
catch (RecognitionException re) {
|
catch (RecognitionException re) {
|
||||||
// TODO: do we gen errors now?
|
// TODO: do we gen errors now?
|
||||||
|
|
|
@ -198,6 +198,8 @@ public class Grammar implements AttributeResolver {
|
||||||
in.name = fileName;
|
in.name = fileName;
|
||||||
|
|
||||||
this.ast = tool.load(in);
|
this.ast = tool.load(in);
|
||||||
|
if ( ast==null ) return;
|
||||||
|
|
||||||
// ensure each node has pointer to surrounding grammar
|
// ensure each node has pointer to surrounding grammar
|
||||||
final Grammar thiz = this;
|
final Grammar thiz = this;
|
||||||
TreeVisitor v = new TreeVisitor(new GrammarASTAdaptor());
|
TreeVisitor v = new TreeVisitor(new GrammarASTAdaptor());
|
||||||
|
|
Loading…
Reference in New Issue