use of org.antlr.v4.tool.DOTGenerator in project antlr4 by antlr.
the class BaseJavaTest method checkRuleATN.
public void checkRuleATN(Grammar g, String ruleName, String expecting) {
// DOTGenerator dot = new DOTGenerator(g);
// System.out.println(dot.getDOT(g.atn.ruleToStartState[g.getRule(ruleName).index]));
Rule r = g.getRule(ruleName);
ATNState startState = g.getATN().ruleToStartState[r.index];
ATNPrinter serializer = new ATNPrinter(g, startState);
String result = serializer.asString();
//System.out.print(result);
assertEquals(expecting, result);
}
use of org.antlr.v4.tool.DOTGenerator in project antlr4 by antlr.
the class BaseCppTest method checkRuleATN.
void checkRuleATN(Grammar g, String ruleName, String expecting) {
ParserATNFactory f = new ParserATNFactory(g);
ATN atn = f.createATN();
DOTGenerator dot = new DOTGenerator(g);
System.out.println(dot.getDOT(atn.ruleToStartState[g.getRule(ruleName).index]));
Rule r = g.getRule(ruleName);
ATNState startState = atn.ruleToStartState[r.index];
ATNPrinter serializer = new ATNPrinter(g, startState);
String result = serializer.asString();
//System.out.print(result);
assertEquals(expecting, result);
}
use of org.antlr.v4.tool.DOTGenerator in project antlr4 by antlr.
the class TestATNSerialization method testNot.
@Test
public void testNot() throws Exception {
Grammar g = new Grammar("parser grammar T;\n" + "tokens {A, B, C}\n" + "a : ~A ;");
String expecting = "max type 3\n" + "0:RULE_START 0\n" + "1:RULE_STOP 0\n" + "2:BASIC 0\n" + "3:BASIC 0\n" + "4:BASIC 0\n" + "rule 0:0\n" + "0:A..A\n" + "0->2 EPSILON 0,0,0\n" + "2->3 NOT_SET 0,0,0\n" + "3->1 EPSILON 0,0,0\n";
ATN atn = createATN(g, true);
DOTGenerator gen = new DOTGenerator(g);
String result = ATNSerializer.getDecoded(atn, Arrays.asList(g.getTokenNames()));
assertEquals(expecting, result);
}
use of org.antlr.v4.tool.DOTGenerator in project antlr4 by antlr.
the class BasePythonTest method checkRuleATN.
void checkRuleATN(Grammar g, String ruleName, String expecting) {
ParserATNFactory f = new ParserATNFactory(g);
ATN atn = f.createATN();
DOTGenerator dot = new DOTGenerator(g);
System.out.println(dot.getDOT(atn.ruleToStartState[g.getRule(ruleName).index]));
Rule r = g.getRule(ruleName);
ATNState startState = atn.ruleToStartState[r.index];
ATNPrinter serializer = new ATNPrinter(g, startState);
String result = serializer.asString();
//System.out.print(result);
assertEquals(expecting, result);
}
use of org.antlr.v4.tool.DOTGenerator in project antlr4 by antlr.
the class TestExpectedTokens method testFollowIncludedInLeftRecursiveRule.
// Test for https://github.com/antlr/antlr4/issues/1480
// can't reproduce
@Test
public void testFollowIncludedInLeftRecursiveRule() throws Exception {
String gtext = "grammar T;\n" + "s : expr EOF ;\n" + "expr : L expr R\n" + " | expr PLUS expr\n" + " | ID\n" + " ;\n";
Grammar g = new Grammar(gtext);
String atnText = "RuleStart_expr_2->BlockStart_13\n" + "BlockStart_13->s7\n" + "BlockStart_13->s12\n" + "s7-action_1:-1->s8\n" + "s12-ID->BlockEnd_14\n" + "s8-L->s9\n" + "BlockEnd_14->StarLoopEntry_20\n" + "s9-expr->RuleStart_expr_2\n" + "StarLoopEntry_20->StarBlockStart_18\n" + "StarLoopEntry_20->s21\n" + "s10-R->s11\n" + "StarBlockStart_18->s15\n" + "s21->RuleStop_expr_3\n" + "s11->BlockEnd_14\n" + "s15-2 >= _p->s16\n" + "RuleStop_expr_3->s5\n" + "RuleStop_expr_3->s10\n" + "RuleStop_expr_3->BlockEnd_19\n" + "s16-PLUS->s17\n" + "s17-expr->RuleStart_expr_2\n" + "BlockEnd_19->StarLoopBack_22\n" + "StarLoopBack_22->StarLoopEntry_20\n";
checkRuleATN(g, "expr", atnText);
ATN atn = g.getATN();
// DOTGenerator gen = new DOTGenerator(g);
// String dot = gen.getDOT(atn.states.get(2), g.getRuleNames(), false);
// System.out.println(dot);
// Simulate call stack after input '(x' from rule s
ParserRuleContext callStackFrom_s = new ParserRuleContext(null, 4);
ParserRuleContext callStackFrom_expr = new ParserRuleContext(callStackFrom_s, 9);
int afterID = 14;
IntervalSet tokens = atn.getExpectedTokens(afterID, callStackFrom_expr);
assertEquals("{R, PLUS}", tokens.toString(g.getTokenNames()));
// Simulate call stack after input '(x' from within rule expr
callStackFrom_expr = new ParserRuleContext(null, 9);
tokens = atn.getExpectedTokens(afterID, callStackFrom_expr);
assertEquals("{R, PLUS}", tokens.toString(g.getTokenNames()));
}
Aggregations