Search in sources :

Example 1 with LexerATNSimulator

use of org.antlr.v4.runtime.atn.LexerATNSimulator in project antlr4 by antlr.

the class BaseGoTest method getTokenTypes.

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;
    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;
}
Also used : LexerATNSimulator(org.antlr.v4.runtime.atn.LexerATNSimulator) ArrayList(java.util.ArrayList) STGroupString(org.stringtemplate.v4.STGroupString) BaseRuntimeTest.antlrOnString(org.antlr.v4.test.runtime.BaseRuntimeTest.antlrOnString) DFA(org.antlr.v4.runtime.dfa.DFA)

Example 2 with LexerATNSimulator

use of org.antlr.v4.runtime.atn.LexerATNSimulator in project antlr4 by antlr.

the class BaseGoTest method getTokenTypesViaATN.

public IntegerList getTokenTypesViaATN(String input, LexerATNSimulator lexerATN) {
    ANTLRInputStream in = new ANTLRInputStream(input);
    IntegerList tokenTypes = new IntegerList();
    int ttype;
    do {
        ttype = lexerATN.match(in, Lexer.DEFAULT_MODE);
        tokenTypes.add(ttype);
    } while (ttype != Token.EOF);
    return tokenTypes;
}
Also used : IntegerList(org.antlr.v4.runtime.misc.IntegerList) ANTLRInputStream(org.antlr.v4.runtime.ANTLRInputStream)

Example 3 with LexerATNSimulator

use of org.antlr.v4.runtime.atn.LexerATNSimulator in project antlr4 by antlr.

the class BaseCppTest method getTokenTypesViaATN.

public IntegerList getTokenTypesViaATN(String input, LexerATNSimulator lexerATN) {
    ANTLRInputStream in = new ANTLRInputStream(input);
    IntegerList tokenTypes = new IntegerList();
    int ttype;
    do {
        ttype = lexerATN.match(in, Lexer.DEFAULT_MODE);
        tokenTypes.add(ttype);
    } while (ttype != Token.EOF);
    return tokenTypes;
}
Also used : IntegerList(org.antlr.v4.runtime.misc.IntegerList) ANTLRInputStream(org.antlr.v4.runtime.ANTLRInputStream)

Example 4 with LexerATNSimulator

use of org.antlr.v4.runtime.atn.LexerATNSimulator in project antlr4 by antlr.

the class BaseJavaTest method getTokenTypes.

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;
    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;
}
Also used : LexerATNSimulator(org.antlr.v4.runtime.atn.LexerATNSimulator) ArrayList(java.util.ArrayList) STGroupString(org.stringtemplate.v4.STGroupString) DFA(org.antlr.v4.runtime.dfa.DFA)

Example 5 with LexerATNSimulator

use of org.antlr.v4.runtime.atn.LexerATNSimulator in project antlr4 by antlr.

the class BaseJavaTest method getTokenTypesViaATN.

public IntegerList getTokenTypesViaATN(String input, LexerATNSimulator lexerATN) {
    ANTLRInputStream in = new ANTLRInputStream(input);
    IntegerList tokenTypes = new IntegerList();
    int ttype;
    do {
        ttype = lexerATN.match(in, Lexer.DEFAULT_MODE);
        tokenTypes.add(ttype);
    } while (ttype != Token.EOF);
    return tokenTypes;
}
Also used : IntegerList(org.antlr.v4.runtime.misc.IntegerList) ANTLRInputStream(org.antlr.v4.runtime.ANTLRInputStream)

Aggregations

LexerATNSimulator (org.antlr.v4.runtime.atn.LexerATNSimulator)11 DFA (org.antlr.v4.runtime.dfa.DFA)11 IntegerList (org.antlr.v4.runtime.misc.IntegerList)9 ArrayList (java.util.ArrayList)7 ANTLRInputStream (org.antlr.v4.runtime.ANTLRInputStream)7 STGroupString (org.stringtemplate.v4.STGroupString)6 BaseRuntimeTest.antlrOnString (org.antlr.v4.test.runtime.BaseRuntimeTest.antlrOnString)5 ATN (org.antlr.v4.runtime.atn.ATN)4 ExecutionException (java.util.concurrent.ExecutionException)2 ParserATNFactory (org.antlr.v4.automata.ParserATNFactory)2 CharStream (org.antlr.v4.runtime.CharStream)2 Lexer (org.antlr.v4.runtime.Lexer)2 Parser (org.antlr.v4.runtime.Parser)2 TokenStream (org.antlr.v4.runtime.TokenStream)2 ParserATNSimulator (org.antlr.v4.runtime.atn.ParserATNSimulator)2 PredictionContextCache (org.antlr.v4.runtime.atn.PredictionContextCache)2 DOTGenerator (org.antlr.v4.tool.DOTGenerator)2 Rule (org.antlr.v4.tool.Rule)2 File (java.io.File)1 IOException (java.io.IOException)1