use of org.antlr.v4.runtime.atn.LookaheadEventInfo in project antlr4 by antlr.
the class TestLookaheadTrees method testLookaheadTrees.
public void testLookaheadTrees(LexerGrammar lg, Grammar g, String input, String startRuleName, int decision, String[] expectedTrees) {
int startRuleIndex = g.getRule(startRuleName).index;
InterpreterTreeTextProvider nodeTextProvider = new InterpreterTreeTextProvider(g.getRuleNames());
LexerInterpreter lexEngine = lg.createLexerInterpreter(new ANTLRInputStream(input));
CommonTokenStream tokens = new CommonTokenStream(lexEngine);
GrammarParserInterpreter parser = g.createGrammarParserInterpreter(tokens);
parser.setProfile(true);
ParseTree t = parser.parse(startRuleIndex);
DecisionInfo decisionInfo = parser.getParseInfo().getDecisionInfo()[decision];
LookaheadEventInfo lookaheadEventInfo = decisionInfo.SLL_MaxLookEvent;
List<ParserRuleContext> lookaheadParseTrees = GrammarParserInterpreter.getLookaheadParseTrees(g, parser, tokens, startRuleIndex, lookaheadEventInfo.decision, lookaheadEventInfo.startIndex, lookaheadEventInfo.stopIndex);
assertEquals(expectedTrees.length, lookaheadParseTrees.size());
for (int i = 0; i < lookaheadParseTrees.size(); i++) {
ParserRuleContext lt = lookaheadParseTrees.get(i);
assertEquals(expectedTrees[i], Trees.toStringTree(lt, nodeTextProvider));
}
}
Aggregations