Example usage for org.antlr.v4.runtime.atn ATNState BASIC

List of usage examples for org.antlr.v4.runtime.atn ATNState BASIC

Introduction

In this page you can find the example usage for org.antlr.v4.runtime.atn ATNState BASIC.

Prototype

int BASIC

To view the source code for org.antlr.v4.runtime.atn ATNState BASIC.

Click Source Link

Usage

From source file:io.github.hjuergens.time.GenerateParseTreeAST.java

License:Apache License

/**
 * <a href="https://stackoverflow.com/questions/10614659/no-viable-alternative-at-input"></a>
 *//*from ww w  .  j a  v  a  2 s .c om*/
@Test(expectedExceptions = java.lang.NoSuchFieldError.class)
public void dotTree() {

    // the expression
    String src = "(ICOM LIKE '%bridge%' or ICOM LIKE '%Munich%')";

    // create a lexer & parser
    //DatesLexer lexer = new DatesLexer(new ANTLRStringStream(src));
    //DatesParser parser = new DatesParser(new CommonTokenStream(lexer));

    DatesLexer lexer = new DatesLexer(new ANTLRInputStream(src));
    DatesParser parser = new DatesParser(new CommonTokenStream(lexer));

    // invoke the entry point of the parser (the parse() method) and get the AST
    Tree tree = parser.date();
    String grammarFileName = lexer.getGrammarFileName();
    log.info("grammar file name=" + grammarFileName);

    // print the DOT representation of the AST 
    Grammar grammar = Grammar.load(grammarFileName);
    DOTGenerator gen = new DOTGenerator(grammar);

    ATNState startState = new ATNState() {
        @Override
        public int getStateType() {
            return ATNState.BASIC;
        }
    };
    String st = gen.getDOT(startState);
    log.info(st);
}