Search in sources :

Example 11 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)9 ATNState (org.antlr.v4.runtime.atn.ATNState)9 Rule (org.antlr.v4.tool.Rule)9 ParserATNFactory (org.antlr.v4.automata.ParserATNFactory)7 ATN (org.antlr.v4.runtime.atn.ATN)7 STGroupString (org.stringtemplate.v4.STGroupString)7 DOTGenerator (org.antlr.v4.tool.DOTGenerator)6 BaseRuntimeTest.antlrOnString (org.antlr.v4.test.runtime.BaseRuntimeTest.antlrOnString)5 TestRule (org.junit.rules.TestRule)3 LexerATNFactory (org.antlr.v4.automata.LexerATNFactory)2 RuleStartState (org.antlr.v4.runtime.atn.RuleStartState)2 RuleStopState (org.antlr.v4.runtime.atn.RuleStopState)2 LeftRecursiveRule (org.antlr.v4.tool.LeftRecursiveRule)2 NotNull (org.antlr.v4.runtime.misc.NotNull)1