use of org.antlr.v4.tool.GrammarParserInterpreter in project antlr4 by antlr.
the class TestUnicodeGrammar method parseTreeForGrammarWithInput.
private static String parseTreeForGrammarWithInput(String grammarText, String rootRule, String inputText) throws Exception {
Grammar grammar = new Grammar(grammarText);
LexerInterpreter lexEngine = grammar.createLexerInterpreter(CharStreams.fromString(inputText));
CommonTokenStream tokens = new CommonTokenStream(lexEngine);
GrammarParserInterpreter parser = grammar.createGrammarParserInterpreter(tokens);
ParseTree parseTree = parser.parse(grammar.rules.get(rootRule).index);
InterpreterTreeTextProvider nodeTextProvider = new InterpreterTreeTextProvider(grammar.getRuleNames());
return Trees.toStringTree(parseTree, nodeTextProvider);
}
Aggregations