Example usage for org.antlr.v4.runtime.dfa DFA DFA

List of usage examples for org.antlr.v4.runtime.dfa DFA DFA

Introduction

In this page you can find the example usage for org.antlr.v4.runtime.dfa DFA DFA.

Prototype

public DFA(DecisionState atnStartState) 

Source Link

Usage

From source file:net.certiv.json.test.base.AbstractBase.java

License:Open Source License

public List<String> getTokenTypes(LexerGrammar lg, ATN atn, CharStream input) {
    LexerATNSimulator interp = new LexerATNSimulator(atn,
            new DFA[] { new DFA(atn.modeToStartState.get(Lexer.DEFAULT_MODE)) }, null);
    List<String> tokenTypes = new ArrayList<String>();
    int ttype;//  w w  w.jav  a 2 s. c o m
    boolean hitEOF = false;
    do {
        if (hitEOF) {
            tokenTypes.add("EOF");
            break;
        }
        int t = input.LA(1);
        ttype = interp.match(input, Lexer.DEFAULT_MODE);
        if (ttype == Token.EOF) {
            tokenTypes.add("EOF");
        } else {
            tokenTypes.add(lg.typeToTokenList.get(ttype));
        }

        if (t == IntStream.EOF) {
            hitEOF = true;
        }
    } while (ttype != Token.EOF);
    return tokenTypes;
}