List of usage examples for org.antlr.v4 Tool parseGrammarFromString
public GrammarRootAST parseGrammarFromString(String grammar)
From source file:org.opencypher.tools.grammar.Antlr4TestUtils.java
License:Apache License
private static Grammar createGrammar(String resource, org.opencypher.grammar.Grammar.ParserOption... options) { // We need to do some custom post-processing to get the lexer rules right ByteArrayOutputStream out = new ByteArrayOutputStream(); String grammarString = null;//from ww w .j av a2s . co m try { Antlr4.write(Fixture.grammarResource(Antlr4.class, resource, options), out); grammarString = out.toString(UTF_8.name()); System.out.println(grammarString); } catch (Throwable t) { t.printStackTrace(); fail("Unexpected error while writing antlr grammar"); } org.antlr.v4.Tool tool = new org.antlr.v4.Tool(); GrammarRootAST ast = tool.parseGrammarFromString(grammarString); Grammar grammar = tool.createGrammar(ast); tool.process(grammar, false); return grammar; }