Search in sources :

Example 1 with ATNBuilder

use of org.antlr.v4.parse.ATNBuilder in project antlr4 by antlr.

the class ParserATNFactory method _createATN.

protected void _createATN(Collection<Rule> rules) {
    createRuleStartAndStopATNStates();
    GrammarASTAdaptor adaptor = new GrammarASTAdaptor();
    for (Rule r : rules) {
        // find rule's block
        GrammarAST blk = (GrammarAST) r.ast.getFirstChildWithType(ANTLRParser.BLOCK);
        CommonTreeNodeStream nodes = new CommonTreeNodeStream(adaptor, blk);
        ATNBuilder b = new ATNBuilder(nodes, this);
        try {
            setCurrentRuleName(r.name);
            Handle h = b.ruleBlock(null);
            rule(r.ast, r.name, h);
        } catch (RecognitionException re) {
            ErrorManager.fatalInternalError("bad grammar AST structure", re);
        }
    }
}
Also used : ATNBuilder(org.antlr.v4.parse.ATNBuilder) GrammarAST(org.antlr.v4.tool.ast.GrammarAST) GrammarASTAdaptor(org.antlr.v4.parse.GrammarASTAdaptor) Rule(org.antlr.v4.tool.Rule) LeftRecursiveRule(org.antlr.v4.tool.LeftRecursiveRule) RecognitionException(org.antlr.runtime.RecognitionException) CommonTreeNodeStream(org.antlr.runtime.tree.CommonTreeNodeStream)

Aggregations

RecognitionException (org.antlr.runtime.RecognitionException)1 CommonTreeNodeStream (org.antlr.runtime.tree.CommonTreeNodeStream)1 ATNBuilder (org.antlr.v4.parse.ATNBuilder)1 GrammarASTAdaptor (org.antlr.v4.parse.GrammarASTAdaptor)1 LeftRecursiveRule (org.antlr.v4.tool.LeftRecursiveRule)1 Rule (org.antlr.v4.tool.Rule)1 GrammarAST (org.antlr.v4.tool.ast.GrammarAST)1