use of org.antlr.v4.runtime.misc.IntegerList in project antlr4 by antlr.
the class BaseBrowserTest method getTypesFromString.
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.misc.IntegerList in project antlr4 by tunnelvisionlabs.
the class TestATNInterpreter method checkMatchedAlt.
public void checkMatchedAlt(LexerGrammar lg, final Grammar g, String inputString, int expected) {
ATN lexatn = createATN(lg, true);
LexerATNSimulator lexInterp = new LexerATNSimulator(lexatn);
IntegerList types = getTokenTypesViaATN(inputString, lexInterp);
System.out.println(types);
g.importVocab(lg);
ParserATNFactory f = new ParserATNFactory(g);
ATN atn = f.createATN();
IntTokenStream input = new IntTokenStream(types);
System.out.println("input=" + input.types);
ParserInterpreterForTesting interp = new ParserInterpreterForTesting(g, input);
ATNState startState = atn.ruleToStartState[g.getRule("a").index];
if (startState.transition(0).target instanceof BlockStartState) {
startState = startState.transition(0).target;
}
DOTGenerator dot = new DOTGenerator(g);
System.out.println(dot.getDOT(atn.ruleToStartState[g.getRule("a").index]));
Rule r = g.getRule("e");
if (r != null)
System.out.println(dot.getDOT(atn.ruleToStartState[r.index]));
int result = interp.matchATN(input, startState);
assertEquals(expected, result);
}
use of org.antlr.v4.runtime.misc.IntegerList in project antlr4 by tunnelvisionlabs.
the class TestATNParserPrediction method checkDFAConstruction.
public void checkDFAConstruction(LexerGrammar lg, Grammar g, int decision, String[] inputString, String[] dfaString) {
// Tool.internalOption_ShowATNConfigsInDFA = true;
ATN lexatn = createATN(lg, true);
LexerATNSimulator lexInterp = new LexerATNSimulator(lexatn);
semanticProcess(lg);
g.importVocab(lg);
semanticProcess(g);
ParserInterpreterForTesting interp = new ParserInterpreterForTesting(g, null);
for (int i = 0; i < inputString.length; i++) {
// Check DFA
IntegerList types = getTokenTypesViaATN(inputString[i], lexInterp);
System.out.println(types);
TokenStream input = new IntTokenStream(types);
try {
interp.adaptivePredict(input, decision, ParserRuleContext.emptyContext());
} catch (NoViableAltException nvae) {
nvae.printStackTrace(System.err);
}
DFA dfa = interp.getATNSimulator().atn.decisionToDFA[decision];
assertEquals(dfaString[i], dfa.toString(g.getVocabulary(), g.rules.keySet().toArray(new String[g.rules.size()])));
}
}
use of org.antlr.v4.runtime.misc.IntegerList in project antlr4 by tunnelvisionlabs.
the class BaseTest 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.misc.IntegerList in project antlr4 by tunnelvisionlabs.
the class TestIntegerList method emptyListToEmptyCharArray.
@Test
public void emptyListToEmptyCharArray() {
IntegerList l = new IntegerList();
assertArrayEquals(new char[0], Utils.toCharArray(l));
}
Aggregations