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

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

Introduction

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

Prototype

public LexerATNSimulator(ATN atn, DFA[] decisionToDFA, PredictionContextCache sharedContextCache) 

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;//  ww  w . j av a 2s. c om
    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;
}