diff --git a/tool/test/org/antlr/v4/test/BaseTest.java b/tool/test/org/antlr/v4/test/BaseTest.java index 50d6afe35..a64acd186 100644 --- a/tool/test/org/antlr/v4/test/BaseTest.java +++ b/tool/test/org/antlr/v4/test/BaseTest.java @@ -1025,6 +1025,7 @@ public abstract class BaseTest { "import org.antlr.v4.runtime.*;\n" + "import org.antlr.v4.runtime.tree.*;\n" + "import org.antlr.v4.runtime.atn.*;\n" + + "import java.util.Arrays;\n"+ "\n" + "public class Test {\n" + " public static void main(String[] args) throws Exception {\n" + @@ -1035,7 +1036,7 @@ public abstract class BaseTest { " parser.setBuildParseTree(true);\n" + " \n"+ " ParserRuleContext tree = parser.();\n" + - " profiler.dump();\n" + + " System.out.println(Arrays.toString(profiler.getDecisionInfo()));\n" + " ParseTreeWalker.DEFAULT.walk(new TreeShapeListener(), tree);\n" + " }\n" + "\n" + diff --git a/tool/test/org/antlr/v4/test/TestParserProfiler.java b/tool/test/org/antlr/v4/test/TestParserProfiler.java index f75d6e896..4c9fb9141 100644 --- a/tool/test/org/antlr/v4/test/TestParserProfiler.java +++ b/tool/test/org/antlr/v4/test/TestParserProfiler.java @@ -208,6 +208,7 @@ public class TestParserProfiler extends BaseTest { // pred forces to // ambig and ('+' e)* tail recursion forces lookahead to fall out of e + // any non-precedence predicates are always evaluated as true by the interpreter DecisionInfo[] info = interpAndGetDecisionInfo(lg, g, "s", "a+b+c;"); // at "+b" it uses k=1 and enters loop then calls e for b... // e matches and d=2 uses "+c;" for k=3 @@ -220,6 +221,32 @@ public class TestParserProfiler extends BaseTest { assertEquals(expecting, Arrays.toString(info)); } + @Test public void testProfilerGeneratedCode() throws Exception { + String grammar = + "grammar T;\n" + + "s : a+ ID EOF ;\n" + + "a : ID ';'{}\n" + + " | ID '.'\n" + + " ;\n"+ + "WS : [ \\r\\t\\n]+ -> channel(HIDDEN) ;\n" + + "SEMI : ';' ;\n" + + "DOT : '.' ;\n" + + "ID : [a-zA-Z]+ ;\n" + + "INT : [0-9]+ ;\n" + + "PLUS : '+' ;\n" + + "MULT : '*' ;\n"; + + String found = execParser("T.g4", grammar, "TParser", "TLexer", "s", + "xyz;abc;z.q", false, true); + String expecting = + "[{decision=0, contextSensitivities=0, errors=0, ambiguities=0, SLL_lookahead=6, SLL_ATNTransitions=4, " + + "SLL_DFATransitions=2, LL_Fallback=0, LL_lookahead=0, LL_ATNTransitions=0}," + + " {decision=1, contextSensitivities=0, errors=0, ambiguities=0, SLL_lookahead=6, " + + "SLL_ATNTransitions=3, SLL_DFATransitions=3, LL_Fallback=0, LL_lookahead=0, LL_ATNTransitions=0}]\n"; + assertEquals(expecting, found); + assertEquals(null, stderrDuringParse); + } + public DecisionInfo[] interpAndGetDecisionInfo( LexerGrammar lg, Grammar g, String startRule, String... input)