forked from jasder/antlr
Merge pull request #616 from parrt/test-profiler-with-generated-code
test profiler with generated code. dump profile information using toStri...
This commit is contained in:
commit
0c0fd67082
|
@ -1052,6 +1052,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" +
|
||||
|
@ -1062,7 +1063,7 @@ public abstract class BaseTest {
|
|||
" parser.setBuildParseTree(true);\n" +
|
||||
" <profile>\n"+
|
||||
" ParserRuleContext tree = parser.<parserStartRuleName>();\n" +
|
||||
" <if(profile)>profiler.dump();<endif>\n" +
|
||||
" <if(profile)>System.out.println(Arrays.toString(profiler.getDecisionInfo()));<endif>\n" +
|
||||
" ParseTreeWalker.DEFAULT.walk(new TreeShapeListener(), tree);\n" +
|
||||
" }\n" +
|
||||
"\n" +
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue