public ATN getATN() { if (atn == null) { ParserATNFactory factory = new ParserATNFactory(this); atn = factory.createATN(); } return atn; }
void checkTokensRule(LexerGrammar g, String modeName, String expecting) { // if ( g.ast!=null && !g.ast.hasErrors ) { // System.out.println(g.ast.toStringTree()); // Tool antlr = new Tool(); // SemanticPipeline sem = new SemanticPipeline(g); // sem.process(); // if ( g.getImportedGrammars()!=null ) { // process imported grammars (if any) // for (Grammar imp : g.getImportedGrammars()) { // antlr.processNonCombinedGrammar(imp); // } // } // } 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); }
ATN createATN(Grammar g) { if (g.atn != null) return g.atn; semanticProcess(g); ParserATNFactory f = new ParserATNFactory(g); if (g.isLexer()) f = new LexerATNFactory((LexerGrammar) g); g.atn = f.createATN(); return g.atn; }
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); }
protected ATN createATN(Grammar g, boolean useSerializer) { if (g.atn == null) { semanticProcess(g); assertEquals(0, g.tool.getNumErrors()); ParserATNFactory f; if (g.isLexer()) { f = new LexerATNFactory((LexerGrammar) g); } else { f = new ParserATNFactory(g); } g.atn = f.createATN(); assertEquals(0, g.tool.getNumErrors()); } ATN atn = g.atn; if (useSerializer) { char[] serialized = ATNSerializer.getSerializedAsChars(atn); return new ATNDeserializer().deserialize(serialized); } return atn; }