List of usage examples for org.antlr.v4.runtime Lexer setInputStream
@Override public void setInputStream(IntStream input)
From source file:nl.lxtreme.libtdl.grammar.TdlFactory.java
License:Apache License
/** * Directly creates a parse tree from the given input using the given * configuration./*from ww w . j a v a2 s . c o m*/ * * @param config * the configuration to use, cannot be <code>null</code>; * @param input * the input to parse, cannot be <code>null</code>. * @return a {@link ParseTree}, never <code>null</code>. */ public static ParseTree createParseTree(TdlConfig config, String input) { Lexer lexer = createLexer(config); lexer.setInputStream(new ANTLRInputStream(input)); Parser parser = createParser(config); parser.setInputStream(new CommonTokenStream(lexer)); TdlDialect dialect = config.getDialect(); switch (dialect) { case BASIC: return ((BasicTdlParser) parser).prog(); case ADVANCED: return ((AdvTdlParser) parser).prog(); default: throw new RuntimeException("Invalid/unknown dialect: " + dialect); } }