A few more fixes.

This commit is contained in:
Mike Lischke 2016-06-02 17:32:19 +02:00
parent b7ade0ade1
commit ac664a91b8
21 changed files with 199 additions and 224 deletions

View File

@ -158,75 +158,49 @@ string(text) ::= <<
writeBoolean(o) ::= "<if(o && !isEmpty.(o))>true<else>false<endif>" writeBoolean(o) ::= "<if(o && !isEmpty.(o))>true<else>false<endif>"
writeln(s) ::= "std::cout \<\< <s> \<\< std::endl;" writeln(s) ::= "std::cout \<\< <s> \<\< std::endl;"
write(s) ::= "std::cout \<\< <s>;" write(s) ::= "std::cout \<\< <s>;"
writeList(s) ::= << std::cout \<\< <s; separator=" \<\< "> \<\< std::endl;>>
False() ::= "false" False() ::= "false"
True() ::= "true" True() ::= "true"
Not(v) ::= "!<v>" Not(v) ::= "!<v>"
Assert(s) ::= "" Assert(s) ::= ""
Cast(t,v) ::= "std::dynamic_pointer_cast\<<t>>(<v>)" // Should actually use a more specific name. We may have to use other casts as well. Cast(t,v) ::= "std::dynamic_pointer_cast\<<t>>(<v>)" // Should actually use a more specific name. We may have to use other casts as well.
Append(a,b) ::= "<a> + <b>->toString()" Append(a,b) ::= "<a> + <b>->toString()"
Concat(a,b) ::= "<a><b>" Concat(a,b) ::= "<a><b>"
DeclareLocal(s,v) ::= "<s> = <v>" DeclareLocal(s,v) ::= "<s> = <v>"
AssertIsList(v) ::= "assert(<v>.size() >= 0);" // Use a method that exists only on a list (vector actually). AssertIsList(v) ::= "assert(<v>.size() >= 0);" // Use a method that exists only on a list (vector actually).
AssignLocal(s,v) ::= "<s> = <v>" AssignLocal(s,v) ::= "<s> = <v>"
InitIntMember(n,v) ::= <%int <n> = <v>;%> InitIntMember(n,v) ::= "int <n> = <v>;"
InitBooleanMember(n,v) ::= "bool <n> = <v>;"
InitBooleanMember(n,v) ::= <%bool <n> = <v>;%> GetMember(n) ::= "<n>"
SetMember(n,v) ::= "<n> = <v>;"
GetMember(n) ::= <%<n>%> AddMember(n,v) ::= "<n> += <v>;"
PlusMember(v,n) ::= "<v> + <n>"
SetMember(n,v) ::= <%<n> = <v>%> MemberEquals(n,v) ::= "<n> == <v>"
ModMemberEquals(n,m,v) ::= "<n> % <m> == <v>"
AddMember(n,v) ::= <%<n> += <v>%> ModMemberNotEquals(n,m,v) ::= "<n> % <m> != <v>"
PlusMember(v,n) ::= <%<v> + <n>->toString()%>
MemberEquals(n,v) ::= <%<n> == <v>%>
ModMemberEquals(n,m,v) ::= <%<n> % <m> == <v>%>
ModMemberNotEquals(n,m,v) ::= <%<n> % <m> != <v>%>
DumpDFA() ::= "dumpDFA();" DumpDFA() ::= "dumpDFA();"
Pass() ::= "/* do nothing */" Pass() ::= "/* do nothing */"
StringList() ::= "std::vector\<std::string>" StringList() ::= "std::vector\<std::string>"
BuildParseTrees() ::= "setBuildParseTree(true);"
BuildParseTrees() ::= "setBuildParseTrees(true);"
BailErrorStrategy() ::= "_errHandler = std::make_shared\<BailErrorStrategy>();" BailErrorStrategy() ::= "_errHandler = std::make_shared\<BailErrorStrategy>();"
ToStringTree(s) ::= "<s>->toStringTree(this)" ToStringTree(s) ::= "<s>->toStringTree(this)"
Column() ::= "getCharPositionInLine()" Column() ::= "getCharPositionInLine()"
Text() ::= "getText()" Text() ::= "getText()"
ValEquals(a,b) ::= "<a> == <b>" ValEquals(a,b) ::= "<a> == <b>"
TextEquals(a) ::= "getText() == \"<a>\"" TextEquals(a) ::= "getText() == \"<a>\""
PlusText(a) ::="\"<a>\" + getText()" PlusText(a) ::="\"<a>\" + getText()"
InputText() ::= "_input->getText()" InputText() ::= "_input->getText()"
LTEquals(i, v) ::= "_input->LT(<i>)->getText() == <v>"
LTEquals(i, v) ::= "_input->LT(<i>).text == <v>"
LANotEquals(i, v) ::= "_input->LA(<i>) != <v>" LANotEquals(i, v) ::= "_input->LA(<i>) != <v>"
TokenStartColumnEquals(i) ::= "tokenStartCharPositionInLine == <i>" TokenStartColumnEquals(i) ::= "tokenStartCharPositionInLine == <i>"
ImportListener(X) ::= "" ImportListener(X) ::= ""
@ -432,13 +406,14 @@ Declare_foo() ::= <<void foo() {
Invoke_foo() ::= "foo();" Invoke_foo() ::= "foo();"
Declare_pred() ::= << Declare_pred() ::= <<
void pred(v) { bool pred(bool v) {
std::cout \<\< "eval=" \<\< v->toString().lower(); std::cout \<\< "eval=" \<\< std::boolalpha \<\< v \<\< std::endl;
return v; return v;
} }
>> >>
Invoke_pred(v) ::= <<pred(<v>)>> Invoke_pred(v) ::= <<pred(<v>)>>
ParserTokenType(t) ::= "Parser::<t>" ParserTokenType(t) ::= "Parser::<t>"
ContextRuleFunction(ctx, rule) ::= "<ctx>-><rule>" ContextRuleFunction(ctx, rule) ::= "<ctx>-><rule>"
StringType() ::= "std::string" StringType() ::= "std::string"

View File

@ -148,8 +148,8 @@ string(text) ::= <<
writeBoolean(o) ::= "<if(o && !isEmpty.(o))>true<else>false<endif>" writeBoolean(o) ::= "<if(o && !isEmpty.(o))>true<else>false<endif>"
writeln(s) ::= <<Console.WriteLine(<s>);>> writeln(s) ::= <<Console.WriteLine(<s>);>>
write(s) ::= <<Console.Write(<s>);>> write(s) ::= <<Console.Write(<s>);>>
writeList(s) ::= <<Console.WriteLine(<s; separator="+">);>>
False() ::= "false" False() ::= "false"

View File

@ -155,8 +155,8 @@ string(text) ::= <<
writeBoolean(o) ::= "<if(o && !isEmpty.(o))>true<else>false<endif>" writeBoolean(o) ::= "<if(o && !isEmpty.(o))>true<else>false<endif>"
writeln(s) ::= <<System.out.println(<s>);>> writeln(s) ::= <<System.out.println(<s>);>>
write(s) ::= <<System.out.print(<s>);>> write(s) ::= <<System.out.print(<s>);>>
writeList(s) ::= <<System.out.println(<s; separator="+">);>>
False() ::= "false" False() ::= "false"

View File

@ -154,8 +154,8 @@ string(text) ::= <<
writeBoolean(o) ::= "<if(o && !isEmpty.(o))>true<else>false<endif>" writeBoolean(o) ::= "<if(o && !isEmpty.(o))>true<else>false<endif>"
writeln(s) ::= <<document.getElementById('output').value += <s> + '\\n';>> writeln(s) ::= <<document.getElementById('output').value += <s> + '\\n';>>
write(s) ::= <<document.getElementById('output').value += <s>;>> write(s) ::= <<document.getElementById('output').value += <s>;>>
writeList(s) ::= <<document.getElementById('output').value += <s; separator="+">;>>
False() ::= "false" False() ::= "false"

View File

@ -154,8 +154,8 @@ string(text) ::= <<
writeBoolean(o) ::= "<if(o && !isEmpty.(o))>true<else>false<endif>" writeBoolean(o) ::= "<if(o && !isEmpty.(o))>true<else>false<endif>"
writeln(s) ::= <<document.getElementById('output').value += <s> + '\\n';>> writeln(s) ::= <<document.getElementById('output').value += <s> + '\\n';>>
write(s) ::= <<document.getElementById('output').value += <s>;>> write(s) ::= <<document.getElementById('output').value += <s>;>>
writeList(s) ::= <<document.getElementById('output').value += <s; separator="+">;>>
False() ::= "false" False() ::= "false"

View File

@ -154,8 +154,8 @@ string(text) ::= <<
writeBoolean(o) ::= "<if(o && !isEmpty.(o))>true<else>false<endif>" writeBoolean(o) ::= "<if(o && !isEmpty.(o))>true<else>false<endif>"
writeln(s) ::= <<console.log(<s>);>> writeln(s) ::= <<console.log(<s>);>>
write(s) ::= <<process.stdout.write(<s>);>> write(s) ::= <<process.stdout.write(<s>);>>
writeList(s) ::= <<console.log(<s; separator="+">);>>
False() ::= "false" False() ::= "false"

View File

@ -154,8 +154,8 @@ string(text) ::= <<
writeBoolean(o) ::= "<if(o && !isEmpty.(o))>true<else>false<endif>" writeBoolean(o) ::= "<if(o && !isEmpty.(o))>true<else>false<endif>"
writeln(s) ::= <<document.getElementById('output').value += <s> + '\\n';>> writeln(s) ::= <<document.getElementById('output').value += <s> + '\\n';>>
write(s) ::= <<document.getElementById('output').value += <s>;>> write(s) ::= <<document.getElementById('output').value += <s>;>>
writeList(s) ::= <<document.getElementById('output').value += <s; separator="+">;>>
False() ::= "false" False() ::= "false"

View File

@ -158,8 +158,8 @@ string(text) ::= <<
writeBoolean(o) ::= "<if(o && !isEmpty.(o))>true<else>false<endif>" writeBoolean(o) ::= "<if(o && !isEmpty.(o))>true<else>false<endif>"
writeln(s) ::= <<print(<s>)>> writeln(s) ::= <<print(<s>)>>
write(s) ::= <<print(<s>,end='')>> write(s) ::= <<print(<s>,end='')>>
writeList(s) ::= <<print(<s: {v | str(<v>)}; separator="+">)>>
False() ::= "False" False() ::= "False"

View File

@ -158,8 +158,8 @@ string(text) ::= <<
writeBoolean(o) ::= "<if(o && !isEmpty.(o))>true<else>false<endif>" writeBoolean(o) ::= "<if(o && !isEmpty.(o))>true<else>false<endif>"
writeln(s) ::= <<print(<s>)>> writeln(s) ::= <<print(<s>)>>
write(s) ::= <<print(<s>,end='')>> write(s) ::= <<print(<s>,end='')>>
writeList(s) ::= <<print(<s: {v | str(<v>)}; separator="+">)>>
False() ::= "False" False() ::= "False"

View File

@ -18,7 +18,7 @@ file_
@after {<ToStringTree("$ctx"):writeln()>} @after {<ToStringTree("$ctx"):writeln()>}
: para para EOF ; : para para EOF ;
para: paraContent NL NL ; para: paraContent NL NL ;
paraContent : ('s'|'x'|{<LANotEquals("2",{<grammarName>Parser.NL})>}? NL)+ ; paraContent : ('s'|'x'|{<LANotEquals("2", {<grammarName><ParserTokenType("NL")>})>}? NL)+ ;
NL : '\n' ; NL : '\n' ;
s : 's' ; s : 's' ;
X : 'x' ; X : 'x' ;

View File

@ -33,7 +33,7 @@ grammar(grammarName) ::= <<
grammar <grammarName>; grammar <grammarName>;
@members {<InitIntMember("i","0")>} @members {<InitIntMember("i","0")>}
s : ({<AddMember("i","1")> s : ({<AddMember("i","1")>
<PlusMember("\"i=\"","i"):writeln()>} a)+ ; <writeList(["\"i=\"", "i"])>} a)+ ;
a : {<ModMemberEquals("i","2","0")>}? ID {<writeln("\"alt 1\"")>} a : {<ModMemberEquals("i","2","0")>}? ID {<writeln("\"alt 1\"")>}
| {<ModMemberNotEquals("i","2","0")>}? ID {<writeln("\"alt 2\"")>} | {<ModMemberNotEquals("i","2","0")>}? ID {<writeln("\"alt 2\"")>}
; ;

View File

@ -13,11 +13,11 @@ public class TestParseTrees extends BaseCppTest {
public void test2AltLoop() throws Exception { public void test2AltLoop() throws Exception {
mkdir(tmpdir); mkdir(tmpdir);
StringBuilder grammarBuilder = new StringBuilder(148); StringBuilder grammarBuilder = new StringBuilder(147);
grammarBuilder.append("grammar T;\n"); grammarBuilder.append("grammar T;\n");
grammarBuilder.append("s\n"); grammarBuilder.append("s\n");
grammarBuilder.append("@init {\n"); grammarBuilder.append("@init {\n");
grammarBuilder.append("setBuildParseTrees(true);\n"); grammarBuilder.append("setBuildParseTree(true);\n");
grammarBuilder.append("}\n"); grammarBuilder.append("}\n");
grammarBuilder.append("@after {\n"); grammarBuilder.append("@after {\n");
grammarBuilder.append("std::cout << $r.ctx->toStringTree(this) << std::endl;\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 { public void test2Alts() throws Exception {
mkdir(tmpdir); mkdir(tmpdir);
StringBuilder grammarBuilder = new StringBuilder(141); StringBuilder grammarBuilder = new StringBuilder(140);
grammarBuilder.append("grammar T;\n"); grammarBuilder.append("grammar T;\n");
grammarBuilder.append("s\n"); grammarBuilder.append("s\n");
grammarBuilder.append("@init {\n"); grammarBuilder.append("@init {\n");
grammarBuilder.append("setBuildParseTrees(true);\n"); grammarBuilder.append("setBuildParseTree(true);\n");
grammarBuilder.append("}\n"); grammarBuilder.append("}\n");
grammarBuilder.append("@after {\n"); grammarBuilder.append("@after {\n");
grammarBuilder.append("std::cout << $r.ctx->toStringTree(this) << std::endl;\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 { public void testAltNum() throws Exception {
mkdir(tmpdir); mkdir(tmpdir);
StringBuilder grammarBuilder = new StringBuilder(588); StringBuilder grammarBuilder = new StringBuilder(587);
grammarBuilder.append("grammar T;\n"); grammarBuilder.append("grammar T;\n");
grammarBuilder.append("\n"); grammarBuilder.append("\n");
grammarBuilder.append("options { contextSuperClass=MyRuleNode; }\n"); grammarBuilder.append("options { contextSuperClass=MyRuleNode; }\n");
@ -89,7 +89,7 @@ public class TestParseTrees extends BaseCppTest {
grammarBuilder.append("\n"); grammarBuilder.append("\n");
grammarBuilder.append("s\n"); grammarBuilder.append("s\n");
grammarBuilder.append("@init {\n"); grammarBuilder.append("@init {\n");
grammarBuilder.append("setBuildParseTrees(true);\n"); grammarBuilder.append("setBuildParseTree(true);\n");
grammarBuilder.append("}\n"); grammarBuilder.append("}\n");
grammarBuilder.append("@after {\n"); grammarBuilder.append("@after {\n");
grammarBuilder.append("std::cout << $r.ctx->toStringTree(this) << std::endl;\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 { public void testExtraToken() throws Exception {
mkdir(tmpdir); mkdir(tmpdir);
StringBuilder grammarBuilder = new StringBuilder(154); StringBuilder grammarBuilder = new StringBuilder(153);
grammarBuilder.append("grammar T;\n"); grammarBuilder.append("grammar T;\n");
grammarBuilder.append("s\n"); grammarBuilder.append("s\n");
grammarBuilder.append("@init {\n"); grammarBuilder.append("@init {\n");
grammarBuilder.append("setBuildParseTrees(true);\n"); grammarBuilder.append("setBuildParseTree(true);\n");
grammarBuilder.append("}\n"); grammarBuilder.append("}\n");
grammarBuilder.append("@after {\n"); grammarBuilder.append("@after {\n");
grammarBuilder.append("std::cout << $r.ctx->toStringTree(this) << std::endl;\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 { public void testNoViableAlt() throws Exception {
mkdir(tmpdir); mkdir(tmpdir);
StringBuilder grammarBuilder = new StringBuilder(156); StringBuilder grammarBuilder = new StringBuilder(155);
grammarBuilder.append("grammar T;\n"); grammarBuilder.append("grammar T;\n");
grammarBuilder.append("s\n"); grammarBuilder.append("s\n");
grammarBuilder.append("@init {\n"); grammarBuilder.append("@init {\n");
grammarBuilder.append("setBuildParseTrees(true);\n"); grammarBuilder.append("setBuildParseTree(true);\n");
grammarBuilder.append("}\n"); grammarBuilder.append("}\n");
grammarBuilder.append("@after {\n"); grammarBuilder.append("@after {\n");
grammarBuilder.append("std::cout << $r.ctx->toStringTree(this) << std::endl;\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 { public void testRuleRef() throws Exception {
mkdir(tmpdir); mkdir(tmpdir);
StringBuilder grammarBuilder = new StringBuilder(150); StringBuilder grammarBuilder = new StringBuilder(149);
grammarBuilder.append("grammar T;\n"); grammarBuilder.append("grammar T;\n");
grammarBuilder.append("s\n"); grammarBuilder.append("s\n");
grammarBuilder.append("@init {\n"); grammarBuilder.append("@init {\n");
grammarBuilder.append("setBuildParseTrees(true);\n"); grammarBuilder.append("setBuildParseTree(true);\n");
grammarBuilder.append("}\n"); grammarBuilder.append("}\n");
grammarBuilder.append("@after {\n"); grammarBuilder.append("@after {\n");
grammarBuilder.append("std::cout << $r.ctx->toStringTree(this) << std::endl;\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 { public void testSync() throws Exception {
mkdir(tmpdir); mkdir(tmpdir);
StringBuilder grammarBuilder = new StringBuilder(157); StringBuilder grammarBuilder = new StringBuilder(156);
grammarBuilder.append("grammar T;\n"); grammarBuilder.append("grammar T;\n");
grammarBuilder.append("s\n"); grammarBuilder.append("s\n");
grammarBuilder.append("@init {\n"); grammarBuilder.append("@init {\n");
grammarBuilder.append("setBuildParseTrees(true);\n"); grammarBuilder.append("setBuildParseTree(true);\n");
grammarBuilder.append("}\n"); grammarBuilder.append("}\n");
grammarBuilder.append("@after {\n"); grammarBuilder.append("@after {\n");
grammarBuilder.append("std::cout << $r.ctx->toStringTree(this) << std::endl;\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 { public void testToken2() throws Exception {
mkdir(tmpdir); mkdir(tmpdir);
StringBuilder grammarBuilder = new StringBuilder(139); StringBuilder grammarBuilder = new StringBuilder(138);
grammarBuilder.append("grammar T;\n"); grammarBuilder.append("grammar T;\n");
grammarBuilder.append("s\n"); grammarBuilder.append("s\n");
grammarBuilder.append("@init {\n"); grammarBuilder.append("@init {\n");
grammarBuilder.append("setBuildParseTrees(true);\n"); grammarBuilder.append("setBuildParseTree(true);\n");
grammarBuilder.append("}\n"); grammarBuilder.append("}\n");
grammarBuilder.append("@after {\n"); grammarBuilder.append("@after {\n");
grammarBuilder.append("std::cout << $r.ctx->toStringTree(this) << std::endl;\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 { public void testTokenAndRuleContextString() throws Exception {
mkdir(tmpdir); mkdir(tmpdir);
StringBuilder grammarBuilder = new StringBuilder(218); StringBuilder grammarBuilder = new StringBuilder(217);
grammarBuilder.append("grammar T;\n"); grammarBuilder.append("grammar T;\n");
grammarBuilder.append("s\n"); grammarBuilder.append("s\n");
grammarBuilder.append("@init {\n"); grammarBuilder.append("@init {\n");
grammarBuilder.append("setBuildParseTrees(true);\n"); grammarBuilder.append("setBuildParseTree(true);\n");
grammarBuilder.append("}\n"); grammarBuilder.append("}\n");
grammarBuilder.append("@after {\n"); grammarBuilder.append("@after {\n");
grammarBuilder.append("std::cout << $r.ctx->toStringTree(this) << std::endl;\n"); grammarBuilder.append("std::cout << $r.ctx->toStringTree(this) << std::endl;\n");

View File

@ -13,12 +13,12 @@ public class TestSemPredEvalParser extends BaseCppTest {
public void test2UnpredicatedAlts() throws Exception { public void test2UnpredicatedAlts() throws Exception {
mkdir(tmpdir); mkdir(tmpdir);
StringBuilder grammarBuilder = new StringBuilder(316); StringBuilder grammarBuilder = new StringBuilder(374);
grammarBuilder.append("grammar T;\n"); 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("s : {getInterpreter<atn::ParserATNSimulator>()->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\" << \"\\n\";}\n"); grammarBuilder.append("a : ID {std::cout << \"alt 1\" << std::endl;}\n");
grammarBuilder.append(" | ID {std::cout << \"alt 2\" << \"\\n\";}\n"); grammarBuilder.append(" | ID {std::cout << \"alt 2\" << std::endl;}\n");
grammarBuilder.append(" | {false}? ID {std::cout << \"alt 3\" << \"\\n\";}\n"); grammarBuilder.append(" | {false}? ID {std::cout << \"alt 3\" << std::endl;}\n");
grammarBuilder.append(" ;\n"); grammarBuilder.append(" ;\n");
grammarBuilder.append("ID : 'a'..'z'+ ;\n"); grammarBuilder.append("ID : 'a'..'z'+ ;\n");
grammarBuilder.append("INT : '0'..'9'+;\n"); grammarBuilder.append("INT : '0'..'9'+;\n");
@ -46,13 +46,13 @@ public class TestSemPredEvalParser extends BaseCppTest {
public void test2UnpredicatedAltsAndOneOrthogonalAlt() throws Exception { public void test2UnpredicatedAltsAndOneOrthogonalAlt() throws Exception {
mkdir(tmpdir); mkdir(tmpdir);
StringBuilder grammarBuilder = new StringBuilder(376); StringBuilder grammarBuilder = new StringBuilder(439);
grammarBuilder.append("grammar T;\n"); grammarBuilder.append("grammar T;\n");
grammarBuilder.append("s : {_interp.predictionMode = PredictionMode.LL_EXACT_AMBIG_DETECTION} a ';' a ';' a;\n"); grammarBuilder.append("s : {getInterpreter<atn::ParserATNSimulator>()->setPredictionMode(atn::PredictionMode::LL_EXACT_AMBIG_DETECTION);} a ';' a ';' a;\n");
grammarBuilder.append("a : INT {std::cout << \"alt 1\" << \"\\n\";}\n"); grammarBuilder.append("a : INT {std::cout << \"alt 1\" << std::endl;}\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 2\" << std::endl;} // must pick this one for ID since pred is false\n");
grammarBuilder.append(" | ID {std::cout << \"alt 3\" << \"\\n\";}\n"); grammarBuilder.append(" | ID {std::cout << \"alt 3\" << std::endl;}\n");
grammarBuilder.append(" | {false}? ID {std::cout << \"alt 4\" << \"\\n\";}\n"); grammarBuilder.append(" | {false}? ID {std::cout << \"alt 4\" << std::endl;}\n");
grammarBuilder.append(" ;\n"); grammarBuilder.append(" ;\n");
grammarBuilder.append("ID : 'a'..'z'+ ;\n"); grammarBuilder.append("ID : 'a'..'z'+ ;\n");
grammarBuilder.append("INT : '0'..'9'+;\n"); grammarBuilder.append("INT : '0'..'9'+;\n");
@ -81,12 +81,12 @@ public class TestSemPredEvalParser extends BaseCppTest {
public void testActionHidesPreds() throws Exception { public void testActionHidesPreds() throws Exception {
mkdir(tmpdir); mkdir(tmpdir);
StringBuilder grammarBuilder = new StringBuilder(214); StringBuilder grammarBuilder = new StringBuilder(231);
grammarBuilder.append("grammar T;\n"); 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("s : a+ ;\n");
grammarBuilder.append("a : {i = 1} ID {i == 1}? {std::cout << \"alt 1\" << \"\\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\" << \"\\n\";}\n"); grammarBuilder.append(" | {i = 2;} ID {i == 2}? {std::cout << \"alt 2\" << std::endl;}\n");
grammarBuilder.append(" ;\n"); grammarBuilder.append(" ;\n");
grammarBuilder.append("ID : 'a'..'z'+ ;\n"); grammarBuilder.append("ID : 'a'..'z'+ ;\n");
grammarBuilder.append("INT : '0'..'9'+;\n"); grammarBuilder.append("INT : '0'..'9'+;\n");
@ -110,15 +110,15 @@ public class TestSemPredEvalParser extends BaseCppTest {
public void testActionsHidePredsInGlobalFOLLOW() throws Exception { public void testActionsHidePredsInGlobalFOLLOW() throws Exception {
mkdir(tmpdir); mkdir(tmpdir);
StringBuilder grammarBuilder = new StringBuilder(282); StringBuilder grammarBuilder = new StringBuilder(308);
grammarBuilder.append("grammar T;\n"); grammarBuilder.append("grammar T;\n");
grammarBuilder.append("@members {\n"); grammarBuilder.append("@members {\n");
grammarBuilder.append("def pred(self, v):\n"); grammarBuilder.append("bool pred(bool v) {\n");
grammarBuilder.append(" std::cout << \"eval=\" << str(v).lower();\n"); grammarBuilder.append(" std::cout << \"eval=\" << std::boolalpha << v << std::endl;\n");
grammarBuilder.append(" return v\n"); grammarBuilder.append(" return v;\n");
grammarBuilder.append("\n");
grammarBuilder.append("}\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("t : e {} {pred(false)}? ID ;\n");
grammarBuilder.append("e : ID | ; // non-LL(1) so we use ATN\n"); grammarBuilder.append("e : ID | ; // non-LL(1) so we use ATN\n");
grammarBuilder.append("ID : 'a'..'z'+ ;\n"); grammarBuilder.append("ID : 'a'..'z'+ ;\n");
@ -164,17 +164,17 @@ public class TestSemPredEvalParser extends BaseCppTest {
public void testDepedentPredsInGlobalFOLLOW() throws Exception { public void testDepedentPredsInGlobalFOLLOW() throws Exception {
mkdir(tmpdir); mkdir(tmpdir);
StringBuilder grammarBuilder = new StringBuilder(305); StringBuilder grammarBuilder = new StringBuilder(335);
grammarBuilder.append("grammar T;\n"); grammarBuilder.append("grammar T;\n");
grammarBuilder.append("@members {\n"); grammarBuilder.append("@members {\n");
grammarBuilder.append("def pred(self, v):\n"); grammarBuilder.append("bool pred(bool v) {\n");
grammarBuilder.append(" std::cout << \"eval=\" << str(v).lower();\n"); grammarBuilder.append(" std::cout << \"eval=\" << std::boolalpha << v << std::endl;\n");
grammarBuilder.append(" return v\n"); grammarBuilder.append(" return v;\n");
grammarBuilder.append("\n"); grammarBuilder.append("}\n");
grammarBuilder.append("}\n"); grammarBuilder.append("}\n");
grammarBuilder.append("s : a[99] ;\n"); grammarBuilder.append("s : a[99] ;\n");
grammarBuilder.append("a[int i] : e {pred($i==99)}? {std::cout << \"parse\" << \"\\n\";} '!' ;\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("b[int i] : e {pred($i == 99)}? ID ;\n");
grammarBuilder.append("e : ID | ; // non-LL(1) so we use ATN\n"); grammarBuilder.append("e : ID | ; // non-LL(1) so we use ATN\n");
grammarBuilder.append("ID : 'a'..'z'+ ;\n"); grammarBuilder.append("ID : 'a'..'z'+ ;\n");
grammarBuilder.append("INT : '0'..'9'+;\n"); grammarBuilder.append("INT : '0'..'9'+;\n");
@ -197,13 +197,13 @@ public class TestSemPredEvalParser extends BaseCppTest {
public void testDependentPredNotInOuterCtxShouldBeIgnored() throws Exception { public void testDependentPredNotInOuterCtxShouldBeIgnored() throws Exception {
mkdir(tmpdir); mkdir(tmpdir);
StringBuilder grammarBuilder = new StringBuilder(286); StringBuilder grammarBuilder = new StringBuilder(300);
grammarBuilder.append("grammar T;\n"); 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("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("b[int i] : a[i] ;\n");
grammarBuilder.append("a[int i]\n"); grammarBuilder.append("a[int i]\n");
grammarBuilder.append(" : {$i==1}? ID {std::cout << \"alt 1\" << \"\\n\";}\n"); grammarBuilder.append(" : {$i == 1}? ID {std::cout << \"alt 1\" << std::endl;}\n");
grammarBuilder.append(" | {$i==2}? ID {std::cout << \"alt 2\" << \"\\n\";}\n"); grammarBuilder.append(" | {$i == 2}? ID {std::cout << \"alt 2\" << std::endl;}\n");
grammarBuilder.append(" ;\n"); grammarBuilder.append(" ;\n");
grammarBuilder.append("ID : 'a'..'z'+ ;\n"); grammarBuilder.append("ID : 'a'..'z'+ ;\n");
grammarBuilder.append("INT : '0'..'9'+;\n"); grammarBuilder.append("INT : '0'..'9'+;\n");
@ -246,13 +246,13 @@ public class TestSemPredEvalParser extends BaseCppTest {
public void testIndependentPredNotPassedOuterCtxToAvoidCastException() throws Exception { public void testIndependentPredNotPassedOuterCtxToAvoidCastException() throws Exception {
mkdir(tmpdir); mkdir(tmpdir);
StringBuilder grammarBuilder = new StringBuilder(199); StringBuilder grammarBuilder = new StringBuilder(209);
grammarBuilder.append("grammar T;\n"); grammarBuilder.append("grammar T;\n");
grammarBuilder.append("s : b ';' | b '.' ;\n"); grammarBuilder.append("s : b ';' | b '.' ;\n");
grammarBuilder.append("b : a ;\n"); grammarBuilder.append("b : a ;\n");
grammarBuilder.append("a\n"); grammarBuilder.append("a\n");
grammarBuilder.append(" : {false}? ID {std::cout << \"alt 1\" << \"\\n\";}\n"); grammarBuilder.append(" : {false}? ID {std::cout << \"alt 1\" << std::endl;}\n");
grammarBuilder.append(" | {true}? ID {std::cout << \"alt 2\" << \"\\n\";}\n"); grammarBuilder.append(" | {true}? ID {std::cout << \"alt 2\" << std::endl;}\n");
grammarBuilder.append(" ;\n"); grammarBuilder.append(" ;\n");
grammarBuilder.append("ID : 'a'..'z'+ ;\n"); grammarBuilder.append("ID : 'a'..'z'+ ;\n");
grammarBuilder.append("INT : '0'..'9'+;\n"); grammarBuilder.append("INT : '0'..'9'+;\n");
@ -273,11 +273,11 @@ public class TestSemPredEvalParser extends BaseCppTest {
public void testNoTruePredsThrowsNoViableAlt() throws Exception { public void testNoTruePredsThrowsNoViableAlt() throws Exception {
mkdir(tmpdir); mkdir(tmpdir);
StringBuilder grammarBuilder = new StringBuilder(187); StringBuilder grammarBuilder = new StringBuilder(197);
grammarBuilder.append("grammar T;\n"); grammarBuilder.append("grammar T;\n");
grammarBuilder.append("s : a a;\n"); grammarBuilder.append("s : a a;\n");
grammarBuilder.append("a : {false}? ID INT {std::cout << \"alt 1\" << \"\\n\";}\n"); grammarBuilder.append("a : {false}? ID INT {std::cout << \"alt 1\" << std::endl;}\n");
grammarBuilder.append(" | {false}? ID INT {std::cout << \"alt 2\" << \"\\n\";}\n"); grammarBuilder.append(" | {false}? ID INT {std::cout << \"alt 2\" << std::endl;}\n");
grammarBuilder.append(" ;\n"); grammarBuilder.append(" ;\n");
grammarBuilder.append("ID : 'a'..'z'+ ;\n"); grammarBuilder.append("ID : 'a'..'z'+ ;\n");
grammarBuilder.append("INT : '0'..'9'+;\n"); grammarBuilder.append("INT : '0'..'9'+;\n");
@ -299,13 +299,13 @@ public class TestSemPredEvalParser extends BaseCppTest {
public void testOrder() throws Exception { public void testOrder() throws Exception {
mkdir(tmpdir); mkdir(tmpdir);
StringBuilder grammarBuilder = new StringBuilder(313); StringBuilder grammarBuilder = new StringBuilder(323);
grammarBuilder.append("grammar T;\n"); grammarBuilder.append("grammar T;\n");
grammarBuilder.append("s : a {} a; // do 2x: once in ATN, next in DFA;\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("// action blocks lookahead from falling off of 'a'\n");
grammarBuilder.append("// and looking into 2nd 'a' ref. !ctx dependent pred\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("a : ID {std::cout << \"alt 1\" << std::endl;}\n");
grammarBuilder.append(" | {true}? ID {std::cout << \"alt 2\" << \"\\n\";}\n"); grammarBuilder.append(" | {true}? ID {std::cout << \"alt 2\" << std::endl;}\n");
grammarBuilder.append(" ;\n"); grammarBuilder.append(" ;\n");
grammarBuilder.append("ID : 'a'..'z'+ ;\n"); grammarBuilder.append("ID : 'a'..'z'+ ;\n");
grammarBuilder.append("INT : '0'..'9'+;\n"); grammarBuilder.append("INT : '0'..'9'+;\n");
@ -328,13 +328,13 @@ public class TestSemPredEvalParser extends BaseCppTest {
public void testPredFromAltTestedInLoopBack_1() throws Exception { public void testPredFromAltTestedInLoopBack_1() throws Exception {
mkdir(tmpdir); mkdir(tmpdir);
StringBuilder grammarBuilder = new StringBuilder(214); StringBuilder grammarBuilder = new StringBuilder(217);
grammarBuilder.append("grammar T;\n"); grammarBuilder.append("grammar T;\n");
grammarBuilder.append("file_\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 para EOF ;\n");
grammarBuilder.append("para: paraContent NL NL ;\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("NL : '\\n' ;\n");
grammarBuilder.append("s : 's' ;\n"); grammarBuilder.append("s : 's' ;\n");
grammarBuilder.append("X : 'x' ;"); grammarBuilder.append("X : 'x' ;");
@ -361,13 +361,13 @@ public class TestSemPredEvalParser extends BaseCppTest {
public void testPredFromAltTestedInLoopBack_2() throws Exception { public void testPredFromAltTestedInLoopBack_2() throws Exception {
mkdir(tmpdir); mkdir(tmpdir);
StringBuilder grammarBuilder = new StringBuilder(214); StringBuilder grammarBuilder = new StringBuilder(217);
grammarBuilder.append("grammar T;\n"); grammarBuilder.append("grammar T;\n");
grammarBuilder.append("file_\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 para EOF ;\n");
grammarBuilder.append("para: paraContent NL NL ;\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("NL : '\\n' ;\n");
grammarBuilder.append("s : 's' ;\n"); grammarBuilder.append("s : 's' ;\n");
grammarBuilder.append("X : 'x' ;"); grammarBuilder.append("X : 'x' ;");
@ -392,12 +392,12 @@ public class TestSemPredEvalParser extends BaseCppTest {
public void testPredTestedEvenWhenUnAmbig_1() throws Exception { public void testPredTestedEvenWhenUnAmbig_1() throws Exception {
mkdir(tmpdir); mkdir(tmpdir);
StringBuilder grammarBuilder = new StringBuilder(206); StringBuilder grammarBuilder = new StringBuilder(222);
grammarBuilder.append("grammar T;\n"); grammarBuilder.append("grammar T;\n");
grammarBuilder.append("@members {enumKeyword = true}\n"); grammarBuilder.append("@members {bool enumKeyword = true;}\n");
grammarBuilder.append("primary\n"); grammarBuilder.append("primary\n");
grammarBuilder.append(" : ID {std::cout << \"ID \"+$ID.text << \"\\n\";}\n"); grammarBuilder.append(" : ID {std::cout << \"ID \"+$ID.text << std::endl;}\n");
grammarBuilder.append(" | {!enumKeyword}? 'enum' {std::cout << \"enum\" << \"\\n\";}\n"); grammarBuilder.append(" | {!enumKeyword}? 'enum' {std::cout << \"enum\" << std::endl;}\n");
grammarBuilder.append(" ;\n"); grammarBuilder.append(" ;\n");
grammarBuilder.append("ID : [a-z]+ ;\n"); grammarBuilder.append("ID : [a-z]+ ;\n");
grammarBuilder.append("WS : [ \\t\\n\\r]+ -> skip ;"); grammarBuilder.append("WS : [ \\t\\n\\r]+ -> skip ;");
@ -417,12 +417,12 @@ public class TestSemPredEvalParser extends BaseCppTest {
public void testPredTestedEvenWhenUnAmbig_2() throws Exception { public void testPredTestedEvenWhenUnAmbig_2() throws Exception {
mkdir(tmpdir); mkdir(tmpdir);
StringBuilder grammarBuilder = new StringBuilder(206); StringBuilder grammarBuilder = new StringBuilder(222);
grammarBuilder.append("grammar T;\n"); grammarBuilder.append("grammar T;\n");
grammarBuilder.append("@members {enumKeyword = true}\n"); grammarBuilder.append("@members {bool enumKeyword = true;}\n");
grammarBuilder.append("primary\n"); grammarBuilder.append("primary\n");
grammarBuilder.append(" : ID {std::cout << \"ID \"+$ID.text << \"\\n\";}\n"); grammarBuilder.append(" : ID {std::cout << \"ID \"+$ID.text << std::endl;}\n");
grammarBuilder.append(" | {!enumKeyword}? 'enum' {std::cout << \"enum\" << \"\\n\";}\n"); grammarBuilder.append(" | {!enumKeyword}? 'enum' {std::cout << \"enum\" << std::endl;}\n");
grammarBuilder.append(" ;\n"); grammarBuilder.append(" ;\n");
grammarBuilder.append("ID : [a-z]+ ;\n"); grammarBuilder.append("ID : [a-z]+ ;\n");
grammarBuilder.append("WS : [ \\t\\n\\r]+ -> skip ;"); grammarBuilder.append("WS : [ \\t\\n\\r]+ -> skip ;");
@ -443,13 +443,13 @@ public class TestSemPredEvalParser extends BaseCppTest {
public void testPredicateDependentOnArg() throws Exception { public void testPredicateDependentOnArg() throws Exception {
mkdir(tmpdir); mkdir(tmpdir);
StringBuilder grammarBuilder = new StringBuilder(211); StringBuilder grammarBuilder = new StringBuilder(230);
grammarBuilder.append("grammar T;\n"); 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("s : a[2] a[1];\n");
grammarBuilder.append("a[int i]\n"); grammarBuilder.append("a[int i]\n");
grammarBuilder.append(" : {$i==1}? ID {std::cout << \"alt 1\" << \"\\n\";}\n"); grammarBuilder.append(" : {$i == 1}? ID {std::cout << \"alt 1\" << std::endl;}\n");
grammarBuilder.append(" | {$i==2}? ID {std::cout << \"alt 2\" << \"\\n\";}\n"); grammarBuilder.append(" | {$i == 2}? ID {std::cout << \"alt 2\" << std::endl;}\n");
grammarBuilder.append(" ;\n"); grammarBuilder.append(" ;\n");
grammarBuilder.append("ID : 'a'..'z'+ ;\n"); grammarBuilder.append("ID : 'a'..'z'+ ;\n");
grammarBuilder.append("INT : '0'..'9'+;\n"); grammarBuilder.append("INT : '0'..'9'+;\n");
@ -472,13 +472,13 @@ public class TestSemPredEvalParser extends BaseCppTest {
public void testPredicateDependentOnArg2() throws Exception { public void testPredicateDependentOnArg2() throws Exception {
mkdir(tmpdir); mkdir(tmpdir);
StringBuilder grammarBuilder = new StringBuilder(149); StringBuilder grammarBuilder = new StringBuilder(158);
grammarBuilder.append("grammar T;\n"); 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("s : a[2] a[1];\n");
grammarBuilder.append("a[int i]\n"); grammarBuilder.append("a[int i]\n");
grammarBuilder.append(" : {$i==1}? ID \n"); grammarBuilder.append(" : {$i == 1}? ID \n");
grammarBuilder.append(" | {$i==2}? ID \n"); grammarBuilder.append(" | {$i == 2}? ID \n");
grammarBuilder.append(" ;\n"); grammarBuilder.append(" ;\n");
grammarBuilder.append("ID : 'a'..'z'+ ;\n"); grammarBuilder.append("ID : 'a'..'z'+ ;\n");
grammarBuilder.append("INT : '0'..'9'+;\n"); grammarBuilder.append("INT : '0'..'9'+;\n");
@ -499,15 +499,15 @@ public class TestSemPredEvalParser extends BaseCppTest {
public void testPredsInGlobalFOLLOW() throws Exception { public void testPredsInGlobalFOLLOW() throws Exception {
mkdir(tmpdir); mkdir(tmpdir);
StringBuilder grammarBuilder = new StringBuilder(276); StringBuilder grammarBuilder = new StringBuilder(302);
grammarBuilder.append("grammar T;\n"); grammarBuilder.append("grammar T;\n");
grammarBuilder.append("@members {\n"); grammarBuilder.append("@members {\n");
grammarBuilder.append("def pred(self, v):\n"); grammarBuilder.append("bool pred(bool v) {\n");
grammarBuilder.append(" std::cout << \"eval=\" << str(v).lower();\n"); grammarBuilder.append(" std::cout << \"eval=\" << std::boolalpha << v << std::endl;\n");
grammarBuilder.append(" return v\n"); grammarBuilder.append(" return v;\n");
grammarBuilder.append("\n");
grammarBuilder.append("}\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("t : e {pred(false)}? ID ;\n");
grammarBuilder.append("e : ID | ; // non-LL(1) so we use ATN\n"); grammarBuilder.append("e : ID | ; // non-LL(1) so we use ATN\n");
grammarBuilder.append("ID : 'a'..'z'+ ;\n"); grammarBuilder.append("ID : 'a'..'z'+ ;\n");
@ -531,11 +531,11 @@ public class TestSemPredEvalParser extends BaseCppTest {
public void testRewindBeforePredEval() throws Exception { public void testRewindBeforePredEval() throws Exception {
mkdir(tmpdir); mkdir(tmpdir);
StringBuilder grammarBuilder = new StringBuilder(223); StringBuilder grammarBuilder = new StringBuilder(249);
grammarBuilder.append("grammar T;\n"); grammarBuilder.append("grammar T;\n");
grammarBuilder.append("s : a a;\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("a : {_input->LT(1)->getText() == \"x\"}? ID INT {std::cout << \"alt 1\" << std::endl;}\n");
grammarBuilder.append(" | {_input->LT(1).text==\"y\"}? ID INT {std::cout << \"alt 2\" << \"\\n\";}\n"); grammarBuilder.append(" | {_input->LT(1)->getText() == \"y\"}? ID INT {std::cout << \"alt 2\" << std::endl;}\n");
grammarBuilder.append(" ;\n"); grammarBuilder.append(" ;\n");
grammarBuilder.append("ID : 'a'..'z'+ ;\n"); grammarBuilder.append("ID : 'a'..'z'+ ;\n");
grammarBuilder.append("INT : '0'..'9'+;\n"); grammarBuilder.append("INT : '0'..'9'+;\n");
@ -558,12 +558,12 @@ public class TestSemPredEvalParser extends BaseCppTest {
public void testSimple() throws Exception { public void testSimple() throws Exception {
mkdir(tmpdir); mkdir(tmpdir);
StringBuilder grammarBuilder = new StringBuilder(280); StringBuilder grammarBuilder = new StringBuilder(295);
grammarBuilder.append("grammar T;\n"); 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("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("a : {false}? ID {std::cout << \"alt 1\" << std::endl;}\n");
grammarBuilder.append(" | {true}? ID {std::cout << \"alt 2\" << \"\\n\";}\n"); grammarBuilder.append(" | {true}? ID {std::cout << \"alt 2\" << std::endl;}\n");
grammarBuilder.append(" | INT {std::cout << \"alt 3\" << \"\\n\";}\n"); grammarBuilder.append(" | INT {std::cout << \"alt 3\" << std::endl;}\n");
grammarBuilder.append(" ;\n"); grammarBuilder.append(" ;\n");
grammarBuilder.append("ID : 'a'..'z'+ ;\n"); grammarBuilder.append("ID : 'a'..'z'+ ;\n");
grammarBuilder.append("INT : '0'..'9'+;\n"); grammarBuilder.append("INT : '0'..'9'+;\n");
@ -587,11 +587,11 @@ public class TestSemPredEvalParser extends BaseCppTest {
public void testSimpleValidate() throws Exception { public void testSimpleValidate() throws Exception {
mkdir(tmpdir); mkdir(tmpdir);
StringBuilder grammarBuilder = new StringBuilder(180); StringBuilder grammarBuilder = new StringBuilder(190);
grammarBuilder.append("grammar T;\n"); grammarBuilder.append("grammar T;\n");
grammarBuilder.append("s : a ;\n"); grammarBuilder.append("s : a ;\n");
grammarBuilder.append("a : {false}? ID {std::cout << \"alt 1\" << \"\\n\";}\n"); grammarBuilder.append("a : {false}? ID {std::cout << \"alt 1\" << std::endl;}\n");
grammarBuilder.append(" | {true}? INT {std::cout << \"alt 2\" << \"\\n\";}\n"); grammarBuilder.append(" | {true}? INT {std::cout << \"alt 2\" << std::endl;}\n");
grammarBuilder.append(" ;\n"); grammarBuilder.append(" ;\n");
grammarBuilder.append("ID : 'a'..'z'+ ;\n"); grammarBuilder.append("ID : 'a'..'z'+ ;\n");
grammarBuilder.append("INT : '0'..'9'+;\n"); grammarBuilder.append("INT : '0'..'9'+;\n");
@ -613,11 +613,11 @@ public class TestSemPredEvalParser extends BaseCppTest {
public void testSimpleValidate2() throws Exception { public void testSimpleValidate2() throws Exception {
mkdir(tmpdir); mkdir(tmpdir);
StringBuilder grammarBuilder = new StringBuilder(183); StringBuilder grammarBuilder = new StringBuilder(193);
grammarBuilder.append("grammar T;\n"); grammarBuilder.append("grammar T;\n");
grammarBuilder.append("s : a a a;\n"); grammarBuilder.append("s : a a a;\n");
grammarBuilder.append("a : {false}? ID {std::cout << \"alt 1\" << \"\\n\";}\n"); grammarBuilder.append("a : {false}? ID {std::cout << \"alt 1\" << std::endl;}\n");
grammarBuilder.append(" | {true}? INT {std::cout << \"alt 2\" << \"\\n\";}\n"); grammarBuilder.append(" | {true}? INT {std::cout << \"alt 2\" << std::endl;}\n");
grammarBuilder.append(" ;\n"); grammarBuilder.append(" ;\n");
grammarBuilder.append("ID : 'a'..'z'+ ;\n"); grammarBuilder.append("ID : 'a'..'z'+ ;\n");
grammarBuilder.append("INT : '0'..'9'+;\n"); grammarBuilder.append("INT : '0'..'9'+;\n");
@ -641,11 +641,11 @@ public class TestSemPredEvalParser extends BaseCppTest {
public void testToLeft() throws Exception { public void testToLeft() throws Exception {
mkdir(tmpdir); mkdir(tmpdir);
StringBuilder grammarBuilder = new StringBuilder(180); StringBuilder grammarBuilder = new StringBuilder(190);
grammarBuilder.append("grammar T;\n"); grammarBuilder.append("grammar T;\n");
grammarBuilder.append(" s : a+ ;\n"); grammarBuilder.append(" s : a+ ;\n");
grammarBuilder.append("a : {false}? ID {std::cout << \"alt 1\" << \"\\n\";}\n"); grammarBuilder.append("a : {false}? ID {std::cout << \"alt 1\" << std::endl;}\n");
grammarBuilder.append(" | {true}? ID {std::cout << \"alt 2\" << \"\\n\";}\n"); grammarBuilder.append(" | {true}? ID {std::cout << \"alt 2\" << std::endl;}\n");
grammarBuilder.append(" ;\n"); grammarBuilder.append(" ;\n");
grammarBuilder.append("ID : 'a'..'z'+ ;\n"); grammarBuilder.append("ID : 'a'..'z'+ ;\n");
grammarBuilder.append("INT : '0'..'9'+;\n"); grammarBuilder.append("INT : '0'..'9'+;\n");
@ -669,13 +669,13 @@ public class TestSemPredEvalParser extends BaseCppTest {
public void testToLeftWithVaryingPredicate() throws Exception { public void testToLeftWithVaryingPredicate() throws Exception {
mkdir(tmpdir); mkdir(tmpdir);
StringBuilder grammarBuilder = new StringBuilder(259); StringBuilder grammarBuilder = new StringBuilder(271);
grammarBuilder.append("grammar T;\n"); grammarBuilder.append("grammar T;\n");
grammarBuilder.append("@members {i = 0}\n"); grammarBuilder.append("@members {int i = 0;}\n");
grammarBuilder.append("s : ({i += 1\n"); grammarBuilder.append("s : ({i += 1;\n");
grammarBuilder.append("std::cout << \"i=\" + i.toString() << \"\\n\";} a)+ ;\n"); grammarBuilder.append(" std::cout << \"i=\" << i << std::endl;} a)+ ;\n");
grammarBuilder.append("a : {i % 2 == 0}? ID {std::cout << \"alt 1\" << \"\\n\";}\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\" << \"\\n\";}\n"); grammarBuilder.append(" | {i % 2 != 0}? ID {std::cout << \"alt 2\" << std::endl;}\n");
grammarBuilder.append(" ;\n"); grammarBuilder.append(" ;\n");
grammarBuilder.append("ID : 'a'..'z'+ ;\n"); grammarBuilder.append("ID : 'a'..'z'+ ;\n");
grammarBuilder.append("INT : '0'..'9'+;\n"); grammarBuilder.append("INT : '0'..'9'+;\n");
@ -702,10 +702,10 @@ public class TestSemPredEvalParser extends BaseCppTest {
public void testUnpredicatedPathsInAlt() throws Exception { public void testUnpredicatedPathsInAlt() throws Exception {
mkdir(tmpdir); mkdir(tmpdir);
StringBuilder grammarBuilder = new StringBuilder(199); StringBuilder grammarBuilder = new StringBuilder(209);
grammarBuilder.append("grammar T;\n"); grammarBuilder.append("grammar T;\n");
grammarBuilder.append("s : a {std::cout << \"alt 1\" << \"\\n\";}\n"); grammarBuilder.append("s : a {std::cout << \"alt 1\" << std::endl;}\n");
grammarBuilder.append(" | b {std::cout << \"alt 2\" << \"\\n\";}\n"); grammarBuilder.append(" | b {std::cout << \"alt 2\" << std::endl;}\n");
grammarBuilder.append(" ;\n"); grammarBuilder.append(" ;\n");
grammarBuilder.append("a : {false}? ID INT\n"); grammarBuilder.append("a : {false}? ID INT\n");
grammarBuilder.append(" | ID INT\n"); grammarBuilder.append(" | ID INT\n");
@ -731,14 +731,14 @@ public class TestSemPredEvalParser extends BaseCppTest {
public void testValidateInDFA() throws Exception { public void testValidateInDFA() throws Exception {
mkdir(tmpdir); mkdir(tmpdir);
StringBuilder grammarBuilder = new StringBuilder(348); StringBuilder grammarBuilder = new StringBuilder(358);
grammarBuilder.append("grammar T;\n"); grammarBuilder.append("grammar T;\n");
grammarBuilder.append("s : a ';' a;\n"); grammarBuilder.append("s : a ';' a;\n");
grammarBuilder.append("// ';' helps us to resynchronize without consuming\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("// 2nd 'a' reference. We our testing that the DFA also\n");
grammarBuilder.append("// throws an exception if the validating predicate fails\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("a : {false}? ID {std::cout << \"alt 1\" << std::endl;}\n");
grammarBuilder.append(" | {true}? INT {std::cout << \"alt 2\" << \"\\n\";}\n"); grammarBuilder.append(" | {true}? INT {std::cout << \"alt 2\" << std::endl;}\n");
grammarBuilder.append(" ;\n"); grammarBuilder.append(" ;\n");
grammarBuilder.append("ID : 'a'..'z'+ ;\n"); grammarBuilder.append("ID : 'a'..'z'+ ;\n");
grammarBuilder.append("INT : '0'..'9'+;\n"); grammarBuilder.append("INT : '0'..'9'+;\n");

View File

@ -13,9 +13,9 @@ public class TestSets extends BaseCppTest {
public void testCharSetLiteral() throws Exception { public void testCharSetLiteral() throws Exception {
mkdir(tmpdir); mkdir(tmpdir);
StringBuilder grammarBuilder = new StringBuilder(93); StringBuilder grammarBuilder = new StringBuilder(98);
grammarBuilder.append("grammar T;\n"); 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("A : [AaBb] ;\n");
grammarBuilder.append("WS : (' '|'\\n')+ -> skip ;"); grammarBuilder.append("WS : (' '|'\\n')+ -> skip ;");
String grammar = grammarBuilder.toString(); String grammar = grammarBuilder.toString();
@ -61,9 +61,9 @@ public class TestSets extends BaseCppTest {
public void testLexerOptionalSet() throws Exception { public void testLexerOptionalSet() throws Exception {
mkdir(tmpdir); mkdir(tmpdir);
StringBuilder grammarBuilder = new StringBuilder(81); StringBuilder grammarBuilder = new StringBuilder(86);
grammarBuilder.append("grammar T;\n"); 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' ;"); grammarBuilder.append("A : ('a'|'b')? 'c' ;");
String grammar = grammarBuilder.toString(); String grammar = grammarBuilder.toString();
@ -81,9 +81,9 @@ public class TestSets extends BaseCppTest {
public void testLexerPlusSet() throws Exception { public void testLexerPlusSet() throws Exception {
mkdir(tmpdir); mkdir(tmpdir);
StringBuilder grammarBuilder = new StringBuilder(81); StringBuilder grammarBuilder = new StringBuilder(86);
grammarBuilder.append("grammar T;\n"); 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' ;"); grammarBuilder.append("A : ('a'|'b')+ 'c' ;");
String grammar = grammarBuilder.toString(); String grammar = grammarBuilder.toString();
@ -101,9 +101,9 @@ public class TestSets extends BaseCppTest {
public void testLexerStarSet() throws Exception { public void testLexerStarSet() throws Exception {
mkdir(tmpdir); mkdir(tmpdir);
StringBuilder grammarBuilder = new StringBuilder(81); StringBuilder grammarBuilder = new StringBuilder(86);
grammarBuilder.append("grammar T;\n"); 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' ;"); grammarBuilder.append("A : ('a'|'b')* 'c' ;");
String grammar = grammarBuilder.toString(); String grammar = grammarBuilder.toString();
@ -121,9 +121,9 @@ public class TestSets extends BaseCppTest {
public void testNotChar() throws Exception { public void testNotChar() throws Exception {
mkdir(tmpdir); mkdir(tmpdir);
StringBuilder grammarBuilder = new StringBuilder(61); StringBuilder grammarBuilder = new StringBuilder(66);
grammarBuilder.append("grammar T;\n"); 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' ;"); grammarBuilder.append("A : ~'b' ;");
String grammar = grammarBuilder.toString(); String grammar = grammarBuilder.toString();
@ -141,9 +141,9 @@ public class TestSets extends BaseCppTest {
public void testNotCharSet() throws Exception { public void testNotCharSet() throws Exception {
mkdir(tmpdir); mkdir(tmpdir);
StringBuilder grammarBuilder = new StringBuilder(67); StringBuilder grammarBuilder = new StringBuilder(72);
grammarBuilder.append("grammar T;\n"); 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') ;"); grammarBuilder.append("A : ~('b'|'c') ;");
String grammar = grammarBuilder.toString(); String grammar = grammarBuilder.toString();
@ -161,9 +161,9 @@ public class TestSets extends BaseCppTest {
public void testNotCharSetWithLabel() throws Exception { public void testNotCharSetWithLabel() throws Exception {
mkdir(tmpdir); mkdir(tmpdir);
StringBuilder grammarBuilder = new StringBuilder(69); StringBuilder grammarBuilder = new StringBuilder(74);
grammarBuilder.append("grammar T;\n"); 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') ;"); grammarBuilder.append("A : h=~('b'|'c') ;");
String grammar = grammarBuilder.toString(); String grammar = grammarBuilder.toString();
@ -181,9 +181,9 @@ public class TestSets extends BaseCppTest {
public void testNotCharSetWithRuleRef3() throws Exception { public void testNotCharSetWithRuleRef3() throws Exception {
mkdir(tmpdir); mkdir(tmpdir);
StringBuilder grammarBuilder = new StringBuilder(133); StringBuilder grammarBuilder = new StringBuilder(138);
grammarBuilder.append("grammar T;\n"); 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("A : ('a'|B) ; // this doesn't collapse to set but works\n");
grammarBuilder.append("fragment\n"); grammarBuilder.append("fragment\n");
grammarBuilder.append("B : ~('a'|'c') ;"); grammarBuilder.append("B : ~('a'|'c') ;");
@ -203,9 +203,9 @@ public class TestSets extends BaseCppTest {
public void testOptionalLexerSingleElement() throws Exception { public void testOptionalLexerSingleElement() throws Exception {
mkdir(tmpdir); mkdir(tmpdir);
StringBuilder grammarBuilder = new StringBuilder(75); StringBuilder grammarBuilder = new StringBuilder(80);
grammarBuilder.append("grammar T;\n"); 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' ;"); grammarBuilder.append("A : 'b'? 'c' ;");
String grammar = grammarBuilder.toString(); String grammar = grammarBuilder.toString();
@ -223,9 +223,9 @@ public class TestSets extends BaseCppTest {
public void testOptionalSet() throws Exception { public void testOptionalSet() throws Exception {
mkdir(tmpdir); mkdir(tmpdir);
StringBuilder grammarBuilder = new StringBuilder(73); StringBuilder grammarBuilder = new StringBuilder(78);
grammarBuilder.append("grammar T;\n"); 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(); String grammar = grammarBuilder.toString();
@ -242,9 +242,9 @@ public class TestSets extends BaseCppTest {
public void testOptionalSingleElement() throws Exception { public void testOptionalSingleElement() throws Exception {
mkdir(tmpdir); mkdir(tmpdir);
StringBuilder grammarBuilder = new StringBuilder(75); StringBuilder grammarBuilder = new StringBuilder(80);
grammarBuilder.append("grammar T;\n"); 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' ;"); grammarBuilder.append("A : 'b' ;");
String grammar = grammarBuilder.toString(); String grammar = grammarBuilder.toString();
@ -262,9 +262,9 @@ public class TestSets extends BaseCppTest {
public void testParserNotSet() throws Exception { public void testParserNotSet() throws Exception {
mkdir(tmpdir); mkdir(tmpdir);
StringBuilder grammarBuilder = new StringBuilder(65); StringBuilder grammarBuilder = new StringBuilder(70);
grammarBuilder.append("grammar T;\n"); 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(); String grammar = grammarBuilder.toString();
@ -281,9 +281,9 @@ public class TestSets extends BaseCppTest {
public void testParserNotToken() throws Exception { public void testParserNotToken() throws Exception {
mkdir(tmpdir); mkdir(tmpdir);
StringBuilder grammarBuilder = new StringBuilder(67); StringBuilder grammarBuilder = new StringBuilder(72);
grammarBuilder.append("grammar T;\n"); 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(); String grammar = grammarBuilder.toString();
@ -300,9 +300,9 @@ public class TestSets extends BaseCppTest {
public void testParserNotTokenWithLabel() throws Exception { public void testParserNotTokenWithLabel() throws Exception {
mkdir(tmpdir); mkdir(tmpdir);
StringBuilder grammarBuilder = new StringBuilder(59); StringBuilder grammarBuilder = new StringBuilder(64);
grammarBuilder.append("grammar T;\n"); 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(); String grammar = grammarBuilder.toString();
@ -319,9 +319,9 @@ public class TestSets extends BaseCppTest {
public void testParserSet() throws Exception { public void testParserSet() throws Exception {
mkdir(tmpdir); mkdir(tmpdir);
StringBuilder grammarBuilder = new StringBuilder(60); StringBuilder grammarBuilder = new StringBuilder(65);
grammarBuilder.append("grammar T;\n"); 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(); String grammar = grammarBuilder.toString();
@ -338,9 +338,9 @@ public class TestSets extends BaseCppTest {
public void testPlusLexerSingleElement() throws Exception { public void testPlusLexerSingleElement() throws Exception {
mkdir(tmpdir); mkdir(tmpdir);
StringBuilder grammarBuilder = new StringBuilder(75); StringBuilder grammarBuilder = new StringBuilder(80);
grammarBuilder.append("grammar T;\n"); 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' ;"); grammarBuilder.append("A : 'b'+ 'c' ;");
String grammar = grammarBuilder.toString(); String grammar = grammarBuilder.toString();
@ -358,9 +358,9 @@ public class TestSets extends BaseCppTest {
public void testPlusSet() throws Exception { public void testPlusSet() throws Exception {
mkdir(tmpdir); mkdir(tmpdir);
StringBuilder grammarBuilder = new StringBuilder(73); StringBuilder grammarBuilder = new StringBuilder(78);
grammarBuilder.append("grammar T;\n"); 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(); String grammar = grammarBuilder.toString();
@ -377,9 +377,9 @@ public class TestSets extends BaseCppTest {
public void testRuleAsSet() throws Exception { public void testRuleAsSet() throws Exception {
mkdir(tmpdir); mkdir(tmpdir);
StringBuilder grammarBuilder = new StringBuilder(80); StringBuilder grammarBuilder = new StringBuilder(85);
grammarBuilder.append("grammar T;\n"); 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(); String grammar = grammarBuilder.toString();
@ -396,9 +396,9 @@ public class TestSets extends BaseCppTest {
public void testSeqDoesNotBecomeSet() throws Exception { public void testSeqDoesNotBecomeSet() throws Exception {
mkdir(tmpdir); mkdir(tmpdir);
StringBuilder grammarBuilder = new StringBuilder(117); StringBuilder grammarBuilder = new StringBuilder(122);
grammarBuilder.append("grammar T;\n"); 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 A : '1' | '2';\n");
grammarBuilder.append("fragment B : '3' '4';\n"); grammarBuilder.append("fragment B : '3' '4';\n");
grammarBuilder.append("C : A | B;"); grammarBuilder.append("C : A | B;");
@ -418,9 +418,9 @@ public class TestSets extends BaseCppTest {
public void testStarLexerSingleElement_1() throws Exception { public void testStarLexerSingleElement_1() throws Exception {
mkdir(tmpdir); mkdir(tmpdir);
StringBuilder grammarBuilder = new StringBuilder(75); StringBuilder grammarBuilder = new StringBuilder(80);
grammarBuilder.append("grammar T;\n"); 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' ;"); grammarBuilder.append("A : 'b'* 'c' ;");
String grammar = grammarBuilder.toString(); String grammar = grammarBuilder.toString();
@ -438,9 +438,9 @@ public class TestSets extends BaseCppTest {
public void testStarLexerSingleElement_2() throws Exception { public void testStarLexerSingleElement_2() throws Exception {
mkdir(tmpdir); mkdir(tmpdir);
StringBuilder grammarBuilder = new StringBuilder(75); StringBuilder grammarBuilder = new StringBuilder(80);
grammarBuilder.append("grammar T;\n"); 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' ;"); grammarBuilder.append("A : 'b'* 'c' ;");
String grammar = grammarBuilder.toString(); String grammar = grammarBuilder.toString();
@ -458,9 +458,9 @@ public class TestSets extends BaseCppTest {
public void testStarSet() throws Exception { public void testStarSet() throws Exception {
mkdir(tmpdir); mkdir(tmpdir);
StringBuilder grammarBuilder = new StringBuilder(73); StringBuilder grammarBuilder = new StringBuilder(78);
grammarBuilder.append("grammar T;\n"); 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(); String grammar = grammarBuilder.toString();

View File

@ -552,11 +552,11 @@ public class TestSemPredEvalParser extends BaseTest {
@Test @Test
public void testToLeftWithVaryingPredicate() throws Exception { public void testToLeftWithVaryingPredicate() throws Exception {
mkdir(tmpdir); mkdir(tmpdir);
StringBuilder grammarBuilder = new StringBuilder(268); StringBuilder grammarBuilder = new StringBuilder(261);
grammarBuilder.append("grammar T;\n"); grammarBuilder.append("grammar T;\n");
grammarBuilder.append("@members {int i = 0;}\n"); grammarBuilder.append("@members {int i = 0;}\n");
grammarBuilder.append("s : ({this.i += 1;\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("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(" | {this.i % 2 != 0}? ID {Console.WriteLine(\"alt 2\");}\n");
grammarBuilder.append(" ;\n"); grammarBuilder.append(" ;\n");

View File

@ -646,11 +646,11 @@ public class TestSemPredEvalParser extends BaseTest {
public void testToLeftWithVaryingPredicate() throws Exception { public void testToLeftWithVaryingPredicate() throws Exception {
mkdir(tmpdir); mkdir(tmpdir);
StringBuilder grammarBuilder = new StringBuilder(271); StringBuilder grammarBuilder = new StringBuilder(264);
grammarBuilder.append("grammar T;\n"); grammarBuilder.append("grammar T;\n");
grammarBuilder.append("@members {int i = 0;}\n"); grammarBuilder.append("@members {int i = 0;}\n");
grammarBuilder.append("s : ({this.i += 1;\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("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(" | {this.i % 2 != 0}? ID {System.out.println(\"alt 2\");}\n");
grammarBuilder.append(" ;\n"); grammarBuilder.append(" ;\n");

View File

@ -600,11 +600,11 @@ public class TestSemPredEvalParser extends BaseTest {
@Test @Test
public void testToLeftWithVaryingPredicate() throws Exception { public void testToLeftWithVaryingPredicate() throws Exception {
mkdir(tmpdir); mkdir(tmpdir);
StringBuilder grammarBuilder = new StringBuilder(252); StringBuilder grammarBuilder = new StringBuilder(245);
grammarBuilder.append("grammar T;\n"); grammarBuilder.append("grammar T;\n");
grammarBuilder.append("@members {this.i = 0;}\n"); grammarBuilder.append("@members {this.i = 0;}\n");
grammarBuilder.append("s : ({this.i += 1;\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("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(" | {this.i % 2 != 0}? ID {console.log(\"alt 2\");}\n");
grammarBuilder.append(" ;\n"); grammarBuilder.append(" ;\n");

View File

@ -669,11 +669,11 @@ public class TestSemPredEvalParser extends BasePython2Test {
public void testToLeftWithVaryingPredicate() throws Exception { public void testToLeftWithVaryingPredicate() throws Exception {
mkdir(tmpdir); mkdir(tmpdir);
StringBuilder grammarBuilder = new StringBuilder(228); StringBuilder grammarBuilder = new StringBuilder(226);
grammarBuilder.append("grammar T;\n"); grammarBuilder.append("grammar T;\n");
grammarBuilder.append("@members {i = 0}\n"); grammarBuilder.append("@members {i = 0}\n");
grammarBuilder.append("s : ({self.i += 1\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("a : {self.i % 2 == 0}? ID {print(\"alt 1\")}\n");
grammarBuilder.append(" | {self.i % 2 != 0}? ID {print(\"alt 2\")}\n"); grammarBuilder.append(" | {self.i % 2 != 0}? ID {print(\"alt 2\")}\n");
grammarBuilder.append(" ;\n"); grammarBuilder.append(" ;\n");

View File

@ -669,11 +669,11 @@ public class TestSemPredEvalParser extends BasePython3Test {
public void testToLeftWithVaryingPredicate() throws Exception { public void testToLeftWithVaryingPredicate() throws Exception {
mkdir(tmpdir); mkdir(tmpdir);
StringBuilder grammarBuilder = new StringBuilder(228); StringBuilder grammarBuilder = new StringBuilder(226);
grammarBuilder.append("grammar T;\n"); grammarBuilder.append("grammar T;\n");
grammarBuilder.append("@members {i = 0}\n"); grammarBuilder.append("@members {i = 0}\n");
grammarBuilder.append("s : ({self.i += 1\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("a : {self.i % 2 == 0}? ID {print(\"alt 1\")}\n");
grammarBuilder.append(" | {self.i % 2 != 0}? ID {print(\"alt 2\")}\n"); grammarBuilder.append(" | {self.i % 2 != 0}? ID {print(\"alt 2\")}\n");
grammarBuilder.append(" ;\n"); grammarBuilder.append(" ;\n");

View File

@ -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. // ATN states in SLL implies LL will also get nowhere.
// If conflict in states that dip out, choose min since we // If conflict in states that dip out, choose min since we
// will get error no matter what. // 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) { if (alt != ATN::INVALID_ALT_NUMBER) {
// return w/o altering DFA
return alt; return alt;
} }

View File

@ -700,7 +700,7 @@ setState(<choice.stateNumber>);
_errHandler->sync(this); _errHandler->sync(this);
switch (getInterpreter\<atn::ParserATNSimulator>()->adaptivePredict(_input, <choice.decision>, _ctx)) { switch (getInterpreter\<atn::ParserATNSimulator>()->adaptivePredict(_input, <choice.decision>, _ctx)) {
<alts: {alt | case <i><if (!choice.ast.greedy)>+1<endif>: { <alts: {alt | case <i><if (!choice.ast.greedy)> + 1<endif>: {
<alt> <alt>
break; break;
\} \}
@ -714,7 +714,7 @@ setState(<choice.stateNumber>);
_errHandler->sync(this); _errHandler->sync(this);
alt = getInterpreter\<atn::ParserATNSimulator>()->adaptivePredict(_input, <choice.decision>, _ctx); alt = getInterpreter\<atn::ParserATNSimulator>()->adaptivePredict(_input, <choice.decision>, _ctx);
while (alt != <choice.exitAlt> && alt != -1) { while (alt != <choice.exitAlt> && alt != -1) {
if ( alt == 1 <if(!choice.ast.greedy)>+ 1<endif>) { if (alt == 1<if(!choice.ast.greedy)> + 1<endif>) {
<iteration> <iteration>
<alts> <! should only be one !> <alts> <! should only be one !>
} }
@ -728,7 +728,7 @@ PlusBlockHeader(choice, alts, error) ::= "<! Required to exist, but unused. !>"
PlusBlock(choice, alts, error) ::= << PlusBlock(choice, alts, error) ::= <<
setState(<choice.blockStartStateNumber>); <! alt block decision !> setState(<choice.blockStartStateNumber>); <! alt block decision !>
_errHandler->sync(this); _errHandler->sync(this);
alt = getInterpreter\<atn::ParserATNSimulator>()->adaptivePredict(_input, <choice.decision>, _ctx); alt = 1<if(!choice.ast.greedy)> + 1<endif>;
do { do {
switch (alt) { switch (alt) {
<alts: {alt | case <i><if (!choice.ast.greedy)> + 1<endif>: { <alts: {alt | case <i><if (!choice.ast.greedy)> + 1<endif>: {
@ -742,7 +742,7 @@ do {
setState(<choice.loopBackStateNumber>); <! loopback/exit decision !> setState(<choice.loopBackStateNumber>); <! loopback/exit decision !>
_errHandler->sync(this); _errHandler->sync(this);
alt = getInterpreter\<atn::ParserATNSimulator>()->adaptivePredict(_input, <choice.decision>, _ctx); alt = getInterpreter\<atn::ParserATNSimulator>()->adaptivePredict(_input, <choice.decision>, _ctx);
} while (alt != <choice.exitAlt> && alt != -1); } while (alt != <choice.exitAlt> && alt != atn::ATN::INVALID_ALT_NUMBER);
>> >>
Sync(s) ::= "Sync(s) sync(<s.expecting.name>);" Sync(s) ::= "Sync(s) sync(<s.expecting.name>);"