Example #1
0
 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);
 }
Example #2
0
  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);
  }