}
}
public void parseAndBuildAST(Reader r) {
// BUILD AST FROM GRAMMAR
ANTLRLexer lexer;
try {
lexer = new ANTLRLexer(new ANTLRReaderStream(r));
} catch (IOException e) {
ErrorManager.internalError("unexpected stream error from parsing "+fileName, e);
return;
}
lexer.setFileName(this.getFileName());
tokenBuffer = new CommonTokenStream(lexer);
ANTLRParser parser = ANTLRParser.createParser(tokenBuffer);
parser.setFileName(this.getFileName());
ANTLRParser.grammar__return result = null;
try {
result = parser.grammar_(this);
}
catch (RecognitionException re) {
ErrorManager.internalError("unexpected parser recognition error from "+fileName, re);
}
dealWithTreeFilterMode(); // tree grammar and filter=true?
if ( lexer.hasASTOperator && !buildAST() ) {
Object value = getOption("output");
if ( value == null ) {
ErrorManager.grammarWarning(ErrorManager.MSG_REWRITE_OR_OP_WITH_NO_OUTPUT_OPTION,
this, null);
setOption("output", "AST", null);
}
else {
ErrorManager.grammarError(ErrorManager.MSG_AST_OP_WITH_NON_AST_OUTPUT_OPTION,
this, null, value);
}
}
setGrammarTree(result.getTree());
//if ( grammarTree!=null ) System.out.println("grammar tree: "+grammarTree.toStringTree());
grammarTree.setUnknownTokenBoundaries();
setFileName(lexer.getFileName()); // the lexer #src might change name
if ( grammarTree.findFirstType(ANTLRParser.RULE)==null ) {
ErrorManager.error(ErrorManager.MSG_NO_RULES, getFileName());
}
}