use of org.antlr.v4.runtime.dfa.DFA 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;
}
use of org.antlr.v4.runtime.dfa.DFA in project antlr4 by antlr.
the class BaseCppTest method checkRuleDFA.
void checkRuleDFA(Grammar g, DecisionState blk, String expecting) throws Exception {
DFA dfa = createDFA(g, blk);
String result = null;
if (dfa != null)
result = dfa.toString();
assertEquals(expecting, result);
}
use of org.antlr.v4.runtime.dfa.DFA 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;
}
use of org.antlr.v4.runtime.dfa.DFA in project antlr4 by antlr.
the class BaseJavaTest method getTypesFromString.
// public void minimizeDFA(DFA dfa) {
// DFAMinimizer dmin = new DFAMinimizer(dfa);
// dfa.minimized = dmin.minimize();
// }
IntegerList getTypesFromString(Grammar g, String expecting) {
IntegerList expectingTokenTypes = new IntegerList();
if (expecting != null && !expecting.trim().isEmpty()) {
for (String tname : expecting.replace(" ", "").split(",")) {
int ttype = g.getTokenType(tname);
expectingTokenTypes.add(ttype);
}
}
return expectingTokenTypes;
}
use of org.antlr.v4.runtime.dfa.DFA in project antlr4 by antlr.
the class BaseJavaTest method checkRuleDFA.
void checkRuleDFA(Grammar g, DecisionState blk, String expecting) throws Exception {
DFA dfa = createDFA(g, blk);
String result = null;
if (dfa != null)
result = dfa.toString();
assertEquals(expecting, result);
}
Aggregations