diff --git a/runtime-testsuite/resources/org/antlr/v4/test/runtime/cpp/Cpp.test.stg b/runtime-testsuite/resources/org/antlr/v4/test/runtime/cpp/Cpp.test.stg index 47267fcbd..c819da091 100644 --- a/runtime-testsuite/resources/org/antlr/v4/test/runtime/cpp/Cpp.test.stg +++ b/runtime-testsuite/resources/org/antlr/v4/test/runtime/cpp/Cpp.test.stg @@ -158,75 +158,49 @@ string(text) ::= << writeBoolean(o) ::= "truefalse" writeln(s) ::= "std::cout \<\< \<\< std::endl;" - write(s) ::= "std::cout \<\< ;" +writeList(s) ::= << std::cout \<\< \<\< std::endl;>> False() ::= "false" - True() ::= "true" - Not(v) ::= "!" - Assert(s) ::= "" - Cast(t,v) ::= "std::dynamic_pointer_cast\<>()" // Should actually use a more specific name. We may have to use other casts as well. - Append(a,b) ::= " + ->toString()" - Concat(a,b) ::= "" DeclareLocal(s,v) ::= " = " AssertIsList(v) ::= "assert(.size() >= 0);" // Use a method that exists only on a list (vector actually). - AssignLocal(s,v) ::= " = " -InitIntMember(n,v) ::= <%int = ;%> +InitIntMember(n,v) ::= "int = ;" +InitBooleanMember(n,v) ::= "bool = ;" -InitBooleanMember(n,v) ::= <%bool = ;%> - -GetMember(n) ::= <%%> - -SetMember(n,v) ::= <% = %> - -AddMember(n,v) ::= <% += %> - -PlusMember(v,n) ::= <% + ->toString()%> - -MemberEquals(n,v) ::= <% == %> - -ModMemberEquals(n,m,v) ::= <% % == %> - -ModMemberNotEquals(n,m,v) ::= <% % != %> +GetMember(n) ::= "" +SetMember(n,v) ::= " = ;" +AddMember(n,v) ::= " += ;" +PlusMember(v,n) ::= " + " +MemberEquals(n,v) ::= " == " +ModMemberEquals(n,m,v) ::= " % == " +ModMemberNotEquals(n,m,v) ::= " % != " DumpDFA() ::= "dumpDFA();" - Pass() ::= "/* do nothing */" StringList() ::= "std::vector\" - -BuildParseTrees() ::= "setBuildParseTrees(true);" - +BuildParseTrees() ::= "setBuildParseTree(true);" BailErrorStrategy() ::= "_errHandler = std::make_shared\();" ToStringTree(s) ::= "->toStringTree(this)" - Column() ::= "getCharPositionInLine()" - Text() ::= "getText()" - ValEquals(a,b) ::= " == " - TextEquals(a) ::= "getText() == \"\"" - PlusText(a) ::="\"\" + getText()" - InputText() ::= "_input->getText()" - -LTEquals(i, v) ::= "_input->LT().text == " - +LTEquals(i, v) ::= "_input->LT()->getText() == " LANotEquals(i, v) ::= "_input->LA() != " - TokenStartColumnEquals(i) ::= "tokenStartCharPositionInLine == " ImportListener(X) ::= "" @@ -432,13 +406,14 @@ Declare_foo() ::= <" ContextRuleFunction(ctx, rule) ::= "->" StringType() ::= "std::string" diff --git a/runtime-testsuite/resources/org/antlr/v4/test/runtime/csharp/CSharp.test.stg b/runtime-testsuite/resources/org/antlr/v4/test/runtime/csharp/CSharp.test.stg index ea80df666..86bf99172 100644 --- a/runtime-testsuite/resources/org/antlr/v4/test/runtime/csharp/CSharp.test.stg +++ b/runtime-testsuite/resources/org/antlr/v4/test/runtime/csharp/CSharp.test.stg @@ -148,8 +148,8 @@ string(text) ::= << writeBoolean(o) ::= "truefalse" writeln(s) ::= <);>> - write(s) ::= <);>> +writeList(s) ::= <);>> False() ::= "false" diff --git a/runtime-testsuite/resources/org/antlr/v4/test/runtime/java/Java.test.stg b/runtime-testsuite/resources/org/antlr/v4/test/runtime/java/Java.test.stg index fc65d2793..0ffdf3756 100644 --- a/runtime-testsuite/resources/org/antlr/v4/test/runtime/java/Java.test.stg +++ b/runtime-testsuite/resources/org/antlr/v4/test/runtime/java/Java.test.stg @@ -155,8 +155,8 @@ string(text) ::= << writeBoolean(o) ::= "truefalse" writeln(s) ::= <);>> - write(s) ::= <);>> +writeList(s) ::= <);>> False() ::= "false" diff --git a/runtime-testsuite/resources/org/antlr/v4/test/runtime/javascript/explorer/Explorer.test.stg b/runtime-testsuite/resources/org/antlr/v4/test/runtime/javascript/explorer/Explorer.test.stg index 0b7adb9d5..c76f94b52 100644 --- a/runtime-testsuite/resources/org/antlr/v4/test/runtime/javascript/explorer/Explorer.test.stg +++ b/runtime-testsuite/resources/org/antlr/v4/test/runtime/javascript/explorer/Explorer.test.stg @@ -154,8 +154,8 @@ string(text) ::= << writeBoolean(o) ::= "truefalse" writeln(s) ::= < + '\\n';>> - write(s) ::= <;>> +writeList(s) ::= <;>> False() ::= "false" diff --git a/runtime-testsuite/resources/org/antlr/v4/test/runtime/javascript/firefox/Firefox.test.stg b/runtime-testsuite/resources/org/antlr/v4/test/runtime/javascript/firefox/Firefox.test.stg index d931a2323..db69ba5ec 100644 --- a/runtime-testsuite/resources/org/antlr/v4/test/runtime/javascript/firefox/Firefox.test.stg +++ b/runtime-testsuite/resources/org/antlr/v4/test/runtime/javascript/firefox/Firefox.test.stg @@ -154,8 +154,8 @@ string(text) ::= << writeBoolean(o) ::= "truefalse" writeln(s) ::= < + '\\n';>> - write(s) ::= <;>> +writeList(s) ::= <;>> False() ::= "false" diff --git a/runtime-testsuite/resources/org/antlr/v4/test/runtime/javascript/node/Node.test.stg b/runtime-testsuite/resources/org/antlr/v4/test/runtime/javascript/node/Node.test.stg index 7f0d0ccef..7b45df56c 100644 --- a/runtime-testsuite/resources/org/antlr/v4/test/runtime/javascript/node/Node.test.stg +++ b/runtime-testsuite/resources/org/antlr/v4/test/runtime/javascript/node/Node.test.stg @@ -154,8 +154,8 @@ string(text) ::= << writeBoolean(o) ::= "truefalse" writeln(s) ::= <);>> - write(s) ::= <);>> +writeList(s) ::= <);>> False() ::= "false" diff --git a/runtime-testsuite/resources/org/antlr/v4/test/runtime/javascript/safari/Safari.test.stg b/runtime-testsuite/resources/org/antlr/v4/test/runtime/javascript/safari/Safari.test.stg index d91cdee3b..aa6322341 100644 --- a/runtime-testsuite/resources/org/antlr/v4/test/runtime/javascript/safari/Safari.test.stg +++ b/runtime-testsuite/resources/org/antlr/v4/test/runtime/javascript/safari/Safari.test.stg @@ -154,8 +154,8 @@ string(text) ::= << writeBoolean(o) ::= "truefalse" writeln(s) ::= < + '\\n';>> - write(s) ::= <;>> +writeList(s) ::= <;>> False() ::= "false" diff --git a/runtime-testsuite/resources/org/antlr/v4/test/runtime/python2/Python2.test.stg b/runtime-testsuite/resources/org/antlr/v4/test/runtime/python2/Python2.test.stg index 48c7f015a..2737189a1 100644 --- a/runtime-testsuite/resources/org/antlr/v4/test/runtime/python2/Python2.test.stg +++ b/runtime-testsuite/resources/org/antlr/v4/test/runtime/python2/Python2.test.stg @@ -158,8 +158,8 @@ string(text) ::= << writeBoolean(o) ::= "truefalse" writeln(s) ::= <)>> - write(s) ::= <,end='')>> +writeList(s) ::= <)}; separator="+">)>> False() ::= "False" diff --git a/runtime-testsuite/resources/org/antlr/v4/test/runtime/python3/Python3.test.stg b/runtime-testsuite/resources/org/antlr/v4/test/runtime/python3/Python3.test.stg index c2e37d679..a0e71cf4f 100644 --- a/runtime-testsuite/resources/org/antlr/v4/test/runtime/python3/Python3.test.stg +++ b/runtime-testsuite/resources/org/antlr/v4/test/runtime/python3/Python3.test.stg @@ -158,8 +158,8 @@ string(text) ::= << writeBoolean(o) ::= "truefalse" writeln(s) ::= <)>> - write(s) ::= <,end='')>> +writeList(s) ::= <)}; separator="+">)>> False() ::= "False" diff --git a/runtime-testsuite/resources/org/antlr/v4/test/runtime/templates/SemPredEvalParser/PredFromAltTestedInLoopBack.stg b/runtime-testsuite/resources/org/antlr/v4/test/runtime/templates/SemPredEvalParser/PredFromAltTestedInLoopBack.stg index 2ce868b63..488f17a84 100644 --- a/runtime-testsuite/resources/org/antlr/v4/test/runtime/templates/SemPredEvalParser/PredFromAltTestedInLoopBack.stg +++ b/runtime-testsuite/resources/org/antlr/v4/test/runtime/templates/SemPredEvalParser/PredFromAltTestedInLoopBack.stg @@ -18,7 +18,7 @@ file_ @after {} : para para EOF ; para: paraContent NL NL ; -paraContent : ('s'|'x'|{Parser.NL})>}? NL)+ ; +paraContent : ('s'|'x'|{})>}? NL)+ ; NL : '\n' ; s : 's' ; X : 'x' ; diff --git a/runtime-testsuite/resources/org/antlr/v4/test/runtime/templates/SemPredEvalParser/ToLeftWithVaryingPredicate.stg b/runtime-testsuite/resources/org/antlr/v4/test/runtime/templates/SemPredEvalParser/ToLeftWithVaryingPredicate.stg index abc856745..4bd007e35 100644 --- a/runtime-testsuite/resources/org/antlr/v4/test/runtime/templates/SemPredEvalParser/ToLeftWithVaryingPredicate.stg +++ b/runtime-testsuite/resources/org/antlr/v4/test/runtime/templates/SemPredEvalParser/ToLeftWithVaryingPredicate.stg @@ -33,7 +33,7 @@ grammar(grammarName) ::= << grammar ; @members {} s : ({ -} a)+ ; +} a)+ ; a : {}? ID {} | {}? ID {} ; diff --git a/runtime-testsuite/test/org/antlr/v4/test/runtime/cpp/TestParseTrees.java b/runtime-testsuite/test/org/antlr/v4/test/runtime/cpp/TestParseTrees.java index 22c450349..d7d694d0b 100644 --- a/runtime-testsuite/test/org/antlr/v4/test/runtime/cpp/TestParseTrees.java +++ b/runtime-testsuite/test/org/antlr/v4/test/runtime/cpp/TestParseTrees.java @@ -13,11 +13,11 @@ public class TestParseTrees extends BaseCppTest { public void test2AltLoop() throws Exception { mkdir(tmpdir); - StringBuilder grammarBuilder = new StringBuilder(148); + StringBuilder grammarBuilder = new StringBuilder(147); grammarBuilder.append("grammar T;\n"); grammarBuilder.append("s\n"); grammarBuilder.append("@init {\n"); - grammarBuilder.append("setBuildParseTrees(true);\n"); + grammarBuilder.append("setBuildParseTree(true);\n"); grammarBuilder.append("}\n"); grammarBuilder.append("@after {\n"); grammarBuilder.append("std::cout << $r.ctx->toStringTree(this) << std::endl;\n"); @@ -41,11 +41,11 @@ public class TestParseTrees extends BaseCppTest { public void test2Alts() throws Exception { mkdir(tmpdir); - StringBuilder grammarBuilder = new StringBuilder(141); + StringBuilder grammarBuilder = new StringBuilder(140); grammarBuilder.append("grammar T;\n"); grammarBuilder.append("s\n"); grammarBuilder.append("@init {\n"); - grammarBuilder.append("setBuildParseTrees(true);\n"); + grammarBuilder.append("setBuildParseTree(true);\n"); grammarBuilder.append("}\n"); grammarBuilder.append("@after {\n"); grammarBuilder.append("std::cout << $r.ctx->toStringTree(this) << std::endl;\n"); @@ -69,7 +69,7 @@ public class TestParseTrees extends BaseCppTest { public void testAltNum() throws Exception { mkdir(tmpdir); - StringBuilder grammarBuilder = new StringBuilder(588); + StringBuilder grammarBuilder = new StringBuilder(587); grammarBuilder.append("grammar T;\n"); grammarBuilder.append("\n"); grammarBuilder.append("options { contextSuperClass=MyRuleNode; }\n"); @@ -89,7 +89,7 @@ public class TestParseTrees extends BaseCppTest { grammarBuilder.append("\n"); grammarBuilder.append("s\n"); grammarBuilder.append("@init {\n"); - grammarBuilder.append("setBuildParseTrees(true);\n"); + grammarBuilder.append("setBuildParseTree(true);\n"); grammarBuilder.append("}\n"); grammarBuilder.append("@after {\n"); grammarBuilder.append("std::cout << $r.ctx->toStringTree(this) << std::endl;\n"); @@ -118,11 +118,11 @@ public class TestParseTrees extends BaseCppTest { public void testExtraToken() throws Exception { mkdir(tmpdir); - StringBuilder grammarBuilder = new StringBuilder(154); + StringBuilder grammarBuilder = new StringBuilder(153); grammarBuilder.append("grammar T;\n"); grammarBuilder.append("s\n"); grammarBuilder.append("@init {\n"); - grammarBuilder.append("setBuildParseTrees(true);\n"); + grammarBuilder.append("setBuildParseTree(true);\n"); grammarBuilder.append("}\n"); grammarBuilder.append("@after {\n"); grammarBuilder.append("std::cout << $r.ctx->toStringTree(this) << std::endl;\n"); @@ -150,11 +150,11 @@ public class TestParseTrees extends BaseCppTest { public void testNoViableAlt() throws Exception { mkdir(tmpdir); - StringBuilder grammarBuilder = new StringBuilder(156); + StringBuilder grammarBuilder = new StringBuilder(155); grammarBuilder.append("grammar T;\n"); grammarBuilder.append("s\n"); grammarBuilder.append("@init {\n"); - grammarBuilder.append("setBuildParseTrees(true);\n"); + grammarBuilder.append("setBuildParseTree(true);\n"); grammarBuilder.append("}\n"); grammarBuilder.append("@after {\n"); grammarBuilder.append("std::cout << $r.ctx->toStringTree(this) << std::endl;\n"); @@ -182,11 +182,11 @@ public class TestParseTrees extends BaseCppTest { public void testRuleRef() throws Exception { mkdir(tmpdir); - StringBuilder grammarBuilder = new StringBuilder(150); + StringBuilder grammarBuilder = new StringBuilder(149); grammarBuilder.append("grammar T;\n"); grammarBuilder.append("s\n"); grammarBuilder.append("@init {\n"); - grammarBuilder.append("setBuildParseTrees(true);\n"); + grammarBuilder.append("setBuildParseTree(true);\n"); grammarBuilder.append("}\n"); grammarBuilder.append("@after {\n"); grammarBuilder.append("std::cout << $r.ctx->toStringTree(this) << std::endl;\n"); @@ -212,11 +212,11 @@ public class TestParseTrees extends BaseCppTest { public void testSync() throws Exception { mkdir(tmpdir); - StringBuilder grammarBuilder = new StringBuilder(157); + StringBuilder grammarBuilder = new StringBuilder(156); grammarBuilder.append("grammar T;\n"); grammarBuilder.append("s\n"); grammarBuilder.append("@init {\n"); - grammarBuilder.append("setBuildParseTrees(true);\n"); + grammarBuilder.append("setBuildParseTree(true);\n"); grammarBuilder.append("}\n"); grammarBuilder.append("@after {\n"); grammarBuilder.append("std::cout << $r.ctx->toStringTree(this) << std::endl;\n"); @@ -243,11 +243,11 @@ public class TestParseTrees extends BaseCppTest { public void testToken2() throws Exception { mkdir(tmpdir); - StringBuilder grammarBuilder = new StringBuilder(139); + StringBuilder grammarBuilder = new StringBuilder(138); grammarBuilder.append("grammar T;\n"); grammarBuilder.append("s\n"); grammarBuilder.append("@init {\n"); - grammarBuilder.append("setBuildParseTrees(true);\n"); + grammarBuilder.append("setBuildParseTree(true);\n"); grammarBuilder.append("}\n"); grammarBuilder.append("@after {\n"); grammarBuilder.append("std::cout << $r.ctx->toStringTree(this) << std::endl;\n"); @@ -271,11 +271,11 @@ public class TestParseTrees extends BaseCppTest { public void testTokenAndRuleContextString() throws Exception { mkdir(tmpdir); - StringBuilder grammarBuilder = new StringBuilder(218); + StringBuilder grammarBuilder = new StringBuilder(217); grammarBuilder.append("grammar T;\n"); grammarBuilder.append("s\n"); grammarBuilder.append("@init {\n"); - grammarBuilder.append("setBuildParseTrees(true);\n"); + grammarBuilder.append("setBuildParseTree(true);\n"); grammarBuilder.append("}\n"); grammarBuilder.append("@after {\n"); grammarBuilder.append("std::cout << $r.ctx->toStringTree(this) << std::endl;\n"); diff --git a/runtime-testsuite/test/org/antlr/v4/test/runtime/cpp/TestSemPredEvalParser.java b/runtime-testsuite/test/org/antlr/v4/test/runtime/cpp/TestSemPredEvalParser.java index f2c7d1606..b17ce6fcd 100644 --- a/runtime-testsuite/test/org/antlr/v4/test/runtime/cpp/TestSemPredEvalParser.java +++ b/runtime-testsuite/test/org/antlr/v4/test/runtime/cpp/TestSemPredEvalParser.java @@ -13,12 +13,12 @@ public class TestSemPredEvalParser extends BaseCppTest { public void test2UnpredicatedAlts() throws Exception { mkdir(tmpdir); - StringBuilder grammarBuilder = new StringBuilder(316); + StringBuilder grammarBuilder = new StringBuilder(374); grammarBuilder.append("grammar T;\n"); - grammarBuilder.append("s : {_interp.predictionMode = PredictionMode.LL_EXACT_AMBIG_DETECTION} a ';' a; // do 2x: once in ATN, next in DFA\n"); - grammarBuilder.append("a : ID {std::cout << \"alt 1\" << \"\\n\";}\n"); - grammarBuilder.append(" | ID {std::cout << \"alt 2\" << \"\\n\";}\n"); - grammarBuilder.append(" | {false}? ID {std::cout << \"alt 3\" << \"\\n\";}\n"); + grammarBuilder.append("s : {getInterpreter()->setPredictionMode(atn::PredictionMode::LL_EXACT_AMBIG_DETECTION);} a ';' a; // do 2x: once in ATN, next in DFA\n"); + grammarBuilder.append("a : ID {std::cout << \"alt 1\" << std::endl;}\n"); + grammarBuilder.append(" | ID {std::cout << \"alt 2\" << std::endl;}\n"); + grammarBuilder.append(" | {false}? ID {std::cout << \"alt 3\" << std::endl;}\n"); grammarBuilder.append(" ;\n"); grammarBuilder.append("ID : 'a'..'z'+ ;\n"); grammarBuilder.append("INT : '0'..'9'+;\n"); @@ -46,13 +46,13 @@ public class TestSemPredEvalParser extends BaseCppTest { public void test2UnpredicatedAltsAndOneOrthogonalAlt() throws Exception { mkdir(tmpdir); - StringBuilder grammarBuilder = new StringBuilder(376); + StringBuilder grammarBuilder = new StringBuilder(439); grammarBuilder.append("grammar T;\n"); - grammarBuilder.append("s : {_interp.predictionMode = PredictionMode.LL_EXACT_AMBIG_DETECTION} a ';' a ';' a;\n"); - grammarBuilder.append("a : INT {std::cout << \"alt 1\" << \"\\n\";}\n"); - grammarBuilder.append(" | ID {std::cout << \"alt 2\" << \"\\n\";} // must pick this one for ID since pred is false\n"); - grammarBuilder.append(" | ID {std::cout << \"alt 3\" << \"\\n\";}\n"); - grammarBuilder.append(" | {false}? ID {std::cout << \"alt 4\" << \"\\n\";}\n"); + grammarBuilder.append("s : {getInterpreter()->setPredictionMode(atn::PredictionMode::LL_EXACT_AMBIG_DETECTION);} a ';' a ';' a;\n"); + grammarBuilder.append("a : INT {std::cout << \"alt 1\" << std::endl;}\n"); + grammarBuilder.append(" | ID {std::cout << \"alt 2\" << std::endl;} // must pick this one for ID since pred is false\n"); + grammarBuilder.append(" | ID {std::cout << \"alt 3\" << std::endl;}\n"); + grammarBuilder.append(" | {false}? ID {std::cout << \"alt 4\" << std::endl;}\n"); grammarBuilder.append(" ;\n"); grammarBuilder.append("ID : 'a'..'z'+ ;\n"); grammarBuilder.append("INT : '0'..'9'+;\n"); @@ -81,12 +81,12 @@ public class TestSemPredEvalParser extends BaseCppTest { public void testActionHidesPreds() throws Exception { mkdir(tmpdir); - StringBuilder grammarBuilder = new StringBuilder(214); + StringBuilder grammarBuilder = new StringBuilder(231); grammarBuilder.append("grammar T;\n"); - grammarBuilder.append("@members {i = 0}\n"); + grammarBuilder.append("@members {int i = 0;}\n"); grammarBuilder.append("s : a+ ;\n"); - grammarBuilder.append("a : {i = 1} ID {i == 1}? {std::cout << \"alt 1\" << \"\\n\";}\n"); - grammarBuilder.append(" | {i = 2} ID {i == 2}? {std::cout << \"alt 2\" << \"\\n\";}\n"); + grammarBuilder.append("a : {i = 1;} ID {i == 1}? {std::cout << \"alt 1\" << std::endl;}\n"); + grammarBuilder.append(" | {i = 2;} ID {i == 2}? {std::cout << \"alt 2\" << std::endl;}\n"); grammarBuilder.append(" ;\n"); grammarBuilder.append("ID : 'a'..'z'+ ;\n"); grammarBuilder.append("INT : '0'..'9'+;\n"); @@ -110,15 +110,15 @@ public class TestSemPredEvalParser extends BaseCppTest { public void testActionsHidePredsInGlobalFOLLOW() throws Exception { mkdir(tmpdir); - StringBuilder grammarBuilder = new StringBuilder(282); + StringBuilder grammarBuilder = new StringBuilder(308); grammarBuilder.append("grammar T;\n"); grammarBuilder.append("@members {\n"); - grammarBuilder.append("def pred(self, v):\n"); - grammarBuilder.append(" std::cout << \"eval=\" << str(v).lower();\n"); - grammarBuilder.append(" return v\n"); - grammarBuilder.append("\n"); + grammarBuilder.append("bool pred(bool v) {\n"); + grammarBuilder.append(" std::cout << \"eval=\" << std::boolalpha << v << std::endl;\n"); + grammarBuilder.append(" return v;\n"); grammarBuilder.append("}\n"); - grammarBuilder.append("s : e {} {pred(true)}? {std::cout << \"parse\" << \"\\n\";} '!' ;\n"); + grammarBuilder.append("}\n"); + grammarBuilder.append("s : e {} {pred(true)}? {std::cout << \"parse\" << std::endl;} '!' ;\n"); grammarBuilder.append("t : e {} {pred(false)}? ID ;\n"); grammarBuilder.append("e : ID | ; // non-LL(1) so we use ATN\n"); grammarBuilder.append("ID : 'a'..'z'+ ;\n"); @@ -164,17 +164,17 @@ public class TestSemPredEvalParser extends BaseCppTest { public void testDepedentPredsInGlobalFOLLOW() throws Exception { mkdir(tmpdir); - StringBuilder grammarBuilder = new StringBuilder(305); + StringBuilder grammarBuilder = new StringBuilder(335); grammarBuilder.append("grammar T;\n"); grammarBuilder.append("@members {\n"); - grammarBuilder.append("def pred(self, v):\n"); - grammarBuilder.append(" std::cout << \"eval=\" << str(v).lower();\n"); - grammarBuilder.append(" return v\n"); - grammarBuilder.append("\n"); + grammarBuilder.append("bool pred(bool v) {\n"); + grammarBuilder.append(" std::cout << \"eval=\" << std::boolalpha << v << std::endl;\n"); + grammarBuilder.append(" return v;\n"); + grammarBuilder.append("}\n"); grammarBuilder.append("}\n"); grammarBuilder.append("s : a[99] ;\n"); - grammarBuilder.append("a[int i] : e {pred($i==99)}? {std::cout << \"parse\" << \"\\n\";} '!' ;\n"); - grammarBuilder.append("b[int i] : e {pred($i==99)}? ID ;\n"); + grammarBuilder.append("a[int i] : e {pred($i == 99)}? {std::cout << \"parse\" << std::endl;} '!' ;\n"); + grammarBuilder.append("b[int i] : e {pred($i == 99)}? ID ;\n"); grammarBuilder.append("e : ID | ; // non-LL(1) so we use ATN\n"); grammarBuilder.append("ID : 'a'..'z'+ ;\n"); grammarBuilder.append("INT : '0'..'9'+;\n"); @@ -197,13 +197,13 @@ public class TestSemPredEvalParser extends BaseCppTest { public void testDependentPredNotInOuterCtxShouldBeIgnored() throws Exception { mkdir(tmpdir); - StringBuilder grammarBuilder = new StringBuilder(286); + StringBuilder grammarBuilder = new StringBuilder(300); grammarBuilder.append("grammar T;\n"); grammarBuilder.append("s : b[2] ';' | b[2] '.' ; // decision in s drills down to ctx-dependent pred in a;\n"); grammarBuilder.append("b[int i] : a[i] ;\n"); grammarBuilder.append("a[int i]\n"); - grammarBuilder.append(" : {$i==1}? ID {std::cout << \"alt 1\" << \"\\n\";}\n"); - grammarBuilder.append(" | {$i==2}? ID {std::cout << \"alt 2\" << \"\\n\";}\n"); + grammarBuilder.append(" : {$i == 1}? ID {std::cout << \"alt 1\" << std::endl;}\n"); + grammarBuilder.append(" | {$i == 2}? ID {std::cout << \"alt 2\" << std::endl;}\n"); grammarBuilder.append(" ;\n"); grammarBuilder.append("ID : 'a'..'z'+ ;\n"); grammarBuilder.append("INT : '0'..'9'+;\n"); @@ -246,13 +246,13 @@ public class TestSemPredEvalParser extends BaseCppTest { public void testIndependentPredNotPassedOuterCtxToAvoidCastException() throws Exception { mkdir(tmpdir); - StringBuilder grammarBuilder = new StringBuilder(199); + StringBuilder grammarBuilder = new StringBuilder(209); grammarBuilder.append("grammar T;\n"); grammarBuilder.append("s : b ';' | b '.' ;\n"); grammarBuilder.append("b : a ;\n"); grammarBuilder.append("a\n"); - grammarBuilder.append(" : {false}? ID {std::cout << \"alt 1\" << \"\\n\";}\n"); - grammarBuilder.append(" | {true}? ID {std::cout << \"alt 2\" << \"\\n\";}\n"); + grammarBuilder.append(" : {false}? ID {std::cout << \"alt 1\" << std::endl;}\n"); + grammarBuilder.append(" | {true}? ID {std::cout << \"alt 2\" << std::endl;}\n"); grammarBuilder.append(" ;\n"); grammarBuilder.append("ID : 'a'..'z'+ ;\n"); grammarBuilder.append("INT : '0'..'9'+;\n"); @@ -273,11 +273,11 @@ public class TestSemPredEvalParser extends BaseCppTest { public void testNoTruePredsThrowsNoViableAlt() throws Exception { mkdir(tmpdir); - StringBuilder grammarBuilder = new StringBuilder(187); + StringBuilder grammarBuilder = new StringBuilder(197); grammarBuilder.append("grammar T;\n"); grammarBuilder.append("s : a a;\n"); - grammarBuilder.append("a : {false}? ID INT {std::cout << \"alt 1\" << \"\\n\";}\n"); - grammarBuilder.append(" | {false}? ID INT {std::cout << \"alt 2\" << \"\\n\";}\n"); + grammarBuilder.append("a : {false}? ID INT {std::cout << \"alt 1\" << std::endl;}\n"); + grammarBuilder.append(" | {false}? ID INT {std::cout << \"alt 2\" << std::endl;}\n"); grammarBuilder.append(" ;\n"); grammarBuilder.append("ID : 'a'..'z'+ ;\n"); grammarBuilder.append("INT : '0'..'9'+;\n"); @@ -299,13 +299,13 @@ public class TestSemPredEvalParser extends BaseCppTest { public void testOrder() throws Exception { mkdir(tmpdir); - StringBuilder grammarBuilder = new StringBuilder(313); + StringBuilder grammarBuilder = new StringBuilder(323); grammarBuilder.append("grammar T;\n"); grammarBuilder.append("s : a {} a; // do 2x: once in ATN, next in DFA;\n"); grammarBuilder.append("// action blocks lookahead from falling off of 'a'\n"); grammarBuilder.append("// and looking into 2nd 'a' ref. !ctx dependent pred\n"); - grammarBuilder.append("a : ID {std::cout << \"alt 1\" << \"\\n\";}\n"); - grammarBuilder.append(" | {true}? ID {std::cout << \"alt 2\" << \"\\n\";}\n"); + grammarBuilder.append("a : ID {std::cout << \"alt 1\" << std::endl;}\n"); + grammarBuilder.append(" | {true}? ID {std::cout << \"alt 2\" << std::endl;}\n"); grammarBuilder.append(" ;\n"); grammarBuilder.append("ID : 'a'..'z'+ ;\n"); grammarBuilder.append("INT : '0'..'9'+;\n"); @@ -328,13 +328,13 @@ public class TestSemPredEvalParser extends BaseCppTest { public void testPredFromAltTestedInLoopBack_1() throws Exception { mkdir(tmpdir); - StringBuilder grammarBuilder = new StringBuilder(214); + StringBuilder grammarBuilder = new StringBuilder(217); grammarBuilder.append("grammar T;\n"); grammarBuilder.append("file_\n"); - grammarBuilder.append("@after {std::cout << $ctx.toStringTree(recog=self) << \"\\n\";}\n"); + grammarBuilder.append("@after {std::cout << $ctx->toStringTree(this) << std::endl;}\n"); grammarBuilder.append(" : para para EOF ;\n"); grammarBuilder.append("para: paraContent NL NL ;\n"); - grammarBuilder.append("paraContent : ('s'|'x'|{_input->LA(2)!=TParser.NL}? NL)+ ;\n"); + grammarBuilder.append("paraContent : ('s'|'x'|{_input->LA(2) != TParser::NL}? NL)+ ;\n"); grammarBuilder.append("NL : '\\n' ;\n"); grammarBuilder.append("s : 's' ;\n"); grammarBuilder.append("X : 'x' ;"); @@ -361,13 +361,13 @@ public class TestSemPredEvalParser extends BaseCppTest { public void testPredFromAltTestedInLoopBack_2() throws Exception { mkdir(tmpdir); - StringBuilder grammarBuilder = new StringBuilder(214); + StringBuilder grammarBuilder = new StringBuilder(217); grammarBuilder.append("grammar T;\n"); grammarBuilder.append("file_\n"); - grammarBuilder.append("@after {std::cout << $ctx.toStringTree(recog=self) << \"\\n\";}\n"); + grammarBuilder.append("@after {std::cout << $ctx->toStringTree(this) << std::endl;}\n"); grammarBuilder.append(" : para para EOF ;\n"); grammarBuilder.append("para: paraContent NL NL ;\n"); - grammarBuilder.append("paraContent : ('s'|'x'|{_input->LA(2)!=TParser.NL}? NL)+ ;\n"); + grammarBuilder.append("paraContent : ('s'|'x'|{_input->LA(2) != TParser::NL}? NL)+ ;\n"); grammarBuilder.append("NL : '\\n' ;\n"); grammarBuilder.append("s : 's' ;\n"); grammarBuilder.append("X : 'x' ;"); @@ -392,12 +392,12 @@ public class TestSemPredEvalParser extends BaseCppTest { public void testPredTestedEvenWhenUnAmbig_1() throws Exception { mkdir(tmpdir); - StringBuilder grammarBuilder = new StringBuilder(206); + StringBuilder grammarBuilder = new StringBuilder(222); grammarBuilder.append("grammar T;\n"); - grammarBuilder.append("@members {enumKeyword = true}\n"); + grammarBuilder.append("@members {bool enumKeyword = true;}\n"); grammarBuilder.append("primary\n"); - grammarBuilder.append(" : ID {std::cout << \"ID \"+$ID.text << \"\\n\";}\n"); - grammarBuilder.append(" | {!enumKeyword}? 'enum' {std::cout << \"enum\" << \"\\n\";}\n"); + grammarBuilder.append(" : ID {std::cout << \"ID \"+$ID.text << std::endl;}\n"); + grammarBuilder.append(" | {!enumKeyword}? 'enum' {std::cout << \"enum\" << std::endl;}\n"); grammarBuilder.append(" ;\n"); grammarBuilder.append("ID : [a-z]+ ;\n"); grammarBuilder.append("WS : [ \\t\\n\\r]+ -> skip ;"); @@ -417,12 +417,12 @@ public class TestSemPredEvalParser extends BaseCppTest { public void testPredTestedEvenWhenUnAmbig_2() throws Exception { mkdir(tmpdir); - StringBuilder grammarBuilder = new StringBuilder(206); + StringBuilder grammarBuilder = new StringBuilder(222); grammarBuilder.append("grammar T;\n"); - grammarBuilder.append("@members {enumKeyword = true}\n"); + grammarBuilder.append("@members {bool enumKeyword = true;}\n"); grammarBuilder.append("primary\n"); - grammarBuilder.append(" : ID {std::cout << \"ID \"+$ID.text << \"\\n\";}\n"); - grammarBuilder.append(" | {!enumKeyword}? 'enum' {std::cout << \"enum\" << \"\\n\";}\n"); + grammarBuilder.append(" : ID {std::cout << \"ID \"+$ID.text << std::endl;}\n"); + grammarBuilder.append(" | {!enumKeyword}? 'enum' {std::cout << \"enum\" << std::endl;}\n"); grammarBuilder.append(" ;\n"); grammarBuilder.append("ID : [a-z]+ ;\n"); grammarBuilder.append("WS : [ \\t\\n\\r]+ -> skip ;"); @@ -443,13 +443,13 @@ public class TestSemPredEvalParser extends BaseCppTest { public void testPredicateDependentOnArg() throws Exception { mkdir(tmpdir); - StringBuilder grammarBuilder = new StringBuilder(211); + StringBuilder grammarBuilder = new StringBuilder(230); grammarBuilder.append("grammar T;\n"); - grammarBuilder.append("@members {i = 0}\n"); + grammarBuilder.append("@members {int i = 0;}\n"); grammarBuilder.append("s : a[2] a[1];\n"); grammarBuilder.append("a[int i]\n"); - grammarBuilder.append(" : {$i==1}? ID {std::cout << \"alt 1\" << \"\\n\";}\n"); - grammarBuilder.append(" | {$i==2}? ID {std::cout << \"alt 2\" << \"\\n\";}\n"); + grammarBuilder.append(" : {$i == 1}? ID {std::cout << \"alt 1\" << std::endl;}\n"); + grammarBuilder.append(" | {$i == 2}? ID {std::cout << \"alt 2\" << std::endl;}\n"); grammarBuilder.append(" ;\n"); grammarBuilder.append("ID : 'a'..'z'+ ;\n"); grammarBuilder.append("INT : '0'..'9'+;\n"); @@ -472,13 +472,13 @@ public class TestSemPredEvalParser extends BaseCppTest { public void testPredicateDependentOnArg2() throws Exception { mkdir(tmpdir); - StringBuilder grammarBuilder = new StringBuilder(149); + StringBuilder grammarBuilder = new StringBuilder(158); grammarBuilder.append("grammar T;\n"); - grammarBuilder.append("@members {i = 0}\n"); + grammarBuilder.append("@members {int i = 0;}\n"); grammarBuilder.append("s : a[2] a[1];\n"); grammarBuilder.append("a[int i]\n"); - grammarBuilder.append(" : {$i==1}? ID \n"); - grammarBuilder.append(" | {$i==2}? ID \n"); + grammarBuilder.append(" : {$i == 1}? ID \n"); + grammarBuilder.append(" | {$i == 2}? ID \n"); grammarBuilder.append(" ;\n"); grammarBuilder.append("ID : 'a'..'z'+ ;\n"); grammarBuilder.append("INT : '0'..'9'+;\n"); @@ -499,15 +499,15 @@ public class TestSemPredEvalParser extends BaseCppTest { public void testPredsInGlobalFOLLOW() throws Exception { mkdir(tmpdir); - StringBuilder grammarBuilder = new StringBuilder(276); + StringBuilder grammarBuilder = new StringBuilder(302); grammarBuilder.append("grammar T;\n"); grammarBuilder.append("@members {\n"); - grammarBuilder.append("def pred(self, v):\n"); - grammarBuilder.append(" std::cout << \"eval=\" << str(v).lower();\n"); - grammarBuilder.append(" return v\n"); - grammarBuilder.append("\n"); + grammarBuilder.append("bool pred(bool v) {\n"); + grammarBuilder.append(" std::cout << \"eval=\" << std::boolalpha << v << std::endl;\n"); + grammarBuilder.append(" return v;\n"); grammarBuilder.append("}\n"); - grammarBuilder.append("s : e {pred(true)}? {std::cout << \"parse\" << \"\\n\";} '!' ;\n"); + grammarBuilder.append("}\n"); + grammarBuilder.append("s : e {pred(true)}? {std::cout << \"parse\" << std::endl;} '!' ;\n"); grammarBuilder.append("t : e {pred(false)}? ID ;\n"); grammarBuilder.append("e : ID | ; // non-LL(1) so we use ATN\n"); grammarBuilder.append("ID : 'a'..'z'+ ;\n"); @@ -531,11 +531,11 @@ public class TestSemPredEvalParser extends BaseCppTest { public void testRewindBeforePredEval() throws Exception { mkdir(tmpdir); - StringBuilder grammarBuilder = new StringBuilder(223); + StringBuilder grammarBuilder = new StringBuilder(249); grammarBuilder.append("grammar T;\n"); grammarBuilder.append("s : a a;\n"); - grammarBuilder.append("a : {_input->LT(1).text==\"x\"}? ID INT {std::cout << \"alt 1\" << \"\\n\";}\n"); - grammarBuilder.append(" | {_input->LT(1).text==\"y\"}? ID INT {std::cout << \"alt 2\" << \"\\n\";}\n"); + grammarBuilder.append("a : {_input->LT(1)->getText() == \"x\"}? ID INT {std::cout << \"alt 1\" << std::endl;}\n"); + grammarBuilder.append(" | {_input->LT(1)->getText() == \"y\"}? ID INT {std::cout << \"alt 2\" << std::endl;}\n"); grammarBuilder.append(" ;\n"); grammarBuilder.append("ID : 'a'..'z'+ ;\n"); grammarBuilder.append("INT : '0'..'9'+;\n"); @@ -558,12 +558,12 @@ public class TestSemPredEvalParser extends BaseCppTest { public void testSimple() throws Exception { mkdir(tmpdir); - StringBuilder grammarBuilder = new StringBuilder(280); + StringBuilder grammarBuilder = new StringBuilder(295); grammarBuilder.append("grammar T;\n"); grammarBuilder.append("s : a a a; // do 3x: once in ATN, next in DFA then INT in ATN\n"); - grammarBuilder.append("a : {false}? ID {std::cout << \"alt 1\" << \"\\n\";}\n"); - grammarBuilder.append(" | {true}? ID {std::cout << \"alt 2\" << \"\\n\";}\n"); - grammarBuilder.append(" | INT {std::cout << \"alt 3\" << \"\\n\";}\n"); + grammarBuilder.append("a : {false}? ID {std::cout << \"alt 1\" << std::endl;}\n"); + grammarBuilder.append(" | {true}? ID {std::cout << \"alt 2\" << std::endl;}\n"); + grammarBuilder.append(" | INT {std::cout << \"alt 3\" << std::endl;}\n"); grammarBuilder.append(" ;\n"); grammarBuilder.append("ID : 'a'..'z'+ ;\n"); grammarBuilder.append("INT : '0'..'9'+;\n"); @@ -587,11 +587,11 @@ public class TestSemPredEvalParser extends BaseCppTest { public void testSimpleValidate() throws Exception { mkdir(tmpdir); - StringBuilder grammarBuilder = new StringBuilder(180); + StringBuilder grammarBuilder = new StringBuilder(190); grammarBuilder.append("grammar T;\n"); grammarBuilder.append("s : a ;\n"); - grammarBuilder.append("a : {false}? ID {std::cout << \"alt 1\" << \"\\n\";}\n"); - grammarBuilder.append(" | {true}? INT {std::cout << \"alt 2\" << \"\\n\";}\n"); + grammarBuilder.append("a : {false}? ID {std::cout << \"alt 1\" << std::endl;}\n"); + grammarBuilder.append(" | {true}? INT {std::cout << \"alt 2\" << std::endl;}\n"); grammarBuilder.append(" ;\n"); grammarBuilder.append("ID : 'a'..'z'+ ;\n"); grammarBuilder.append("INT : '0'..'9'+;\n"); @@ -613,11 +613,11 @@ public class TestSemPredEvalParser extends BaseCppTest { public void testSimpleValidate2() throws Exception { mkdir(tmpdir); - StringBuilder grammarBuilder = new StringBuilder(183); + StringBuilder grammarBuilder = new StringBuilder(193); grammarBuilder.append("grammar T;\n"); grammarBuilder.append("s : a a a;\n"); - grammarBuilder.append("a : {false}? ID {std::cout << \"alt 1\" << \"\\n\";}\n"); - grammarBuilder.append(" | {true}? INT {std::cout << \"alt 2\" << \"\\n\";}\n"); + grammarBuilder.append("a : {false}? ID {std::cout << \"alt 1\" << std::endl;}\n"); + grammarBuilder.append(" | {true}? INT {std::cout << \"alt 2\" << std::endl;}\n"); grammarBuilder.append(" ;\n"); grammarBuilder.append("ID : 'a'..'z'+ ;\n"); grammarBuilder.append("INT : '0'..'9'+;\n"); @@ -641,11 +641,11 @@ public class TestSemPredEvalParser extends BaseCppTest { public void testToLeft() throws Exception { mkdir(tmpdir); - StringBuilder grammarBuilder = new StringBuilder(180); + StringBuilder grammarBuilder = new StringBuilder(190); grammarBuilder.append("grammar T;\n"); grammarBuilder.append(" s : a+ ;\n"); - grammarBuilder.append("a : {false}? ID {std::cout << \"alt 1\" << \"\\n\";}\n"); - grammarBuilder.append(" | {true}? ID {std::cout << \"alt 2\" << \"\\n\";}\n"); + grammarBuilder.append("a : {false}? ID {std::cout << \"alt 1\" << std::endl;}\n"); + grammarBuilder.append(" | {true}? ID {std::cout << \"alt 2\" << std::endl;}\n"); grammarBuilder.append(" ;\n"); grammarBuilder.append("ID : 'a'..'z'+ ;\n"); grammarBuilder.append("INT : '0'..'9'+;\n"); @@ -669,13 +669,13 @@ public class TestSemPredEvalParser extends BaseCppTest { public void testToLeftWithVaryingPredicate() throws Exception { mkdir(tmpdir); - StringBuilder grammarBuilder = new StringBuilder(259); + StringBuilder grammarBuilder = new StringBuilder(271); grammarBuilder.append("grammar T;\n"); - grammarBuilder.append("@members {i = 0}\n"); - grammarBuilder.append("s : ({i += 1\n"); - grammarBuilder.append("std::cout << \"i=\" + i.toString() << \"\\n\";} a)+ ;\n"); - grammarBuilder.append("a : {i % 2 == 0}? ID {std::cout << \"alt 1\" << \"\\n\";}\n"); - grammarBuilder.append(" | {i % 2 != 0}? ID {std::cout << \"alt 2\" << \"\\n\";}\n"); + grammarBuilder.append("@members {int i = 0;}\n"); + grammarBuilder.append("s : ({i += 1;\n"); + grammarBuilder.append(" std::cout << \"i=\" << i << std::endl;} a)+ ;\n"); + grammarBuilder.append("a : {i % 2 == 0}? ID {std::cout << \"alt 1\" << std::endl;}\n"); + grammarBuilder.append(" | {i % 2 != 0}? ID {std::cout << \"alt 2\" << std::endl;}\n"); grammarBuilder.append(" ;\n"); grammarBuilder.append("ID : 'a'..'z'+ ;\n"); grammarBuilder.append("INT : '0'..'9'+;\n"); @@ -702,10 +702,10 @@ public class TestSemPredEvalParser extends BaseCppTest { public void testUnpredicatedPathsInAlt() throws Exception { mkdir(tmpdir); - StringBuilder grammarBuilder = new StringBuilder(199); + StringBuilder grammarBuilder = new StringBuilder(209); grammarBuilder.append("grammar T;\n"); - grammarBuilder.append("s : a {std::cout << \"alt 1\" << \"\\n\";}\n"); - grammarBuilder.append(" | b {std::cout << \"alt 2\" << \"\\n\";}\n"); + grammarBuilder.append("s : a {std::cout << \"alt 1\" << std::endl;}\n"); + grammarBuilder.append(" | b {std::cout << \"alt 2\" << std::endl;}\n"); grammarBuilder.append(" ;\n"); grammarBuilder.append("a : {false}? ID INT\n"); grammarBuilder.append(" | ID INT\n"); @@ -731,14 +731,14 @@ public class TestSemPredEvalParser extends BaseCppTest { public void testValidateInDFA() throws Exception { mkdir(tmpdir); - StringBuilder grammarBuilder = new StringBuilder(348); + StringBuilder grammarBuilder = new StringBuilder(358); grammarBuilder.append("grammar T;\n"); grammarBuilder.append("s : a ';' a;\n"); grammarBuilder.append("// ';' helps us to resynchronize without consuming\n"); grammarBuilder.append("// 2nd 'a' reference. We our testing that the DFA also\n"); grammarBuilder.append("// throws an exception if the validating predicate fails\n"); - grammarBuilder.append("a : {false}? ID {std::cout << \"alt 1\" << \"\\n\";}\n"); - grammarBuilder.append(" | {true}? INT {std::cout << \"alt 2\" << \"\\n\";}\n"); + grammarBuilder.append("a : {false}? ID {std::cout << \"alt 1\" << std::endl;}\n"); + grammarBuilder.append(" | {true}? INT {std::cout << \"alt 2\" << std::endl;}\n"); grammarBuilder.append(" ;\n"); grammarBuilder.append("ID : 'a'..'z'+ ;\n"); grammarBuilder.append("INT : '0'..'9'+;\n"); diff --git a/runtime-testsuite/test/org/antlr/v4/test/runtime/cpp/TestSets.java b/runtime-testsuite/test/org/antlr/v4/test/runtime/cpp/TestSets.java index 4826439b8..4cb72e069 100644 --- a/runtime-testsuite/test/org/antlr/v4/test/runtime/cpp/TestSets.java +++ b/runtime-testsuite/test/org/antlr/v4/test/runtime/cpp/TestSets.java @@ -13,9 +13,9 @@ public class TestSets extends BaseCppTest { public void testCharSetLiteral() throws Exception { mkdir(tmpdir); - StringBuilder grammarBuilder = new StringBuilder(93); + StringBuilder grammarBuilder = new StringBuilder(98); grammarBuilder.append("grammar T;\n"); - grammarBuilder.append("a : (A {std::cout << $A.text << \"\\n\";})+ ;\n"); + grammarBuilder.append("a : (A {std::cout << $A.text << std::endl;})+ ;\n"); grammarBuilder.append("A : [AaBb] ;\n"); grammarBuilder.append("WS : (' '|'\\n')+ -> skip ;"); String grammar = grammarBuilder.toString(); @@ -61,9 +61,9 @@ public class TestSets extends BaseCppTest { public void testLexerOptionalSet() throws Exception { mkdir(tmpdir); - StringBuilder grammarBuilder = new StringBuilder(81); + StringBuilder grammarBuilder = new StringBuilder(86); grammarBuilder.append("grammar T;\n"); - grammarBuilder.append("a : A {std::cout << _input->getText() << \"\\n\";} ;\n"); + grammarBuilder.append("a : A {std::cout << _input->getText() << std::endl;} ;\n"); grammarBuilder.append("A : ('a'|'b')? 'c' ;"); String grammar = grammarBuilder.toString(); @@ -81,9 +81,9 @@ public class TestSets extends BaseCppTest { public void testLexerPlusSet() throws Exception { mkdir(tmpdir); - StringBuilder grammarBuilder = new StringBuilder(81); + StringBuilder grammarBuilder = new StringBuilder(86); grammarBuilder.append("grammar T;\n"); - grammarBuilder.append("a : A {std::cout << _input->getText() << \"\\n\";} ;\n"); + grammarBuilder.append("a : A {std::cout << _input->getText() << std::endl;} ;\n"); grammarBuilder.append("A : ('a'|'b')+ 'c' ;"); String grammar = grammarBuilder.toString(); @@ -101,9 +101,9 @@ public class TestSets extends BaseCppTest { public void testLexerStarSet() throws Exception { mkdir(tmpdir); - StringBuilder grammarBuilder = new StringBuilder(81); + StringBuilder grammarBuilder = new StringBuilder(86); grammarBuilder.append("grammar T;\n"); - grammarBuilder.append("a : A {std::cout << _input->getText() << \"\\n\";} ;\n"); + grammarBuilder.append("a : A {std::cout << _input->getText() << std::endl;} ;\n"); grammarBuilder.append("A : ('a'|'b')* 'c' ;"); String grammar = grammarBuilder.toString(); @@ -121,9 +121,9 @@ public class TestSets extends BaseCppTest { public void testNotChar() throws Exception { mkdir(tmpdir); - StringBuilder grammarBuilder = new StringBuilder(61); + StringBuilder grammarBuilder = new StringBuilder(66); grammarBuilder.append("grammar T;\n"); - grammarBuilder.append("a : A {std::cout << $A.text << \"\\n\";} ;\n"); + grammarBuilder.append("a : A {std::cout << $A.text << std::endl;} ;\n"); grammarBuilder.append("A : ~'b' ;"); String grammar = grammarBuilder.toString(); @@ -141,9 +141,9 @@ public class TestSets extends BaseCppTest { public void testNotCharSet() throws Exception { mkdir(tmpdir); - StringBuilder grammarBuilder = new StringBuilder(67); + StringBuilder grammarBuilder = new StringBuilder(72); grammarBuilder.append("grammar T;\n"); - grammarBuilder.append("a : A {std::cout << $A.text << \"\\n\";} ;\n"); + grammarBuilder.append("a : A {std::cout << $A.text << std::endl;} ;\n"); grammarBuilder.append("A : ~('b'|'c') ;"); String grammar = grammarBuilder.toString(); @@ -161,9 +161,9 @@ public class TestSets extends BaseCppTest { public void testNotCharSetWithLabel() throws Exception { mkdir(tmpdir); - StringBuilder grammarBuilder = new StringBuilder(69); + StringBuilder grammarBuilder = new StringBuilder(74); grammarBuilder.append("grammar T;\n"); - grammarBuilder.append("a : A {std::cout << $A.text << \"\\n\";} ;\n"); + grammarBuilder.append("a : A {std::cout << $A.text << std::endl;} ;\n"); grammarBuilder.append("A : h=~('b'|'c') ;"); String grammar = grammarBuilder.toString(); @@ -181,9 +181,9 @@ public class TestSets extends BaseCppTest { public void testNotCharSetWithRuleRef3() throws Exception { mkdir(tmpdir); - StringBuilder grammarBuilder = new StringBuilder(133); + StringBuilder grammarBuilder = new StringBuilder(138); grammarBuilder.append("grammar T;\n"); - grammarBuilder.append("a : A {std::cout << $A.text << \"\\n\";} ;\n"); + grammarBuilder.append("a : A {std::cout << $A.text << std::endl;} ;\n"); grammarBuilder.append("A : ('a'|B) ; // this doesn't collapse to set but works\n"); grammarBuilder.append("fragment\n"); grammarBuilder.append("B : ~('a'|'c') ;"); @@ -203,9 +203,9 @@ public class TestSets extends BaseCppTest { public void testOptionalLexerSingleElement() throws Exception { mkdir(tmpdir); - StringBuilder grammarBuilder = new StringBuilder(75); + StringBuilder grammarBuilder = new StringBuilder(80); grammarBuilder.append("grammar T;\n"); - grammarBuilder.append("a : A {std::cout << _input->getText() << \"\\n\";} ;\n"); + grammarBuilder.append("a : A {std::cout << _input->getText() << std::endl;} ;\n"); grammarBuilder.append("A : 'b'? 'c' ;"); String grammar = grammarBuilder.toString(); @@ -223,9 +223,9 @@ public class TestSets extends BaseCppTest { public void testOptionalSet() throws Exception { mkdir(tmpdir); - StringBuilder grammarBuilder = new StringBuilder(73); + StringBuilder grammarBuilder = new StringBuilder(78); grammarBuilder.append("grammar T;\n"); - grammarBuilder.append("a : ('a'|'b')? 'c' {std::cout << _input->getText() << \"\\n\";} ;"); + grammarBuilder.append("a : ('a'|'b')? 'c' {std::cout << _input->getText() << std::endl;} ;"); String grammar = grammarBuilder.toString(); @@ -242,9 +242,9 @@ public class TestSets extends BaseCppTest { public void testOptionalSingleElement() throws Exception { mkdir(tmpdir); - StringBuilder grammarBuilder = new StringBuilder(75); + StringBuilder grammarBuilder = new StringBuilder(80); grammarBuilder.append("grammar T;\n"); - grammarBuilder.append("a : A? 'c' {std::cout << _input->getText() << \"\\n\";} ;\n"); + grammarBuilder.append("a : A? 'c' {std::cout << _input->getText() << std::endl;} ;\n"); grammarBuilder.append("A : 'b' ;"); String grammar = grammarBuilder.toString(); @@ -262,9 +262,9 @@ public class TestSets extends BaseCppTest { public void testParserNotSet() throws Exception { mkdir(tmpdir); - StringBuilder grammarBuilder = new StringBuilder(65); + StringBuilder grammarBuilder = new StringBuilder(70); grammarBuilder.append("grammar T;\n"); - grammarBuilder.append("a : t=~('x'|'y') 'z' {std::cout << $t.text << \"\\n\";} ;"); + grammarBuilder.append("a : t=~('x'|'y') 'z' {std::cout << $t.text << std::endl;} ;"); String grammar = grammarBuilder.toString(); @@ -281,9 +281,9 @@ public class TestSets extends BaseCppTest { public void testParserNotToken() throws Exception { mkdir(tmpdir); - StringBuilder grammarBuilder = new StringBuilder(67); + StringBuilder grammarBuilder = new StringBuilder(72); grammarBuilder.append("grammar T;\n"); - grammarBuilder.append("a : ~'x' 'z' {std::cout << _input->getText() << \"\\n\";} ;"); + grammarBuilder.append("a : ~'x' 'z' {std::cout << _input->getText() << std::endl;} ;"); String grammar = grammarBuilder.toString(); @@ -300,9 +300,9 @@ public class TestSets extends BaseCppTest { public void testParserNotTokenWithLabel() throws Exception { mkdir(tmpdir); - StringBuilder grammarBuilder = new StringBuilder(59); + StringBuilder grammarBuilder = new StringBuilder(64); grammarBuilder.append("grammar T;\n"); - grammarBuilder.append("a : t=~'x' 'z' {std::cout << $t.text << \"\\n\";} ;"); + grammarBuilder.append("a : t=~'x' 'z' {std::cout << $t.text << std::endl;} ;"); String grammar = grammarBuilder.toString(); @@ -319,9 +319,9 @@ public class TestSets extends BaseCppTest { public void testParserSet() throws Exception { mkdir(tmpdir); - StringBuilder grammarBuilder = new StringBuilder(60); + StringBuilder grammarBuilder = new StringBuilder(65); grammarBuilder.append("grammar T;\n"); - grammarBuilder.append("a : t=('x'|'y') {std::cout << $t.text << \"\\n\";} ;"); + grammarBuilder.append("a : t=('x'|'y') {std::cout << $t.text << std::endl;} ;"); String grammar = grammarBuilder.toString(); @@ -338,9 +338,9 @@ public class TestSets extends BaseCppTest { public void testPlusLexerSingleElement() throws Exception { mkdir(tmpdir); - StringBuilder grammarBuilder = new StringBuilder(75); + StringBuilder grammarBuilder = new StringBuilder(80); grammarBuilder.append("grammar T;\n"); - grammarBuilder.append("a : A {std::cout << _input->getText() << \"\\n\";} ;\n"); + grammarBuilder.append("a : A {std::cout << _input->getText() << std::endl;} ;\n"); grammarBuilder.append("A : 'b'+ 'c' ;"); String grammar = grammarBuilder.toString(); @@ -358,9 +358,9 @@ public class TestSets extends BaseCppTest { public void testPlusSet() throws Exception { mkdir(tmpdir); - StringBuilder grammarBuilder = new StringBuilder(73); + StringBuilder grammarBuilder = new StringBuilder(78); grammarBuilder.append("grammar T;\n"); - grammarBuilder.append("a : ('a'|'b')+ 'c' {std::cout << _input->getText() << \"\\n\";} ;"); + grammarBuilder.append("a : ('a'|'b')+ 'c' {std::cout << _input->getText() << std::endl;} ;"); String grammar = grammarBuilder.toString(); @@ -377,9 +377,9 @@ public class TestSets extends BaseCppTest { public void testRuleAsSet() throws Exception { mkdir(tmpdir); - StringBuilder grammarBuilder = new StringBuilder(80); + StringBuilder grammarBuilder = new StringBuilder(85); grammarBuilder.append("grammar T;\n"); - grammarBuilder.append("a @after {std::cout << _input->getText() << \"\\n\";} : 'a' | 'b' |'c' ;"); + grammarBuilder.append("a @after {std::cout << _input->getText() << std::endl;} : 'a' | 'b' |'c' ;"); String grammar = grammarBuilder.toString(); @@ -396,9 +396,9 @@ public class TestSets extends BaseCppTest { public void testSeqDoesNotBecomeSet() throws Exception { mkdir(tmpdir); - StringBuilder grammarBuilder = new StringBuilder(117); + StringBuilder grammarBuilder = new StringBuilder(122); grammarBuilder.append("grammar T;\n"); - grammarBuilder.append("a : C {std::cout << _input->getText() << \"\\n\";} ;\n"); + grammarBuilder.append("a : C {std::cout << _input->getText() << std::endl;} ;\n"); grammarBuilder.append("fragment A : '1' | '2';\n"); grammarBuilder.append("fragment B : '3' '4';\n"); grammarBuilder.append("C : A | B;"); @@ -418,9 +418,9 @@ public class TestSets extends BaseCppTest { public void testStarLexerSingleElement_1() throws Exception { mkdir(tmpdir); - StringBuilder grammarBuilder = new StringBuilder(75); + StringBuilder grammarBuilder = new StringBuilder(80); grammarBuilder.append("grammar T;\n"); - grammarBuilder.append("a : A {std::cout << _input->getText() << \"\\n\";} ;\n"); + grammarBuilder.append("a : A {std::cout << _input->getText() << std::endl;} ;\n"); grammarBuilder.append("A : 'b'* 'c' ;"); String grammar = grammarBuilder.toString(); @@ -438,9 +438,9 @@ public class TestSets extends BaseCppTest { public void testStarLexerSingleElement_2() throws Exception { mkdir(tmpdir); - StringBuilder grammarBuilder = new StringBuilder(75); + StringBuilder grammarBuilder = new StringBuilder(80); grammarBuilder.append("grammar T;\n"); - grammarBuilder.append("a : A {std::cout << _input->getText() << \"\\n\";} ;\n"); + grammarBuilder.append("a : A {std::cout << _input->getText() << std::endl;} ;\n"); grammarBuilder.append("A : 'b'* 'c' ;"); String grammar = grammarBuilder.toString(); @@ -458,9 +458,9 @@ public class TestSets extends BaseCppTest { public void testStarSet() throws Exception { mkdir(tmpdir); - StringBuilder grammarBuilder = new StringBuilder(73); + StringBuilder grammarBuilder = new StringBuilder(78); grammarBuilder.append("grammar T;\n"); - grammarBuilder.append("a : ('a'|'b')* 'c' {std::cout << _input->getText() << \"\\n\";} ;"); + grammarBuilder.append("a : ('a'|'b')* 'c' {std::cout << _input->getText() << std::endl;} ;"); String grammar = grammarBuilder.toString(); diff --git a/runtime-testsuite/test/org/antlr/v4/test/runtime/csharp/TestSemPredEvalParser.java b/runtime-testsuite/test/org/antlr/v4/test/runtime/csharp/TestSemPredEvalParser.java index 445cce200..c52d6a258 100644 --- a/runtime-testsuite/test/org/antlr/v4/test/runtime/csharp/TestSemPredEvalParser.java +++ b/runtime-testsuite/test/org/antlr/v4/test/runtime/csharp/TestSemPredEvalParser.java @@ -552,11 +552,11 @@ public class TestSemPredEvalParser extends BaseTest { @Test public void testToLeftWithVaryingPredicate() throws Exception { mkdir(tmpdir); - StringBuilder grammarBuilder = new StringBuilder(268); + StringBuilder grammarBuilder = new StringBuilder(261); grammarBuilder.append("grammar T;\n"); grammarBuilder.append("@members {int i = 0;}\n"); grammarBuilder.append("s : ({this.i += 1;\n"); - grammarBuilder.append("Console.WriteLine(\"i=\" + this.i);} a)+ ;\n"); + grammarBuilder.append("Console.WriteLine(\"i=\"+i);} a)+ ;\n"); grammarBuilder.append("a : {this.i % 2 == 0}? ID {Console.WriteLine(\"alt 1\");}\n"); grammarBuilder.append(" | {this.i % 2 != 0}? ID {Console.WriteLine(\"alt 2\");}\n"); grammarBuilder.append(" ;\n"); diff --git a/runtime-testsuite/test/org/antlr/v4/test/runtime/java/TestSemPredEvalParser.java b/runtime-testsuite/test/org/antlr/v4/test/runtime/java/TestSemPredEvalParser.java index 6a749a76d..a4591c624 100644 --- a/runtime-testsuite/test/org/antlr/v4/test/runtime/java/TestSemPredEvalParser.java +++ b/runtime-testsuite/test/org/antlr/v4/test/runtime/java/TestSemPredEvalParser.java @@ -646,11 +646,11 @@ public class TestSemPredEvalParser extends BaseTest { public void testToLeftWithVaryingPredicate() throws Exception { mkdir(tmpdir); - StringBuilder grammarBuilder = new StringBuilder(271); + StringBuilder grammarBuilder = new StringBuilder(264); grammarBuilder.append("grammar T;\n"); grammarBuilder.append("@members {int i = 0;}\n"); grammarBuilder.append("s : ({this.i += 1;\n"); - grammarBuilder.append("System.out.println(\"i=\" + this.i);} a)+ ;\n"); + grammarBuilder.append("System.out.println(\"i=\"+i);} a)+ ;\n"); grammarBuilder.append("a : {this.i % 2 == 0}? ID {System.out.println(\"alt 1\");}\n"); grammarBuilder.append(" | {this.i % 2 != 0}? ID {System.out.println(\"alt 2\");}\n"); grammarBuilder.append(" ;\n"); diff --git a/runtime-testsuite/test/org/antlr/v4/test/runtime/javascript/node/TestSemPredEvalParser.java b/runtime-testsuite/test/org/antlr/v4/test/runtime/javascript/node/TestSemPredEvalParser.java index 652159bc4..7848e60f0 100644 --- a/runtime-testsuite/test/org/antlr/v4/test/runtime/javascript/node/TestSemPredEvalParser.java +++ b/runtime-testsuite/test/org/antlr/v4/test/runtime/javascript/node/TestSemPredEvalParser.java @@ -600,11 +600,11 @@ public class TestSemPredEvalParser extends BaseTest { @Test public void testToLeftWithVaryingPredicate() throws Exception { mkdir(tmpdir); - StringBuilder grammarBuilder = new StringBuilder(252); + StringBuilder grammarBuilder = new StringBuilder(245); grammarBuilder.append("grammar T;\n"); grammarBuilder.append("@members {this.i = 0;}\n"); grammarBuilder.append("s : ({this.i += 1;\n"); - grammarBuilder.append("console.log(\"i=\" + this.i);} a)+ ;\n"); + grammarBuilder.append("console.log(\"i=\"+i);} a)+ ;\n"); grammarBuilder.append("a : {this.i % 2 === 0}? ID {console.log(\"alt 1\");}\n"); grammarBuilder.append(" | {this.i % 2 != 0}? ID {console.log(\"alt 2\");}\n"); grammarBuilder.append(" ;\n"); diff --git a/runtime-testsuite/test/org/antlr/v4/test/runtime/python2/TestSemPredEvalParser.java b/runtime-testsuite/test/org/antlr/v4/test/runtime/python2/TestSemPredEvalParser.java index 3be34563e..99dfa9992 100644 --- a/runtime-testsuite/test/org/antlr/v4/test/runtime/python2/TestSemPredEvalParser.java +++ b/runtime-testsuite/test/org/antlr/v4/test/runtime/python2/TestSemPredEvalParser.java @@ -669,11 +669,11 @@ public class TestSemPredEvalParser extends BasePython2Test { public void testToLeftWithVaryingPredicate() throws Exception { mkdir(tmpdir); - StringBuilder grammarBuilder = new StringBuilder(228); + StringBuilder grammarBuilder = new StringBuilder(226); grammarBuilder.append("grammar T;\n"); grammarBuilder.append("@members {i = 0}\n"); grammarBuilder.append("s : ({self.i += 1\n"); - grammarBuilder.append("print(\"i=\" + str(self.i))} a)+ ;\n"); + grammarBuilder.append("print(str(\"i=\")+str(i))} a)+ ;\n"); grammarBuilder.append("a : {self.i % 2 == 0}? ID {print(\"alt 1\")}\n"); grammarBuilder.append(" | {self.i % 2 != 0}? ID {print(\"alt 2\")}\n"); grammarBuilder.append(" ;\n"); diff --git a/runtime-testsuite/test/org/antlr/v4/test/runtime/python3/TestSemPredEvalParser.java b/runtime-testsuite/test/org/antlr/v4/test/runtime/python3/TestSemPredEvalParser.java index 0db605df7..fbb79d18c 100644 --- a/runtime-testsuite/test/org/antlr/v4/test/runtime/python3/TestSemPredEvalParser.java +++ b/runtime-testsuite/test/org/antlr/v4/test/runtime/python3/TestSemPredEvalParser.java @@ -669,11 +669,11 @@ public class TestSemPredEvalParser extends BasePython3Test { public void testToLeftWithVaryingPredicate() throws Exception { mkdir(tmpdir); - StringBuilder grammarBuilder = new StringBuilder(228); + StringBuilder grammarBuilder = new StringBuilder(226); grammarBuilder.append("grammar T;\n"); grammarBuilder.append("@members {i = 0}\n"); grammarBuilder.append("s : ({self.i += 1\n"); - grammarBuilder.append("print(\"i=\" + str(self.i))} a)+ ;\n"); + grammarBuilder.append("print(str(\"i=\")+str(i))} a)+ ;\n"); grammarBuilder.append("a : {self.i % 2 == 0}? ID {print(\"alt 1\")}\n"); grammarBuilder.append(" | {self.i % 2 != 0}? ID {print(\"alt 2\")}\n"); grammarBuilder.append(" ;\n"); diff --git a/runtime/Cpp/runtime/src/atn/ParserATNSimulator.cpp b/runtime/Cpp/runtime/src/atn/ParserATNSimulator.cpp index d39aee86f..cb2d6e843 100755 --- a/runtime/Cpp/runtime/src/atn/ParserATNSimulator.cpp +++ b/runtime/Cpp/runtime/src/atn/ParserATNSimulator.cpp @@ -194,9 +194,9 @@ int ParserATNSimulator::execATN(dfa::DFA &dfa, dfa::DFAState *s0, TokenStream *i // ATN states in SLL implies LL will also get nowhere. // If conflict in states that dip out, choose min since we // will get error no matter what. - int alt = getAltThatFinishedDecisionEntryRule(previousD->configs); + input->seek(startIndex); + int alt = getSynValidOrSemInvalidAltThatFinishedDecisionEntryRule(previousD->configs, outerContext); if (alt != ATN::INVALID_ALT_NUMBER) { - // return w/o altering DFA return alt; } diff --git a/tool/resources/org/antlr/v4/tool/templates/codegen/Cpp/Cpp.stg b/tool/resources/org/antlr/v4/tool/templates/codegen/Cpp/Cpp.stg index 7d8ce7662..91f08a398 100644 --- a/tool/resources/org/antlr/v4/tool/templates/codegen/Cpp/Cpp.stg +++ b/tool/resources/org/antlr/v4/tool/templates/codegen/Cpp/Cpp.stg @@ -700,7 +700,7 @@ setState(); _errHandler->sync(this); switch (getInterpreter\()->adaptivePredict(_input, , _ctx)) { -+1: { + + 1: { break; \} @@ -714,7 +714,7 @@ setState(); _errHandler->sync(this); alt = getInterpreter\()->adaptivePredict(_input, , _ctx); while (alt != && alt != -1) { - if ( alt == 1 + 1) { + if (alt == 1 + 1) { } @@ -728,7 +728,7 @@ PlusBlockHeader(choice, alts, error) ::= "" PlusBlock(choice, alts, error) ::= << setState(); _errHandler->sync(this); -alt = getInterpreter\()->adaptivePredict(_input, , _ctx); +alt = 1 + 1; do { switch (alt) { + 1: { @@ -742,7 +742,7 @@ do { setState(); _errHandler->sync(this); alt = getInterpreter\()->adaptivePredict(_input, , _ctx); -} while (alt != && alt != -1); +} while (alt != && alt != atn::ATN::INVALID_ALT_NUMBER); >> Sync(s) ::= "Sync(s) sync();"