Example usage for org.antlr.v4.runtime.atn LexerATNSimulator match

List of usage examples for org.antlr.v4.runtime.atn LexerATNSimulator match

Introduction

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

Prototype

public int match(CharStream input, int mode) 

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;/*from   ww w.  j  a  v a2 s.  co 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;
}