Search in sources :

Example 6 with ATNPrinter

use of org.antlr.v4.automata.ATNPrinter 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);
}
Also used : ParserATNFactory(org.antlr.v4.automata.ParserATNFactory) DOTGenerator(org.antlr.v4.tool.DOTGenerator) ATNPrinter(org.antlr.v4.automata.ATNPrinter) ATN(org.antlr.v4.runtime.atn.ATN) Rule(org.antlr.v4.tool.Rule) TestRule(org.junit.rules.TestRule) STGroupString(org.stringtemplate.v4.STGroupString) BaseRuntimeTest.antlrOnString(org.antlr.v4.test.runtime.BaseRuntimeTest.antlrOnString) ATNState(org.antlr.v4.runtime.atn.ATNState)

Example 7 with ATNPrinter

use of org.antlr.v4.automata.ATNPrinter in project antlr4 by antlr.

the class BaseNodeTest 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);
}
Also used : ParserATNFactory(org.antlr.v4.automata.ParserATNFactory) DOTGenerator(org.antlr.v4.tool.DOTGenerator) ATNPrinter(org.antlr.v4.automata.ATNPrinter) ATN(org.antlr.v4.runtime.atn.ATN) Rule(org.antlr.v4.tool.Rule) STGroupString(org.stringtemplate.v4.STGroupString) BaseRuntimeTest.antlrOnString(org.antlr.v4.test.runtime.BaseRuntimeTest.antlrOnString) ATNState(org.antlr.v4.runtime.atn.ATNState)

Example 8 with ATNPrinter

use of org.antlr.v4.automata.ATNPrinter in project antlr4 by antlr.

the class TestATNConstruction method checkTokensRule.

void checkTokensRule(LexerGrammar g, String modeName, String expecting) {
    //		}
    if (modeName == null)
        modeName = "DEFAULT_MODE";
    if (g.modes.get(modeName) == null) {
        System.err.println("no such mode " + modeName);
        return;
    }
    ParserATNFactory f = new LexerATNFactory(g);
    ATN nfa = f.createATN();
    ATNState startState = nfa.modeNameToStartState.get(modeName);
    ATNPrinter serializer = new ATNPrinter(g, startState);
    String result = serializer.asString();
    //System.out.print(result);
    assertEquals(expecting, result);
}
Also used : ParserATNFactory(org.antlr.v4.automata.ParserATNFactory) ATNPrinter(org.antlr.v4.automata.ATNPrinter) ATN(org.antlr.v4.runtime.atn.ATN) LexerATNFactory(org.antlr.v4.automata.LexerATNFactory) ATNState(org.antlr.v4.runtime.atn.ATNState)

Aggregations

ATNPrinter (org.antlr.v4.automata.ATNPrinter)7 ATNState (org.antlr.v4.runtime.atn.ATNState)7 Rule (org.antlr.v4.tool.Rule)7 ParserATNFactory (org.antlr.v4.automata.ParserATNFactory)6 ATN (org.antlr.v4.runtime.atn.ATN)6 STGroupString (org.stringtemplate.v4.STGroupString)6 BaseRuntimeTest.antlrOnString (org.antlr.v4.test.runtime.BaseRuntimeTest.antlrOnString)5 DOTGenerator (org.antlr.v4.tool.DOTGenerator)5 TestRule (org.junit.rules.TestRule)2 LexerATNFactory (org.antlr.v4.automata.LexerATNFactory)1 RuleStartState (org.antlr.v4.runtime.atn.RuleStartState)1 RuleStopState (org.antlr.v4.runtime.atn.RuleStopState)1 LeftRecursiveRule (org.antlr.v4.tool.LeftRecursiveRule)1