Search in sources :

Example 11 with DOTGenerator

use of org.antlr.v4.tool.DOTGenerator 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 12 with DOTGenerator

use of org.antlr.v4.tool.DOTGenerator in project antlr4 by antlr.

the class Tool method generateATNs.

public void generateATNs(Grammar g) {
    DOTGenerator dotGenerator = new DOTGenerator(g);
    List<Grammar> grammars = new ArrayList<Grammar>();
    grammars.add(g);
    List<Grammar> imported = g.getAllImportedGrammars();
    if (imported != null)
        grammars.addAll(imported);
    for (Grammar ig : grammars) {
        for (Rule r : ig.rules.values()) {
            try {
                String dot = dotGenerator.getDOT(g.atn.ruleToStartState[r.index], g.isLexer());
                if (dot != null) {
                    writeDOTFile(g, r, dot);
                }
            } catch (IOException ioe) {
                errMgr.toolError(ErrorType.CANNOT_WRITE_FILE, ioe);
            }
        }
    }
}
Also used : DOTGenerator(org.antlr.v4.tool.DOTGenerator) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ArrayList(java.util.ArrayList) Grammar(org.antlr.v4.tool.Grammar) LexerGrammar(org.antlr.v4.tool.LexerGrammar) Rule(org.antlr.v4.tool.Rule) IOException(java.io.IOException)

Aggregations

ATN (org.antlr.v4.runtime.atn.ATN)10 DOTGenerator (org.antlr.v4.tool.DOTGenerator)10 Rule (org.antlr.v4.tool.Rule)9 ATNState (org.antlr.v4.runtime.atn.ATNState)8 ParserATNFactory (org.antlr.v4.automata.ParserATNFactory)7 ATNPrinter (org.antlr.v4.automata.ATNPrinter)6 STGroupString (org.stringtemplate.v4.STGroupString)6 BaseRuntimeTest.antlrOnString (org.antlr.v4.test.runtime.BaseRuntimeTest.antlrOnString)5 Grammar (org.antlr.v4.tool.Grammar)3 LexerATNSimulator (org.antlr.v4.runtime.atn.LexerATNSimulator)2 DFA (org.antlr.v4.runtime.dfa.DFA)2 IntegerList (org.antlr.v4.runtime.misc.IntegerList)2 LexerGrammar (org.antlr.v4.tool.LexerGrammar)2 Test (org.junit.Test)2 TestRule (org.junit.rules.TestRule)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)1 CharStream (org.antlr.v4.runtime.CharStream)1 ParserRuleContext (org.antlr.v4.runtime.ParserRuleContext)1