| 646 | } |
| 647 | |
| 648 | public GrammarRootAST parse(String fileName, CharStream in) { |
| 649 | try { |
| 650 | GrammarASTAdaptor adaptor = new GrammarASTAdaptor(in); |
| 651 | ToolANTLRLexer lexer = new ToolANTLRLexer(in, this); |
| 652 | CommonTokenStream tokens = new CommonTokenStream(lexer); |
| 653 | lexer.tokens = tokens; |
| 654 | ToolANTLRParser p = new ToolANTLRParser(tokens, this); |
| 655 | p.setTreeAdaptor(adaptor); |
| 656 | ParserRuleReturnScope r = p.grammarSpec(); |
| 657 | GrammarAST root = (GrammarAST) r.getTree(); |
| 658 | if (root instanceof GrammarRootAST) { |
| 659 | ((GrammarRootAST) root).hasErrors = lexer.getNumberOfSyntaxErrors() > 0 || p.getNumberOfSyntaxErrors() > 0; |
| 660 | assert ((GrammarRootAST) root).tokenStream == tokens; |
| 661 | if (grammarOptions != null) { |
| 662 | ((GrammarRootAST) root).cmdLineOptions = grammarOptions; |
| 663 | } |
| 664 | return ((GrammarRootAST) root); |
| 665 | } |
| 666 | return null; |
| 667 | } |
| 668 | catch (RecognitionException re) { |
| 669 | // TODO: do we gen errors now? |
| 670 | ErrorManager.internalError("can't generate this message at moment; antlr recovers"); |
| 671 | } |
| 672 | return null; |
| 673 | } |
| 674 | |
| 675 | public void generateATNs(Grammar g) { |
| 676 | DOTGenerator dotGenerator = new DOTGenerator(g); |