forked from jasder/antlr
Generate Go tests
This commit is contained in:
parent
c72ef6383e
commit
c9ac8a6c61
|
@ -58,18 +58,18 @@ public class TestCompositeParsers extends BaseTest {
|
|||
@Test
|
||||
public void testDelegatesSeeSameTokenType() throws Exception {
|
||||
mkdir(tmpdir);
|
||||
String slave_T =
|
||||
"parser grammar T;\n" +
|
||||
"tokens { C, B, A } // reverse order\n" +
|
||||
"y : A {Console.WriteLine(\"T.y\");};";
|
||||
writeFile(tmpdir, "T.g4", slave_T);
|
||||
|
||||
String slave_S =
|
||||
"parser grammar S;\n" +
|
||||
"tokens { A, B, C }\n" +
|
||||
"x : A {Console.WriteLine(\"S.x\");};";
|
||||
writeFile(tmpdir, "S.g4", slave_S);
|
||||
|
||||
String slave_T =
|
||||
"parser grammar T;\n" +
|
||||
"tokens { C, B, A } // reverse order\n" +
|
||||
"y : A {Console.WriteLine(\"T.y\");};";
|
||||
writeFile(tmpdir, "T.g4", slave_T);
|
||||
|
||||
StringBuilder grammarBuilder = new StringBuilder(598);
|
||||
grammarBuilder.append("// The lexer will create rules to match letters a, b, c.\n");
|
||||
grammarBuilder.append("// The associated token types A, B, C must have the same value\n");
|
||||
|
@ -191,17 +191,17 @@ public class TestCompositeParsers extends BaseTest {
|
|||
@Test
|
||||
public void testDelegatorInvokesFirstVersionOfDelegateRule() throws Exception {
|
||||
mkdir(tmpdir);
|
||||
String slave_T =
|
||||
"parser grammar T;\n" +
|
||||
"a : B {Console.WriteLine(\"T.a\");};";
|
||||
writeFile(tmpdir, "T.g4", slave_T);
|
||||
|
||||
String slave_S =
|
||||
"parser grammar S;\n" +
|
||||
"a : b {Console.WriteLine(\"S.a\");};\n" +
|
||||
"b : B;";
|
||||
writeFile(tmpdir, "S.g4", slave_S);
|
||||
|
||||
String slave_T =
|
||||
"parser grammar T;\n" +
|
||||
"a : B {Console.WriteLine(\"T.a\");};";
|
||||
writeFile(tmpdir, "T.g4", slave_T);
|
||||
|
||||
StringBuilder grammarBuilder = new StringBuilder(106);
|
||||
grammarBuilder.append("grammar M;\n");
|
||||
grammarBuilder.append("import S,T;\n");
|
||||
|
@ -241,18 +241,18 @@ public class TestCompositeParsers extends BaseTest {
|
|||
@Test
|
||||
public void testDelegatorRuleOverridesDelegates() throws Exception {
|
||||
mkdir(tmpdir);
|
||||
String slave_T =
|
||||
"parser grammar T;\n" +
|
||||
"tokens { A }\n" +
|
||||
"b : 'b' {Console.WriteLine(\"T.b\");};";
|
||||
writeFile(tmpdir, "T.g4", slave_T);
|
||||
|
||||
String slave_S =
|
||||
"parser grammar S;\n" +
|
||||
"a : b {Console.WriteLine(\"S.a\");};\n" +
|
||||
"b : 'b' ;";
|
||||
writeFile(tmpdir, "S.g4", slave_S);
|
||||
|
||||
String slave_T =
|
||||
"parser grammar T;\n" +
|
||||
"tokens { A }\n" +
|
||||
"b : 'b' {Console.WriteLine(\"T.b\");};";
|
||||
writeFile(tmpdir, "T.g4", slave_T);
|
||||
|
||||
StringBuilder grammarBuilder = new StringBuilder(94);
|
||||
grammarBuilder.append("grammar M;\n");
|
||||
grammarBuilder.append("import S, T;\n");
|
||||
|
|
|
@ -529,14 +529,14 @@ public class TestParserExec extends BaseTest {
|
|||
@Test
|
||||
public void testParserProperty() throws Exception {
|
||||
mkdir(tmpdir);
|
||||
StringBuilder grammarBuilder = new StringBuilder(163);
|
||||
StringBuilder grammarBuilder = new StringBuilder(155);
|
||||
grammarBuilder.append("grammar T;\n");
|
||||
grammarBuilder.append("@members {\n");
|
||||
grammarBuilder.append("bool Property() {\n");
|
||||
grammarBuilder.append(" return true;\n");
|
||||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append("a : {$parser.Property()}? ID {Console.WriteLine(\"valid\");}\n");
|
||||
grammarBuilder.append("a : {Property()}? ID {Console.WriteLine(\"valid\");}\n");
|
||||
grammarBuilder.append(" ;\n");
|
||||
grammarBuilder.append("ID : 'a'..'z'+ ;\n");
|
||||
grammarBuilder.append("WS : (' '|'\\n') -> skip ;");
|
||||
|
|
|
@ -27,8 +27,7 @@ public class TestCompositeParsers extends BaseTest {
|
|||
String grammar = grammarBuilder.toString();
|
||||
String input ="=a";
|
||||
String found = execParser("M.g4", grammar, "MParser", "MLexer",
|
||||
"MListener", "MVisitor",
|
||||
"s", input, false);
|
||||
"MListener", "MVisitor", "s", input, false);
|
||||
assertEquals("S.a\n", found);
|
||||
assertNull(this.stderrDuringParse);
|
||||
|
||||
|
@ -52,8 +51,7 @@ public class TestCompositeParsers extends BaseTest {
|
|||
String grammar = grammarBuilder.toString();
|
||||
String input ="x 34 9";
|
||||
String found = execParser("M.g4", grammar, "MParser", "MLexer",
|
||||
"MListener", "MVisitor",
|
||||
"s", input, false);
|
||||
"MListener", "MVisitor", "s", input, false);
|
||||
assertEquals("S.x\n", found);
|
||||
assertNull(this.stderrDuringParse);
|
||||
|
||||
|
@ -62,18 +60,18 @@ public class TestCompositeParsers extends BaseTest {
|
|||
@Test
|
||||
public void testDelegatesSeeSameTokenType() throws Exception {
|
||||
mkdir(parserpkgdir);
|
||||
String slave_T =
|
||||
"parser grammar T;\n" +
|
||||
"tokens { C, B, A } // reverse order\n" +
|
||||
"y : A {fmt.Println(\"T.y\")};";
|
||||
writeFile(parserpkgdir, "T.g4", slave_T);
|
||||
|
||||
String slave_S =
|
||||
"parser grammar S;\n" +
|
||||
"tokens { A, B, C }\n" +
|
||||
"x : A {fmt.Println(\"S.x\")};";
|
||||
writeFile(parserpkgdir, "S.g4", slave_S);
|
||||
|
||||
String slave_T =
|
||||
"parser grammar T;\n" +
|
||||
"tokens { C, B, A } // reverse order\n" +
|
||||
"y : A {fmt.Println(\"T.y\")};";
|
||||
writeFile(parserpkgdir, "T.g4", slave_T);
|
||||
|
||||
StringBuilder grammarBuilder = new StringBuilder(598);
|
||||
grammarBuilder.append("// The lexer will create rules to match letters a, b, c.\n");
|
||||
grammarBuilder.append("// The associated token types A, B, C must have the same value\n");
|
||||
|
@ -95,8 +93,7 @@ public class TestCompositeParsers extends BaseTest {
|
|||
String grammar = grammarBuilder.toString();
|
||||
String input ="aa";
|
||||
String found = execParser("M.g4", grammar, "MParser", "MLexer",
|
||||
"MListener", "MVisitor",
|
||||
"s", input, false);
|
||||
"MListener", "MVisitor", "s", input, false);
|
||||
assertEquals(
|
||||
"S.x\n" +
|
||||
"T.y\n", found);
|
||||
|
@ -125,8 +122,7 @@ public class TestCompositeParsers extends BaseTest {
|
|||
String grammar = grammarBuilder.toString();
|
||||
String input ="b";
|
||||
String found = execParser("M.g4", grammar, "MParser", "MLexer",
|
||||
"MListener", "MVisitor",
|
||||
"s", input, false);
|
||||
"MListener", "MVisitor", "s", input, false);
|
||||
assertEquals("foo\n", found);
|
||||
assertNull(this.stderrDuringParse);
|
||||
|
||||
|
@ -149,8 +145,7 @@ public class TestCompositeParsers extends BaseTest {
|
|||
String grammar = grammarBuilder.toString();
|
||||
String input ="b";
|
||||
String found = execParser("M.g4", grammar, "MParser", "MLexer",
|
||||
"MListener", "MVisitor",
|
||||
"s", input, false);
|
||||
"MListener", "MVisitor", "s", input, false);
|
||||
assertEquals("S.a\n", found);
|
||||
assertNull(this.stderrDuringParse);
|
||||
|
||||
|
@ -173,8 +168,7 @@ public class TestCompositeParsers extends BaseTest {
|
|||
String grammar = grammarBuilder.toString();
|
||||
String input ="b";
|
||||
String found = execParser("M.g4", grammar, "MParser", "MLexer",
|
||||
"MListener", "MVisitor",
|
||||
"s", input, false);
|
||||
"MListener", "MVisitor", "s", input, false);
|
||||
assertEquals("S.a1000\n", found);
|
||||
assertNull(this.stderrDuringParse);
|
||||
|
||||
|
@ -197,8 +191,7 @@ public class TestCompositeParsers extends BaseTest {
|
|||
String grammar = grammarBuilder.toString();
|
||||
String input ="b";
|
||||
String found = execParser("M.g4", grammar, "MParser", "MLexer",
|
||||
"MListener", "MVisitor",
|
||||
"s", input, false);
|
||||
"MListener", "MVisitor", "s", input, false);
|
||||
assertEquals("S.ab\n", found);
|
||||
assertNull(this.stderrDuringParse);
|
||||
|
||||
|
@ -207,17 +200,17 @@ public class TestCompositeParsers extends BaseTest {
|
|||
@Test
|
||||
public void testDelegatorInvokesFirstVersionOfDelegateRule() throws Exception {
|
||||
mkdir(parserpkgdir);
|
||||
String slave_T =
|
||||
"parser grammar T;\n" +
|
||||
"a : B {fmt.Println(\"T.a\")};";
|
||||
writeFile(parserpkgdir, "T.g4", slave_T);
|
||||
|
||||
String slave_S =
|
||||
"parser grammar S;\n" +
|
||||
"a : b {fmt.Println(\"S.a\")};\n" +
|
||||
"b : B;";
|
||||
writeFile(parserpkgdir, "S.g4", slave_S);
|
||||
|
||||
String slave_T =
|
||||
"parser grammar T;\n" +
|
||||
"a : B {fmt.Println(\"T.a\")};";
|
||||
writeFile(parserpkgdir, "T.g4", slave_T);
|
||||
|
||||
StringBuilder grammarBuilder = new StringBuilder(106);
|
||||
grammarBuilder.append("grammar M;\n");
|
||||
grammarBuilder.append("import S,T;\n");
|
||||
|
@ -227,8 +220,7 @@ public class TestCompositeParsers extends BaseTest {
|
|||
String grammar = grammarBuilder.toString();
|
||||
String input ="b";
|
||||
String found = execParser("M.g4", grammar, "MParser", "MLexer",
|
||||
"MListener", "MVisitor",
|
||||
"s", input, false);
|
||||
"MListener", "MVisitor", "s", input, false);
|
||||
assertEquals("S.a\n", found);
|
||||
assertNull(this.stderrDuringParse);
|
||||
|
||||
|
@ -251,8 +243,7 @@ public class TestCompositeParsers extends BaseTest {
|
|||
String grammar = grammarBuilder.toString();
|
||||
String input ="c";
|
||||
String found = execParser("M.g4", grammar, "MParser", "MLexer",
|
||||
"MListener", "MVisitor",
|
||||
"a", input, false);
|
||||
"MListener", "MVisitor", "a", input, false);
|
||||
assertEquals("S.a\n", found);
|
||||
assertNull(this.stderrDuringParse);
|
||||
|
||||
|
@ -261,18 +252,18 @@ public class TestCompositeParsers extends BaseTest {
|
|||
@Test
|
||||
public void testDelegatorRuleOverridesDelegates() throws Exception {
|
||||
mkdir(parserpkgdir);
|
||||
String slave_T =
|
||||
"parser grammar T;\n" +
|
||||
"tokens { A }\n" +
|
||||
"b : 'b' {fmt.Println(\"T.b\")};";
|
||||
writeFile(parserpkgdir, "T.g4", slave_T);
|
||||
|
||||
String slave_S =
|
||||
"parser grammar S;\n" +
|
||||
"a : b {fmt.Println(\"S.a\")};\n" +
|
||||
"b : 'b' ;";
|
||||
writeFile(parserpkgdir, "S.g4", slave_S);
|
||||
|
||||
String slave_T =
|
||||
"parser grammar T;\n" +
|
||||
"tokens { A }\n" +
|
||||
"b : 'b' {fmt.Println(\"T.b\")};";
|
||||
writeFile(parserpkgdir, "T.g4", slave_T);
|
||||
|
||||
StringBuilder grammarBuilder = new StringBuilder(87);
|
||||
grammarBuilder.append("grammar M;\n");
|
||||
grammarBuilder.append("import S, T;\n");
|
||||
|
@ -281,8 +272,7 @@ public class TestCompositeParsers extends BaseTest {
|
|||
String grammar = grammarBuilder.toString();
|
||||
String input ="c";
|
||||
String found = execParser("M.g4", grammar, "MParser", "MLexer",
|
||||
"MListener", "MVisitor",
|
||||
"a", input, false);
|
||||
"MListener", "MVisitor", "a", input, false);
|
||||
assertEquals(
|
||||
"M.b\n" +
|
||||
"S.a\n", found);
|
||||
|
@ -312,8 +302,7 @@ public class TestCompositeParsers extends BaseTest {
|
|||
String grammar = grammarBuilder.toString();
|
||||
String input ="float x = 3;";
|
||||
String found = execParser("M.g4", grammar, "MParser", "MLexer",
|
||||
"MListener", "MVisitor",
|
||||
"prog", input, false);
|
||||
"MListener", "MVisitor", "prog", input, false);
|
||||
assertEquals("JavaDecl: floatx=3;\n", found);
|
||||
assertNull(this.stderrDuringParse);
|
||||
|
||||
|
@ -342,8 +331,7 @@ public class TestCompositeParsers extends BaseTest {
|
|||
String grammar = grammarBuilder.toString();
|
||||
String input ="test test";
|
||||
String found = execParser("Test.g4", grammar, "TestParser", "TestLexer",
|
||||
"TestListener", "TestVisitor",
|
||||
"program", input, false);
|
||||
"TestListener", "TestVisitor", "program", input, false);
|
||||
assertEquals("", found);
|
||||
assertNull(this.stderrDuringParse);
|
||||
|
||||
|
@ -367,8 +355,7 @@ public class TestCompositeParsers extends BaseTest {
|
|||
String grammar = grammarBuilder.toString();
|
||||
String input ="b";
|
||||
String found = execParser("M.g4", grammar, "MParser", "MLexer",
|
||||
"MListener", "MVisitor",
|
||||
"s", input, false);
|
||||
"MListener", "MVisitor", "s", input, false);
|
||||
assertEquals("", found);
|
||||
assertNull(this.stderrDuringParse);
|
||||
|
||||
|
@ -391,8 +378,7 @@ public class TestCompositeParsers extends BaseTest {
|
|||
String grammar = grammarBuilder.toString();
|
||||
String input ="b";
|
||||
String found = execParser("M.g4", grammar, "MParser", "MLexer",
|
||||
"MListener", "MVisitor",
|
||||
"s", input, false);
|
||||
"MListener", "MVisitor", "s", input, false);
|
||||
assertEquals("", found);
|
||||
assertNull(this.stderrDuringParse);
|
||||
|
||||
|
@ -415,8 +401,7 @@ public class TestCompositeParsers extends BaseTest {
|
|||
String grammar = grammarBuilder.toString();
|
||||
String input ="abc";
|
||||
String found = execParser("M.g4", grammar, "MParser", "MLexer",
|
||||
"MListener", "MVisitor",
|
||||
"a", input, false);
|
||||
"MListener", "MVisitor", "a", input, false);
|
||||
assertEquals(
|
||||
"M.A\n" +
|
||||
"M.a: [@0,0:2='abc',<1>,1:0]\n", found);
|
||||
|
|
|
@ -21,8 +21,7 @@ public class TestFullContextParsing extends BaseTest {
|
|||
String grammar = grammarBuilder.toString();
|
||||
String input ="abc";
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer",
|
||||
"TListener", "TVisitor",
|
||||
"s", input, true);
|
||||
"TListener", "TVisitor", "s", input, true);
|
||||
assertEquals(
|
||||
"Decision 0:\n" +
|
||||
"s0-ID->:s1^=>1\n", found);
|
||||
|
@ -34,7 +33,7 @@ public class TestFullContextParsing extends BaseTest {
|
|||
@Test
|
||||
public void testAmbiguityNoLoop() throws Exception {
|
||||
mkdir(parserpkgdir);
|
||||
StringBuilder grammarBuilder = new StringBuilder(218);
|
||||
StringBuilder grammarBuilder = new StringBuilder(217);
|
||||
grammarBuilder.append("grammar T;\n");
|
||||
grammarBuilder.append("prog\n");
|
||||
grammarBuilder.append("@init {p.Interpreter.SetPredictionMode(antlr.PredictionModeLLExactAmbigDetection);}\n");
|
||||
|
@ -50,8 +49,7 @@ public class TestFullContextParsing extends BaseTest {
|
|||
String grammar = grammarBuilder.toString();
|
||||
String input ="a@";
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer",
|
||||
"TListener", "TVisitor",
|
||||
"prog", input, true);
|
||||
"TListener", "TVisitor", "prog", input, true);
|
||||
assertEquals("alt 1\n", found);
|
||||
|
||||
assertEquals(
|
||||
|
@ -78,8 +76,7 @@ public class TestFullContextParsing extends BaseTest {
|
|||
String grammar = grammarBuilder.toString();
|
||||
String input ="$ 34 abc @ 34 abc";
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer",
|
||||
"TListener", "TVisitor",
|
||||
"s", input, true);
|
||||
"TListener", "TVisitor", "s", input, true);
|
||||
assertEquals(
|
||||
"Decision 2:\n" +
|
||||
"s0-INT->s1\n" +
|
||||
|
@ -109,8 +106,7 @@ public class TestFullContextParsing extends BaseTest {
|
|||
String grammar = grammarBuilder.toString();
|
||||
String input ="$ 34 abc";
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer",
|
||||
"TListener", "TVisitor",
|
||||
"s", input, true);
|
||||
"TListener", "TVisitor", "s", input, true);
|
||||
assertEquals(
|
||||
"Decision 1:\n" +
|
||||
"s0-INT->s1\n" +
|
||||
|
@ -138,8 +134,7 @@ public class TestFullContextParsing extends BaseTest {
|
|||
String grammar = grammarBuilder.toString();
|
||||
String input ="@ 34 abc";
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer",
|
||||
"TListener", "TVisitor",
|
||||
"s", input, true);
|
||||
"TListener", "TVisitor", "s", input, true);
|
||||
assertEquals(
|
||||
"Decision 1:\n" +
|
||||
"s0-INT->s1\n" +
|
||||
|
@ -158,7 +153,7 @@ public class TestFullContextParsing extends BaseTest {
|
|||
grammarBuilder.append("grammar T;\n");
|
||||
grammarBuilder.append("s\n");
|
||||
grammarBuilder.append("@init {p.Interpreter.SetPredictionMode(antlr.PredictionModeLLExactAmbigDetection);}\n");
|
||||
grammarBuilder.append(": expr[0] {fmt.Println($expr.ctx.ToStringTree(nil,p))};\n");
|
||||
grammarBuilder.append(": expr[0] {fmt.Println($expr.ctx.ToStringTree(nil, p))};\n");
|
||||
grammarBuilder.append(" expr[int _p]\n");
|
||||
grammarBuilder.append(" : ID \n");
|
||||
grammarBuilder.append(" ( \n");
|
||||
|
@ -171,8 +166,7 @@ public class TestFullContextParsing extends BaseTest {
|
|||
String grammar = grammarBuilder.toString();
|
||||
String input ="a+b";
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer",
|
||||
"TListener", "TVisitor",
|
||||
"s", input, true);
|
||||
"TListener", "TVisitor", "s", input, true);
|
||||
assertEquals("(expr a + (expr b))\n", found);
|
||||
|
||||
assertEquals(
|
||||
|
@ -188,7 +182,7 @@ public class TestFullContextParsing extends BaseTest {
|
|||
grammarBuilder.append("grammar T;\n");
|
||||
grammarBuilder.append("s\n");
|
||||
grammarBuilder.append("@init {p.Interpreter.SetPredictionMode(antlr.PredictionModeLLExactAmbigDetection);}\n");
|
||||
grammarBuilder.append(": expr[0] {fmt.Println($expr.ctx.ToStringTree(nil,p))};\n");
|
||||
grammarBuilder.append(": expr[0] {fmt.Println($expr.ctx.ToStringTree(nil, p))};\n");
|
||||
grammarBuilder.append(" expr[int _p]\n");
|
||||
grammarBuilder.append(" : ID \n");
|
||||
grammarBuilder.append(" ( \n");
|
||||
|
@ -201,8 +195,7 @@ public class TestFullContextParsing extends BaseTest {
|
|||
String grammar = grammarBuilder.toString();
|
||||
String input ="a+b*c";
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer",
|
||||
"TListener", "TVisitor",
|
||||
"s", input, true);
|
||||
"TListener", "TVisitor", "s", input, true);
|
||||
assertEquals("(expr a + (expr b * (expr c)))\n", found);
|
||||
|
||||
assertEquals(
|
||||
|
@ -216,7 +209,7 @@ public class TestFullContextParsing extends BaseTest {
|
|||
@Test
|
||||
public void testFullContextIF_THEN_ELSEParse_1() throws Exception {
|
||||
mkdir(parserpkgdir);
|
||||
StringBuilder grammarBuilder = new StringBuilder(243);
|
||||
StringBuilder grammarBuilder = new StringBuilder(242);
|
||||
grammarBuilder.append("grammar T;\n");
|
||||
grammarBuilder.append("s \n");
|
||||
grammarBuilder.append("@init {p.Interpreter.SetPredictionMode(antlr.PredictionModeLLExactAmbigDetection);}\n");
|
||||
|
@ -230,8 +223,7 @@ public class TestFullContextParsing extends BaseTest {
|
|||
String grammar = grammarBuilder.toString();
|
||||
String input ="{ if x then return }";
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer",
|
||||
"TListener", "TVisitor",
|
||||
"s", input, true);
|
||||
"TListener", "TVisitor", "s", input, true);
|
||||
assertEquals(
|
||||
"Decision 1:\n" +
|
||||
"s0-'}'->:s1=>2\n", found);
|
||||
|
@ -242,7 +234,7 @@ public class TestFullContextParsing extends BaseTest {
|
|||
@Test
|
||||
public void testFullContextIF_THEN_ELSEParse_2() throws Exception {
|
||||
mkdir(parserpkgdir);
|
||||
StringBuilder grammarBuilder = new StringBuilder(243);
|
||||
StringBuilder grammarBuilder = new StringBuilder(242);
|
||||
grammarBuilder.append("grammar T;\n");
|
||||
grammarBuilder.append("s \n");
|
||||
grammarBuilder.append("@init {p.Interpreter.SetPredictionMode(antlr.PredictionModeLLExactAmbigDetection);}\n");
|
||||
|
@ -256,8 +248,7 @@ public class TestFullContextParsing extends BaseTest {
|
|||
String grammar = grammarBuilder.toString();
|
||||
String input ="{ if x then return else foo }";
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer",
|
||||
"TListener", "TVisitor",
|
||||
"s", input, true);
|
||||
"TListener", "TVisitor", "s", input, true);
|
||||
assertEquals(
|
||||
"Decision 1:\n" +
|
||||
"s0-'else'->:s1^=>1\n", found);
|
||||
|
@ -271,7 +262,7 @@ public class TestFullContextParsing extends BaseTest {
|
|||
@Test
|
||||
public void testFullContextIF_THEN_ELSEParse_3() throws Exception {
|
||||
mkdir(parserpkgdir);
|
||||
StringBuilder grammarBuilder = new StringBuilder(243);
|
||||
StringBuilder grammarBuilder = new StringBuilder(242);
|
||||
grammarBuilder.append("grammar T;\n");
|
||||
grammarBuilder.append("s \n");
|
||||
grammarBuilder.append("@init {p.Interpreter.SetPredictionMode(antlr.PredictionModeLLExactAmbigDetection);}\n");
|
||||
|
@ -285,8 +276,7 @@ public class TestFullContextParsing extends BaseTest {
|
|||
String grammar = grammarBuilder.toString();
|
||||
String input ="{ if x then if y then return else foo }";
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer",
|
||||
"TListener", "TVisitor",
|
||||
"s", input, true);
|
||||
"TListener", "TVisitor", "s", input, true);
|
||||
assertEquals(
|
||||
"Decision 1:\n" +
|
||||
"s0-'}'->:s2=>2\n" +
|
||||
|
@ -301,7 +291,7 @@ public class TestFullContextParsing extends BaseTest {
|
|||
@Test
|
||||
public void testFullContextIF_THEN_ELSEParse_4() throws Exception {
|
||||
mkdir(parserpkgdir);
|
||||
StringBuilder grammarBuilder = new StringBuilder(243);
|
||||
StringBuilder grammarBuilder = new StringBuilder(242);
|
||||
grammarBuilder.append("grammar T;\n");
|
||||
grammarBuilder.append("s \n");
|
||||
grammarBuilder.append("@init {p.Interpreter.SetPredictionMode(antlr.PredictionModeLLExactAmbigDetection);}\n");
|
||||
|
@ -315,8 +305,7 @@ public class TestFullContextParsing extends BaseTest {
|
|||
String grammar = grammarBuilder.toString();
|
||||
String input ="{ if x then if y then return else foo else bar }";
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer",
|
||||
"TListener", "TVisitor",
|
||||
"s", input, true);
|
||||
"TListener", "TVisitor", "s", input, true);
|
||||
assertEquals(
|
||||
"Decision 1:\n" +
|
||||
"s0-'else'->:s1^=>1\n", found);
|
||||
|
@ -332,7 +321,7 @@ public class TestFullContextParsing extends BaseTest {
|
|||
@Test
|
||||
public void testFullContextIF_THEN_ELSEParse_5() throws Exception {
|
||||
mkdir(parserpkgdir);
|
||||
StringBuilder grammarBuilder = new StringBuilder(243);
|
||||
StringBuilder grammarBuilder = new StringBuilder(242);
|
||||
grammarBuilder.append("grammar T;\n");
|
||||
grammarBuilder.append("s \n");
|
||||
grammarBuilder.append("@init {p.Interpreter.SetPredictionMode(antlr.PredictionModeLLExactAmbigDetection);}\n");
|
||||
|
@ -348,8 +337,7 @@ public class TestFullContextParsing extends BaseTest {
|
|||
"{ if x then return else foo\n" +
|
||||
"if x then if y then return else foo }";
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer",
|
||||
"TListener", "TVisitor",
|
||||
"s", input, true);
|
||||
"TListener", "TVisitor", "s", input, true);
|
||||
assertEquals(
|
||||
"Decision 1:\n" +
|
||||
"s0-'}'->:s2=>2\n" +
|
||||
|
@ -366,7 +354,7 @@ public class TestFullContextParsing extends BaseTest {
|
|||
@Test
|
||||
public void testFullContextIF_THEN_ELSEParse_6() throws Exception {
|
||||
mkdir(parserpkgdir);
|
||||
StringBuilder grammarBuilder = new StringBuilder(243);
|
||||
StringBuilder grammarBuilder = new StringBuilder(242);
|
||||
grammarBuilder.append("grammar T;\n");
|
||||
grammarBuilder.append("s \n");
|
||||
grammarBuilder.append("@init {p.Interpreter.SetPredictionMode(antlr.PredictionModeLLExactAmbigDetection);}\n");
|
||||
|
@ -382,8 +370,7 @@ public class TestFullContextParsing extends BaseTest {
|
|||
"{ if x then return else foo\n" +
|
||||
"if x then if y then return else foo }";
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer",
|
||||
"TListener", "TVisitor",
|
||||
"s", input, true);
|
||||
"TListener", "TVisitor", "s", input, true);
|
||||
assertEquals(
|
||||
"Decision 1:\n" +
|
||||
"s0-'}'->:s2=>2\n" +
|
||||
|
@ -400,7 +387,7 @@ public class TestFullContextParsing extends BaseTest {
|
|||
@Test
|
||||
public void testLoopsSimulateTailRecursion() throws Exception {
|
||||
mkdir(parserpkgdir);
|
||||
StringBuilder grammarBuilder = new StringBuilder(317);
|
||||
StringBuilder grammarBuilder = new StringBuilder(316);
|
||||
grammarBuilder.append("grammar T;\n");
|
||||
grammarBuilder.append("prog\n");
|
||||
grammarBuilder.append("@init {p.Interpreter.SetPredictionMode(antlr.PredictionModeLLExactAmbigDetection);}\n");
|
||||
|
@ -419,8 +406,7 @@ public class TestFullContextParsing extends BaseTest {
|
|||
String grammar = grammarBuilder.toString();
|
||||
String input ="a(i)<-x";
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer",
|
||||
"TListener", "TVisitor",
|
||||
"prog", input, true);
|
||||
"TListener", "TVisitor", "prog", input, true);
|
||||
assertEquals("pass: a(i)<-x\n", found);
|
||||
|
||||
assertEquals(
|
||||
|
@ -445,8 +431,7 @@ public class TestFullContextParsing extends BaseTest {
|
|||
String grammar = grammarBuilder.toString();
|
||||
String input ="34 abc";
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer",
|
||||
"TListener", "TVisitor",
|
||||
"s", input, true);
|
||||
"TListener", "TVisitor", "s", input, true);
|
||||
assertEquals(
|
||||
"Decision 0:\n" +
|
||||
"s0-INT->s1\n" +
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -4625,7 +4625,7 @@ public class TestLexerExec extends BaseTest {
|
|||
public void testPositionAdjustingLexer() throws Exception {
|
||||
mkdir(parserpkgdir);
|
||||
|
||||
StringBuilder grammarBuilder = new StringBuilder(3037);
|
||||
StringBuilder grammarBuilder = new StringBuilder(2906);
|
||||
grammarBuilder.append("lexer grammar PositionAdjustingLexer;\n");
|
||||
grammarBuilder.append("\n");
|
||||
grammarBuilder.append("@members {\n");
|
||||
|
@ -4636,62 +4636,64 @@ public class TestLexerExec extends BaseTest {
|
|||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append("\n");
|
||||
grammarBuilder.append("func NewPositionAdjustingLexer(input antlr.CharStream) *PositionAdjustingLexer {\n");
|
||||
grammarBuilder.append(" l := new(PositionAdjustingLexer)\n");
|
||||
grammarBuilder.append(" l.BaseLexer = antlr.NewBaseLexer( input )\n");
|
||||
grammarBuilder.append(" return l\n");
|
||||
grammarBuilder.append(" return &PositionAdjustingLexer{BaseLexer: antlr.NewBaseLexer(input)}\n");
|
||||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append("\n");
|
||||
grammarBuilder.append("func (this *PositionAdjustingLexer) NextToken() *Token {\n");
|
||||
grammarBuilder.append("\n");
|
||||
grammarBuilder.append(" _,ok := this._interp.(*PositionAdjustingLexerATNSimulator)\n");
|
||||
grammarBuilder.append("func (p *PositionAdjustingLexer) NextToken() *Token {\n");
|
||||
grammarBuilder.append(" var _, ok = p._interp.(*PositionAdjustingLexerATNSimulator)\n");
|
||||
grammarBuilder.append("\n");
|
||||
grammarBuilder.append(" if !ok {\n");
|
||||
grammarBuilder.append(" this._interp = NewPositionAdjustingLexerATNSimulator(this, _ATN, _decisionToDFA, _sharedContextCache)\n");
|
||||
grammarBuilder.append(" p._interp = NewPositionAdjustingLexerATNSimulator(p, _ATN, _decisionToDFA, _sharedContextCache)\n");
|
||||
grammarBuilder.append(" }\n");
|
||||
grammarBuilder.append("\n");
|
||||
grammarBuilder.append(" return this.BaseLexer.NextToken()\n");
|
||||
grammarBuilder.append(" return p.BaseLexer.NextToken()\n");
|
||||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append("\n");
|
||||
grammarBuilder.append("func (this *PositionAdjustingLexer) Emit() *Token {\n");
|
||||
grammarBuilder.append(" switch (_type) {\n");
|
||||
grammarBuilder.append("func (p *PositionAdjustingLexer) Emit() *Token {\n");
|
||||
grammarBuilder.append(" switch _type {\n");
|
||||
grammarBuilder.append(" case TOKENS:\n");
|
||||
grammarBuilder.append(" this.HandleAcceptPositionForKeyword(\"tokens\")\n");
|
||||
grammarBuilder.append(" p.HandleAcceptPositionForKeyword(\"tokens\")\n");
|
||||
grammarBuilder.append("\n");
|
||||
grammarBuilder.append(" case LABEL:\n");
|
||||
grammarBuilder.append(" this.HandleAcceptPositionForIdentifier()\n");
|
||||
grammarBuilder.append(" p.HandleAcceptPositionForIdentifier()\n");
|
||||
grammarBuilder.append(" }\n");
|
||||
grammarBuilder.append("\n");
|
||||
grammarBuilder.append(" return this.BaseLexer.Emit()\n");
|
||||
grammarBuilder.append(" return p.BaseLexer.Emit()\n");
|
||||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append("\n");
|
||||
grammarBuilder.append("func (this *PositionAdjustingLexer) HandleAcceptPositionForIdentifier() bool {\n");
|
||||
grammarBuilder.append(" tokenText := GetText()\n");
|
||||
grammarBuilder.append(" identifierLength int = 0\n");
|
||||
grammarBuilder.append("func (p *PositionAdjustingLexer) HandleAcceptPositionForIdentifier() bool {\n");
|
||||
grammarBuilder.append(" var tokenText = GetText()\n");
|
||||
grammarBuilder.append(" var identifierLength int\n");
|
||||
grammarBuilder.append("\n");
|
||||
grammarBuilder.append(" for identifierLength < len(tokenText) && isIdentifierChar(tokenText.charAt(identifierLength)) {\n");
|
||||
grammarBuilder.append(" identifierLength += 1\n");
|
||||
grammarBuilder.append(" identifierLength++\n");
|
||||
grammarBuilder.append(" }\n");
|
||||
grammarBuilder.append("\n");
|
||||
grammarBuilder.append(" if GetInputStream().Index() > _tokenStartCharIndex + identifierLength {\n");
|
||||
grammarBuilder.append(" offset int = identifierLength - 1\n");
|
||||
grammarBuilder.append(" this.GetInterpreter().ResetAcceptPosition(this.GetInputStream(), this.TokenStartCharIndex + offset, this.TokenStartLine, this.TokenStartCharPositionInLine + offset)\n");
|
||||
grammarBuilder.append(" return true\n");
|
||||
grammarBuilder.append(" if GetInputStream().Index() <= _tokenStartCharIndex + identifierLength {\n");
|
||||
grammarBuilder.append(" return false\n");
|
||||
grammarBuilder.append(" }\n");
|
||||
grammarBuilder.append("\n");
|
||||
grammarBuilder.append(" return false\n");
|
||||
grammarBuilder.append(" var offset = identifierLength - 1\n");
|
||||
grammarBuilder.append("\n");
|
||||
grammarBuilder.append(" p.GetInterpreter().ResetAcceptPosition(p.GetInputStream(), p.TokenStartCharIndex + offset, p.TokenStartLine, p.TokenStartCharPositionInLine + offset)\n");
|
||||
grammarBuilder.append("\n");
|
||||
grammarBuilder.append(" return true\n");
|
||||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append("\n");
|
||||
grammarBuilder.append("func (this *PositionAdjustingLexer) HandleAcceptPositionForKeyword(keyword string) bool {\n");
|
||||
grammarBuilder.append(" if this.GetInputStream().Index() > this.TokenStartCharIndex + len(keyword) {\n");
|
||||
grammarBuilder.append(" offset := len(keyword) - 1\n");
|
||||
grammarBuilder.append(" this.GetInterpreter().ResetAcceptPosition(this.GetInputStream(), this.TokenStartCharIndex + offset, this.TokenStartLine, this.TokenStartCharPositionInLine + offset)\n");
|
||||
grammarBuilder.append(" return true\n");
|
||||
grammarBuilder.append("func (p *PositionAdjustingLexer) HandleAcceptPositionForKeyword(keyword string) bool {\n");
|
||||
grammarBuilder.append(" if p.GetInputStream().Index() <= p.TokenStartCharIndex + len(keyword) {\n");
|
||||
grammarBuilder.append(" return false\n");
|
||||
grammarBuilder.append(" }\n");
|
||||
grammarBuilder.append("\n");
|
||||
grammarBuilder.append(" return false\n");
|
||||
grammarBuilder.append(" var offset = len(keyword) - 1\n");
|
||||
grammarBuilder.append("\n");
|
||||
grammarBuilder.append(" p.GetInterpreter().ResetAcceptPosition(p.GetInputStream(), p.TokenStartCharIndex + offset, p.TokenStartLine, p.TokenStartCharPositionInLine + offset)\n");
|
||||
grammarBuilder.append("\n");
|
||||
grammarBuilder.append(" return true\n");
|
||||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append("\n");
|
||||
grammarBuilder.append("func (s *PositionAdjustingLexer) GetInterpreter() *LexerATNSimulator {\n");
|
||||
grammarBuilder.append(" return s // return super.(*PositionAdjustingLexerATNSimulator).GetInterpreter()\n");
|
||||
grammarBuilder.append(" return s // TODO: return super.(*PositionAdjustingLexerATNSimulator).GetInterpreter()\n");
|
||||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append("\n");
|
||||
grammarBuilder.append("func isIdentifierChar(c rune) bool {\n");
|
||||
|
@ -4699,23 +4701,20 @@ public class TestLexerExec extends BaseTest {
|
|||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append("\n");
|
||||
grammarBuilder.append("type PositionAdjustingLexerATNSimulator struct {\n");
|
||||
grammarBuilder.append(" *antlr.LexerATNSimulator\n");
|
||||
grammarBuilder.append(" *antlr.LexerATNSimulator\n");
|
||||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append("\n");
|
||||
grammarBuilder.append("func NewPositionAdjustingLexerATNSimulator(recog antlr.Lexer, atn *antlr.ATN, decisionToDFA []*antlr.DFA, sharedContextCache *PredictionContextCache) *PositionAdjustingLexerATNSimulator {\n");
|
||||
grammarBuilder.append("\n");
|
||||
grammarBuilder.append(" l := new(PositionAdjustingLexerATNSimulator)\n");
|
||||
grammarBuilder.append("\n");
|
||||
grammarBuilder.append(" l.LexerATNSimulator = antlr.NewLexerATNSimulator(recog, atn, decisionToDFA, sharedContextCache)\n");
|
||||
grammarBuilder.append("\n");
|
||||
grammarBuilder.append(" return l\n");
|
||||
grammarBuilder.append(" return &PositionAdjustingLexerATNSimulator{\n");
|
||||
grammarBuilder.append(" LexerATNSimulator: antlr.NewLexerATNSimulator(recog, atn, decisionToDFA, sharedContextCache),\n");
|
||||
grammarBuilder.append(" }\n");
|
||||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append("\n");
|
||||
grammarBuilder.append("func (this *NewPositionAdjustingLexerATNSimulator) ResetAcceptPosition(input CharStream, index, line, charPositionInLine int) {\n");
|
||||
grammarBuilder.append(" this.GetInputStream().Seek(index);\n");
|
||||
grammarBuilder.append(" this.Line = line;\n");
|
||||
grammarBuilder.append(" this.CharPositionInLine = charPositionInLine;\n");
|
||||
grammarBuilder.append(" this.Consume(input);\n");
|
||||
grammarBuilder.append("func (p *NewPositionAdjustingLexerATNSimulator) ResetAcceptPosition(input CharStream, index, line, charPositionInLine int) {\n");
|
||||
grammarBuilder.append(" p.GetInputStream().Seek(index)\n");
|
||||
grammarBuilder.append(" p.Line = line\n");
|
||||
grammarBuilder.append(" p.CharPositionInLine = charPositionInLine\n");
|
||||
grammarBuilder.append(" p.Consume(input)\n");
|
||||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append("\n");
|
||||
grammarBuilder.append("}\n");
|
||||
|
|
|
@ -12,7 +12,7 @@ public class TestListeners extends BaseTest {
|
|||
@Test
|
||||
public void testBasic() throws Exception {
|
||||
mkdir(parserpkgdir);
|
||||
StringBuilder grammarBuilder = new StringBuilder(569);
|
||||
StringBuilder grammarBuilder = new StringBuilder(546);
|
||||
grammarBuilder.append("grammar T;\n");
|
||||
grammarBuilder.append("@parser::header {\n");
|
||||
grammarBuilder.append("}\n");
|
||||
|
@ -23,21 +23,20 @@ public class TestListeners extends BaseTest {
|
|||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append("\n");
|
||||
grammarBuilder.append("func NewLeafListener() *LeafListener {\n");
|
||||
grammarBuilder.append(" l := new(LeafListener)\n");
|
||||
grammarBuilder.append(" l.BaseTListener = new(BaseTListener)\n");
|
||||
grammarBuilder.append(" return l\n");
|
||||
grammarBuilder.append(" return &LeafListener{BaseTListener: &BaseTListener{}}\n");
|
||||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append("\n");
|
||||
grammarBuilder.append("func (this *LeafListener) VisitTerminal( node antlr.TerminalNode ) {\n");
|
||||
grammarBuilder.append("func (*LeafListener) VisitTerminal(node antlr.TerminalNode) {\n");
|
||||
grammarBuilder.append(" fmt.Println(node.GetSymbol().GetText())\n");
|
||||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append("\n");
|
||||
grammarBuilder.append("s\n");
|
||||
grammarBuilder.append("@after {\n");
|
||||
grammarBuilder.append("fmt.Println($ctx.r.ToStringTree(nil,p))\n");
|
||||
grammarBuilder.append("walker := antlr.NewParseTreeWalker();\n");
|
||||
grammarBuilder.append("walker.Walk(NewLeafListener(), $ctx.r);\n");
|
||||
grammarBuilder.append("fmt.Println($ctx.r.ToStringTree(nil, p))\n");
|
||||
grammarBuilder.append("var walker = antlr.NewParseTreeWalker()\n");
|
||||
grammarBuilder.append("\n");
|
||||
grammarBuilder.append("walker.Walk(NewLeafListener(), $ctx.r)\n");
|
||||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append(" : r=a ;\n");
|
||||
grammarBuilder.append("a : INT INT\n");
|
||||
|
@ -51,8 +50,7 @@ public class TestListeners extends BaseTest {
|
|||
String grammar = grammarBuilder.toString();
|
||||
String input ="1 2";
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer",
|
||||
"TListener", "TVisitor",
|
||||
"s", input, false);
|
||||
"TListener", "TVisitor", "s", input, false);
|
||||
assertEquals(
|
||||
"(a 1 2)\n" +
|
||||
"1\n" +
|
||||
|
@ -64,7 +62,7 @@ public class TestListeners extends BaseTest {
|
|||
@Test
|
||||
public void testLR() throws Exception {
|
||||
mkdir(parserpkgdir);
|
||||
StringBuilder grammarBuilder = new StringBuilder(743);
|
||||
StringBuilder grammarBuilder = new StringBuilder(723);
|
||||
grammarBuilder.append("grammar T;\n");
|
||||
grammarBuilder.append("@parser::header {\n");
|
||||
grammarBuilder.append("}\n");
|
||||
|
@ -75,14 +73,12 @@ public class TestListeners extends BaseTest {
|
|||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append("\n");
|
||||
grammarBuilder.append("func NewLeafListener() *LeafListener {\n");
|
||||
grammarBuilder.append(" l := new(LeafListener)\n");
|
||||
grammarBuilder.append(" l.BaseTListener = new(BaseTListener)\n");
|
||||
grammarBuilder.append(" return l\n");
|
||||
grammarBuilder.append(" return &LeafListener{BaseTListener: &BaseTListener{}}\n");
|
||||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append("\n");
|
||||
grammarBuilder.append("func (this *LeafListener) ExitE(ctx *EContext) {\n");
|
||||
grammarBuilder.append(" if (ctx.GetChildCount()==3) {\n");
|
||||
grammarBuilder.append(" fmt.Printf(\"%s %s %s\\n\",ctx.E(0)[0].GetStart().GetText(), ctx.E(1)[0].GetStart().GetText(), ctx.E(-1)[0].GetStart().GetText());\n");
|
||||
grammarBuilder.append("func (*LeafListener) ExitE(ctx *EContext) {\n");
|
||||
grammarBuilder.append(" if ctx.GetChildCount() == 3 {\n");
|
||||
grammarBuilder.append(" fmt.Printf(\"%s %s %s\\n\", ctx.E(0)[0].GetStart().GetText(), ctx.E(1)[0].GetStart().GetText(), ctx.E(-1)[0].GetStart().GetText())\n");
|
||||
grammarBuilder.append(" } else {\n");
|
||||
grammarBuilder.append(" fmt.Println(ctx.INT().GetSymbol().GetText())\n");
|
||||
grammarBuilder.append(" }\n");
|
||||
|
@ -91,9 +87,10 @@ public class TestListeners extends BaseTest {
|
|||
grammarBuilder.append("\n");
|
||||
grammarBuilder.append("s\n");
|
||||
grammarBuilder.append("@after {\n");
|
||||
grammarBuilder.append("fmt.Println($ctx.r.ToStringTree(nil,p))\n");
|
||||
grammarBuilder.append("walker := antlr.NewParseTreeWalker();\n");
|
||||
grammarBuilder.append("walker.Walk(NewLeafListener(), $ctx.r);\n");
|
||||
grammarBuilder.append("fmt.Println($ctx.r.ToStringTree(nil, p))\n");
|
||||
grammarBuilder.append("var walker = antlr.NewParseTreeWalker()\n");
|
||||
grammarBuilder.append("\n");
|
||||
grammarBuilder.append("walker.Walk(NewLeafListener(), $ctx.r)\n");
|
||||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append(" : r=e ;\n");
|
||||
grammarBuilder.append("e : e op='*' e\n");
|
||||
|
@ -108,8 +105,7 @@ public class TestListeners extends BaseTest {
|
|||
String grammar = grammarBuilder.toString();
|
||||
String input ="1+2*3";
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer",
|
||||
"TListener", "TVisitor",
|
||||
"s", input, false);
|
||||
"TListener", "TVisitor", "s", input, false);
|
||||
assertEquals(
|
||||
"(e (e 1) + (e (e 2) * (e 3)))\n" +
|
||||
"1\n" +
|
||||
|
@ -124,7 +120,7 @@ public class TestListeners extends BaseTest {
|
|||
@Test
|
||||
public void testLRWithLabels() throws Exception {
|
||||
mkdir(parserpkgdir);
|
||||
StringBuilder grammarBuilder = new StringBuilder(734);
|
||||
StringBuilder grammarBuilder = new StringBuilder(709);
|
||||
grammarBuilder.append("grammar T;\n");
|
||||
grammarBuilder.append("@parser::header {\n");
|
||||
grammarBuilder.append("}\n");
|
||||
|
@ -135,25 +131,24 @@ public class TestListeners extends BaseTest {
|
|||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append("\n");
|
||||
grammarBuilder.append("func NewLeafListener() *LeafListener {\n");
|
||||
grammarBuilder.append(" l := new(LeafListener)\n");
|
||||
grammarBuilder.append(" l.BaseTListener = new(BaseTListener)\n");
|
||||
grammarBuilder.append(" return l\n");
|
||||
grammarBuilder.append(" return &LeafListener{BaseTListener: &BaseTListener{}}\n");
|
||||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append("\n");
|
||||
grammarBuilder.append("func (this *LeafListener) ExitCall(ctx *CallContext) {\n");
|
||||
grammarBuilder.append(" fmt.Printf(\"%s %s\",ctx.E().GetStart().GetText(),ctx.EList());\n");
|
||||
grammarBuilder.append("func (*LeafListener) ExitCall(ctx *CallContext) {\n");
|
||||
grammarBuilder.append(" fmt.Printf(\"%s %s\", ctx.E().GetStart().GetText(), ctx.EList())\n");
|
||||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append("\n");
|
||||
grammarBuilder.append("func (this *LeafListener) ExitInt(ctx *IntContext) {\n");
|
||||
grammarBuilder.append(" fmt.Println(ctx.INT().GetSymbol().GetText());\n");
|
||||
grammarBuilder.append("func (*LeafListener) ExitInt(ctx *IntContext) {\n");
|
||||
grammarBuilder.append(" fmt.Println(ctx.INT().GetSymbol().GetText())\n");
|
||||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append("\n");
|
||||
grammarBuilder.append("s\n");
|
||||
grammarBuilder.append("@after {\n");
|
||||
grammarBuilder.append("fmt.Println($ctx.r.ToStringTree(nil,p))\n");
|
||||
grammarBuilder.append("walker := antlr.NewParseTreeWalker();\n");
|
||||
grammarBuilder.append("walker.Walk(NewLeafListener(), $ctx.r);\n");
|
||||
grammarBuilder.append("fmt.Println($ctx.r.ToStringTree(nil, p))\n");
|
||||
grammarBuilder.append("var walker = antlr.NewParseTreeWalker()\n");
|
||||
grammarBuilder.append("\n");
|
||||
grammarBuilder.append("walker.Walk(NewLeafListener(), $ctx.r)\n");
|
||||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append(" : r=e ;\n");
|
||||
grammarBuilder.append("e : e '(' eList ')' # Call\n");
|
||||
|
@ -168,8 +163,7 @@ public class TestListeners extends BaseTest {
|
|||
String grammar = grammarBuilder.toString();
|
||||
String input ="1(2,3)";
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer",
|
||||
"TListener", "TVisitor",
|
||||
"s", input, false);
|
||||
"TListener", "TVisitor", "s", input, false);
|
||||
assertEquals(
|
||||
"(e (e 1) ( (eList (e 2) , (e 3)) ))\n" +
|
||||
"1\n" +
|
||||
|
@ -183,7 +177,7 @@ public class TestListeners extends BaseTest {
|
|||
@Test
|
||||
public void testRuleGetters_1() throws Exception {
|
||||
mkdir(parserpkgdir);
|
||||
StringBuilder grammarBuilder = new StringBuilder(768);
|
||||
StringBuilder grammarBuilder = new StringBuilder(749);
|
||||
grammarBuilder.append("grammar T;\n");
|
||||
grammarBuilder.append("@parser::header {\n");
|
||||
grammarBuilder.append("}\n");
|
||||
|
@ -194,25 +188,24 @@ public class TestListeners extends BaseTest {
|
|||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append("\n");
|
||||
grammarBuilder.append("func NewLeafListener() *LeafListener {\n");
|
||||
grammarBuilder.append(" l := new(LeafListener)\n");
|
||||
grammarBuilder.append(" l.BaseTListener = new(BaseTListener)\n");
|
||||
grammarBuilder.append(" return l\n");
|
||||
grammarBuilder.append(" return &LeafListener{BaseTListener: &BaseTListener{}}\n");
|
||||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append("\n");
|
||||
grammarBuilder.append("func (this *LeafListener) ExitA(ctx *AContext) {\n");
|
||||
grammarBuilder.append(" if (ctx.GetChildCount()==2) {\n");
|
||||
grammarBuilder.append(" fmt.Printf(\"%s %s %s\",ctx.B(0)[0].GetStart().GetText(),ctx.B(1)[0].GetStart().GetText(),ctx.B(-1)[0].GetStart().GetText());\n");
|
||||
grammarBuilder.append("func (*LeafListener) ExitA(ctx *AContext) {\n");
|
||||
grammarBuilder.append(" if ctx.GetChildCount() == 2 {\n");
|
||||
grammarBuilder.append(" fmt.Printf(\"%s %s %s\", ctx.B(0)[0].GetStart().GetText(), ctx.B(1)[0].GetStart().GetText(), ctx.B(-1)[0].GetStart().GetText())\n");
|
||||
grammarBuilder.append(" } else {\n");
|
||||
grammarBuilder.append(" fmt.Println(ctx.B(0)[0].GetStart().GetText());\n");
|
||||
grammarBuilder.append(" fmt.Println(ctx.B(0)[0].GetStart().GetText())\n");
|
||||
grammarBuilder.append(" }\n");
|
||||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append("\n");
|
||||
grammarBuilder.append("s\n");
|
||||
grammarBuilder.append("@after {\n");
|
||||
grammarBuilder.append("fmt.Println($ctx.r.ToStringTree(nil,p))\n");
|
||||
grammarBuilder.append("walker := antlr.NewParseTreeWalker();\n");
|
||||
grammarBuilder.append("walker.Walk(NewLeafListener(), $ctx.r);\n");
|
||||
grammarBuilder.append("fmt.Println($ctx.r.ToStringTree(nil, p))\n");
|
||||
grammarBuilder.append("var walker = antlr.NewParseTreeWalker()\n");
|
||||
grammarBuilder.append("\n");
|
||||
grammarBuilder.append("walker.Walk(NewLeafListener(), $ctx.r)\n");
|
||||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append(" : r=a ;\n");
|
||||
grammarBuilder.append("a : b b // forces list\n");
|
||||
|
@ -227,8 +220,7 @@ public class TestListeners extends BaseTest {
|
|||
String grammar = grammarBuilder.toString();
|
||||
String input ="1 2";
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer",
|
||||
"TListener", "TVisitor",
|
||||
"s", input, false);
|
||||
"TListener", "TVisitor", "s", input, false);
|
||||
assertEquals(
|
||||
"(a (b 1) (b 2))\n" +
|
||||
"1 2 1\n", found);
|
||||
|
@ -239,7 +231,7 @@ public class TestListeners extends BaseTest {
|
|||
@Test
|
||||
public void testRuleGetters_2() throws Exception {
|
||||
mkdir(parserpkgdir);
|
||||
StringBuilder grammarBuilder = new StringBuilder(768);
|
||||
StringBuilder grammarBuilder = new StringBuilder(749);
|
||||
grammarBuilder.append("grammar T;\n");
|
||||
grammarBuilder.append("@parser::header {\n");
|
||||
grammarBuilder.append("}\n");
|
||||
|
@ -250,25 +242,24 @@ public class TestListeners extends BaseTest {
|
|||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append("\n");
|
||||
grammarBuilder.append("func NewLeafListener() *LeafListener {\n");
|
||||
grammarBuilder.append(" l := new(LeafListener)\n");
|
||||
grammarBuilder.append(" l.BaseTListener = new(BaseTListener)\n");
|
||||
grammarBuilder.append(" return l\n");
|
||||
grammarBuilder.append(" return &LeafListener{BaseTListener: &BaseTListener{}}\n");
|
||||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append("\n");
|
||||
grammarBuilder.append("func (this *LeafListener) ExitA(ctx *AContext) {\n");
|
||||
grammarBuilder.append(" if (ctx.GetChildCount()==2) {\n");
|
||||
grammarBuilder.append(" fmt.Printf(\"%s %s %s\",ctx.B(0)[0].GetStart().GetText(),ctx.B(1)[0].GetStart().GetText(),ctx.B(-1)[0].GetStart().GetText());\n");
|
||||
grammarBuilder.append("func (*LeafListener) ExitA(ctx *AContext) {\n");
|
||||
grammarBuilder.append(" if ctx.GetChildCount() == 2 {\n");
|
||||
grammarBuilder.append(" fmt.Printf(\"%s %s %s\", ctx.B(0)[0].GetStart().GetText(), ctx.B(1)[0].GetStart().GetText(), ctx.B(-1)[0].GetStart().GetText())\n");
|
||||
grammarBuilder.append(" } else {\n");
|
||||
grammarBuilder.append(" fmt.Println(ctx.B(0)[0].GetStart().GetText());\n");
|
||||
grammarBuilder.append(" fmt.Println(ctx.B(0)[0].GetStart().GetText())\n");
|
||||
grammarBuilder.append(" }\n");
|
||||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append("\n");
|
||||
grammarBuilder.append("s\n");
|
||||
grammarBuilder.append("@after {\n");
|
||||
grammarBuilder.append("fmt.Println($ctx.r.ToStringTree(nil,p))\n");
|
||||
grammarBuilder.append("walker := antlr.NewParseTreeWalker();\n");
|
||||
grammarBuilder.append("walker.Walk(NewLeafListener(), $ctx.r);\n");
|
||||
grammarBuilder.append("fmt.Println($ctx.r.ToStringTree(nil, p))\n");
|
||||
grammarBuilder.append("var walker = antlr.NewParseTreeWalker()\n");
|
||||
grammarBuilder.append("\n");
|
||||
grammarBuilder.append("walker.Walk(NewLeafListener(), $ctx.r)\n");
|
||||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append(" : r=a ;\n");
|
||||
grammarBuilder.append("a : b b // forces list\n");
|
||||
|
@ -283,8 +274,7 @@ public class TestListeners extends BaseTest {
|
|||
String grammar = grammarBuilder.toString();
|
||||
String input ="abc";
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer",
|
||||
"TListener", "TVisitor",
|
||||
"s", input, false);
|
||||
"TListener", "TVisitor", "s", input, false);
|
||||
assertEquals(
|
||||
"(a (b abc))\n" +
|
||||
"abc\n", found);
|
||||
|
@ -295,7 +285,7 @@ public class TestListeners extends BaseTest {
|
|||
@Test
|
||||
public void testTokenGetters_1() throws Exception {
|
||||
mkdir(parserpkgdir);
|
||||
StringBuilder grammarBuilder = new StringBuilder(699);
|
||||
StringBuilder grammarBuilder = new StringBuilder(681);
|
||||
grammarBuilder.append("grammar T;\n");
|
||||
grammarBuilder.append("@parser::header {\n");
|
||||
grammarBuilder.append("}\n");
|
||||
|
@ -306,14 +296,12 @@ public class TestListeners extends BaseTest {
|
|||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append("\n");
|
||||
grammarBuilder.append("func NewLeafListener() *LeafListener {\n");
|
||||
grammarBuilder.append(" l := new(LeafListener)\n");
|
||||
grammarBuilder.append(" l.BaseTListener = new(BaseTListener)\n");
|
||||
grammarBuilder.append(" return l\n");
|
||||
grammarBuilder.append(" return &LeafListener{BaseTListener: &BaseTListener{}}\n");
|
||||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append("\n");
|
||||
grammarBuilder.append("func (this *LeafListener) ExitA(ctx *AContext) {\n");
|
||||
grammarBuilder.append(" if (ctx.GetChildCount()==2){\n");
|
||||
grammarBuilder.append(" fmt.Printf(\"%s %s %s\",ctx.INT(0)[0].GetSymbol().GetText(), ctx.INT(1)[0].GetSymbol().GetText(),ctx.INT(0)[0]);\n");
|
||||
grammarBuilder.append("func (*LeafListener) ExitA(ctx *AContext) {\n");
|
||||
grammarBuilder.append(" if ctx.GetChildCount() == 2 {\n");
|
||||
grammarBuilder.append(" fmt.Printf(\"%s %s %s\", ctx.INT(0)[0].GetSymbol().GetText(), ctx.INT(1)[0].GetSymbol().GetText(), ctx.INT(0)[0])\n");
|
||||
grammarBuilder.append(" } else {\n");
|
||||
grammarBuilder.append(" fmt.Println(ctx.ID().GetSymbol())\n");
|
||||
grammarBuilder.append(" }\n");
|
||||
|
@ -322,9 +310,10 @@ public class TestListeners extends BaseTest {
|
|||
grammarBuilder.append("\n");
|
||||
grammarBuilder.append("s\n");
|
||||
grammarBuilder.append("@after {\n");
|
||||
grammarBuilder.append("fmt.Println($ctx.r.ToStringTree(nil,p))\n");
|
||||
grammarBuilder.append("walker := antlr.NewParseTreeWalker();\n");
|
||||
grammarBuilder.append("walker.Walk(NewLeafListener(), $ctx.r);\n");
|
||||
grammarBuilder.append("fmt.Println($ctx.r.ToStringTree(nil, p))\n");
|
||||
grammarBuilder.append("var walker = antlr.NewParseTreeWalker()\n");
|
||||
grammarBuilder.append("\n");
|
||||
grammarBuilder.append("walker.Walk(NewLeafListener(), $ctx.r)\n");
|
||||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append(" : r=a ;\n");
|
||||
grammarBuilder.append("a : INT INT\n");
|
||||
|
@ -338,8 +327,7 @@ public class TestListeners extends BaseTest {
|
|||
String grammar = grammarBuilder.toString();
|
||||
String input ="1 2";
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer",
|
||||
"TListener", "TVisitor",
|
||||
"s", input, false);
|
||||
"TListener", "TVisitor", "s", input, false);
|
||||
assertEquals(
|
||||
"(a 1 2)\n" +
|
||||
"1 2 [1, 2]\n", found);
|
||||
|
@ -350,7 +338,7 @@ public class TestListeners extends BaseTest {
|
|||
@Test
|
||||
public void testTokenGetters_2() throws Exception {
|
||||
mkdir(parserpkgdir);
|
||||
StringBuilder grammarBuilder = new StringBuilder(699);
|
||||
StringBuilder grammarBuilder = new StringBuilder(681);
|
||||
grammarBuilder.append("grammar T;\n");
|
||||
grammarBuilder.append("@parser::header {\n");
|
||||
grammarBuilder.append("}\n");
|
||||
|
@ -361,14 +349,12 @@ public class TestListeners extends BaseTest {
|
|||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append("\n");
|
||||
grammarBuilder.append("func NewLeafListener() *LeafListener {\n");
|
||||
grammarBuilder.append(" l := new(LeafListener)\n");
|
||||
grammarBuilder.append(" l.BaseTListener = new(BaseTListener)\n");
|
||||
grammarBuilder.append(" return l\n");
|
||||
grammarBuilder.append(" return &LeafListener{BaseTListener: &BaseTListener{}}\n");
|
||||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append("\n");
|
||||
grammarBuilder.append("func (this *LeafListener) ExitA(ctx *AContext) {\n");
|
||||
grammarBuilder.append(" if (ctx.GetChildCount()==2){\n");
|
||||
grammarBuilder.append(" fmt.Printf(\"%s %s %s\",ctx.INT(0)[0].GetSymbol().GetText(), ctx.INT(1)[0].GetSymbol().GetText(),ctx.INT(0)[0]);\n");
|
||||
grammarBuilder.append("func (*LeafListener) ExitA(ctx *AContext) {\n");
|
||||
grammarBuilder.append(" if ctx.GetChildCount() == 2 {\n");
|
||||
grammarBuilder.append(" fmt.Printf(\"%s %s %s\", ctx.INT(0)[0].GetSymbol().GetText(), ctx.INT(1)[0].GetSymbol().GetText(), ctx.INT(0)[0])\n");
|
||||
grammarBuilder.append(" } else {\n");
|
||||
grammarBuilder.append(" fmt.Println(ctx.ID().GetSymbol())\n");
|
||||
grammarBuilder.append(" }\n");
|
||||
|
@ -377,9 +363,10 @@ public class TestListeners extends BaseTest {
|
|||
grammarBuilder.append("\n");
|
||||
grammarBuilder.append("s\n");
|
||||
grammarBuilder.append("@after {\n");
|
||||
grammarBuilder.append("fmt.Println($ctx.r.ToStringTree(nil,p))\n");
|
||||
grammarBuilder.append("walker := antlr.NewParseTreeWalker();\n");
|
||||
grammarBuilder.append("walker.Walk(NewLeafListener(), $ctx.r);\n");
|
||||
grammarBuilder.append("fmt.Println($ctx.r.ToStringTree(nil, p))\n");
|
||||
grammarBuilder.append("var walker = antlr.NewParseTreeWalker()\n");
|
||||
grammarBuilder.append("\n");
|
||||
grammarBuilder.append("walker.Walk(NewLeafListener(), $ctx.r)\n");
|
||||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append(" : r=a ;\n");
|
||||
grammarBuilder.append("a : INT INT\n");
|
||||
|
@ -393,8 +380,7 @@ public class TestListeners extends BaseTest {
|
|||
String grammar = grammarBuilder.toString();
|
||||
String input ="abc";
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer",
|
||||
"TListener", "TVisitor",
|
||||
"s", input, false);
|
||||
"TListener", "TVisitor", "s", input, false);
|
||||
assertEquals(
|
||||
"(a abc)\n" +
|
||||
"[@0,0:2='abc',<4>,1:0]\n", found);
|
||||
|
|
|
@ -12,14 +12,14 @@ public class TestParseTrees extends BaseTest {
|
|||
@Test
|
||||
public void test2AltLoop() throws Exception {
|
||||
mkdir(parserpkgdir);
|
||||
StringBuilder grammarBuilder = new StringBuilder(133);
|
||||
StringBuilder grammarBuilder = new StringBuilder(134);
|
||||
grammarBuilder.append("grammar T;\n");
|
||||
grammarBuilder.append("s\n");
|
||||
grammarBuilder.append("@init {\n");
|
||||
grammarBuilder.append("p.BuildParseTrees = true\n");
|
||||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append("@after {\n");
|
||||
grammarBuilder.append("fmt.Println($r.ctx.ToStringTree(nil,p))\n");
|
||||
grammarBuilder.append("fmt.Println($r.ctx.ToStringTree(nil, p))\n");
|
||||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append(" : r=a ;\n");
|
||||
grammarBuilder.append("a : ('x' | 'y')* 'z'\n");
|
||||
|
@ -27,8 +27,7 @@ public class TestParseTrees extends BaseTest {
|
|||
String grammar = grammarBuilder.toString();
|
||||
String input ="xyyxyxz";
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer",
|
||||
"TListener", "TVisitor",
|
||||
"s", input, false);
|
||||
"TListener", "TVisitor", "s", input, false);
|
||||
assertEquals("(a x y y x y x z)\n", found);
|
||||
assertNull(this.stderrDuringParse);
|
||||
|
||||
|
@ -37,14 +36,14 @@ public class TestParseTrees extends BaseTest {
|
|||
@Test
|
||||
public void test2Alts() throws Exception {
|
||||
mkdir(parserpkgdir);
|
||||
StringBuilder grammarBuilder = new StringBuilder(126);
|
||||
StringBuilder grammarBuilder = new StringBuilder(127);
|
||||
grammarBuilder.append("grammar T;\n");
|
||||
grammarBuilder.append("s\n");
|
||||
grammarBuilder.append("@init {\n");
|
||||
grammarBuilder.append("p.BuildParseTrees = true\n");
|
||||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append("@after {\n");
|
||||
grammarBuilder.append("fmt.Println($r.ctx.ToStringTree(nil,p))\n");
|
||||
grammarBuilder.append("fmt.Println($r.ctx.ToStringTree(nil, p))\n");
|
||||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append(" : r=a ;\n");
|
||||
grammarBuilder.append("a : 'x' | 'y'\n");
|
||||
|
@ -52,8 +51,7 @@ public class TestParseTrees extends BaseTest {
|
|||
String grammar = grammarBuilder.toString();
|
||||
String input ="y";
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer",
|
||||
"TListener", "TVisitor",
|
||||
"s", input, false);
|
||||
"TListener", "TVisitor", "s", input, false);
|
||||
assertEquals("(a y)\n", found);
|
||||
assertNull(this.stderrDuringParse);
|
||||
|
||||
|
@ -62,14 +60,14 @@ public class TestParseTrees extends BaseTest {
|
|||
@Test
|
||||
public void testExtraToken() throws Exception {
|
||||
mkdir(parserpkgdir);
|
||||
StringBuilder grammarBuilder = new StringBuilder(139);
|
||||
StringBuilder grammarBuilder = new StringBuilder(140);
|
||||
grammarBuilder.append("grammar T;\n");
|
||||
grammarBuilder.append("s\n");
|
||||
grammarBuilder.append("@init {\n");
|
||||
grammarBuilder.append("p.BuildParseTrees = true\n");
|
||||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append("@after {\n");
|
||||
grammarBuilder.append("fmt.Println($r.ctx.ToStringTree(nil,p))\n");
|
||||
grammarBuilder.append("fmt.Println($r.ctx.ToStringTree(nil, p))\n");
|
||||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append(" : r=a ;\n");
|
||||
grammarBuilder.append("a : 'x' 'y'\n");
|
||||
|
@ -80,8 +78,7 @@ public class TestParseTrees extends BaseTest {
|
|||
String grammar = grammarBuilder.toString();
|
||||
String input ="xzy";
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer",
|
||||
"TListener", "TVisitor",
|
||||
"s", input, false);
|
||||
"TListener", "TVisitor", "s", input, false);
|
||||
assertEquals("(a x z y)\n", found);
|
||||
|
||||
assertEquals("line 1:1 extraneous input 'z' expecting 'y'\n", this.stderrDuringParse);
|
||||
|
@ -91,14 +88,14 @@ public class TestParseTrees extends BaseTest {
|
|||
@Test
|
||||
public void testNoViableAlt() throws Exception {
|
||||
mkdir(parserpkgdir);
|
||||
StringBuilder grammarBuilder = new StringBuilder(141);
|
||||
StringBuilder grammarBuilder = new StringBuilder(142);
|
||||
grammarBuilder.append("grammar T;\n");
|
||||
grammarBuilder.append("s\n");
|
||||
grammarBuilder.append("@init {\n");
|
||||
grammarBuilder.append("p.BuildParseTrees = true\n");
|
||||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append("@after {\n");
|
||||
grammarBuilder.append("fmt.Println($r.ctx.ToStringTree(nil,p))\n");
|
||||
grammarBuilder.append("fmt.Println($r.ctx.ToStringTree(nil, p))\n");
|
||||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append(" : r=a ;\n");
|
||||
grammarBuilder.append("a : 'x' | 'y'\n");
|
||||
|
@ -109,8 +106,7 @@ public class TestParseTrees extends BaseTest {
|
|||
String grammar = grammarBuilder.toString();
|
||||
String input ="z";
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer",
|
||||
"TListener", "TVisitor",
|
||||
"s", input, false);
|
||||
"TListener", "TVisitor", "s", input, false);
|
||||
assertEquals("(a z)\n", found);
|
||||
|
||||
assertEquals("line 1:0 mismatched input 'z' expecting {'x', 'y'}\n", this.stderrDuringParse);
|
||||
|
@ -120,14 +116,14 @@ public class TestParseTrees extends BaseTest {
|
|||
@Test
|
||||
public void testRuleRef() throws Exception {
|
||||
mkdir(parserpkgdir);
|
||||
StringBuilder grammarBuilder = new StringBuilder(135);
|
||||
StringBuilder grammarBuilder = new StringBuilder(136);
|
||||
grammarBuilder.append("grammar T;\n");
|
||||
grammarBuilder.append("s\n");
|
||||
grammarBuilder.append("@init {\n");
|
||||
grammarBuilder.append("p.BuildParseTrees = true\n");
|
||||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append("@after {\n");
|
||||
grammarBuilder.append("fmt.Println($r.ctx.ToStringTree(nil,p))\n");
|
||||
grammarBuilder.append("fmt.Println($r.ctx.ToStringTree(nil, p))\n");
|
||||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append(" : r=a ;\n");
|
||||
grammarBuilder.append("a : b 'x'\n");
|
||||
|
@ -137,8 +133,7 @@ public class TestParseTrees extends BaseTest {
|
|||
String grammar = grammarBuilder.toString();
|
||||
String input ="yx";
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer",
|
||||
"TListener", "TVisitor",
|
||||
"s", input, false);
|
||||
"TListener", "TVisitor", "s", input, false);
|
||||
assertEquals("(a (b y) x)\n", found);
|
||||
assertNull(this.stderrDuringParse);
|
||||
|
||||
|
@ -147,14 +142,14 @@ public class TestParseTrees extends BaseTest {
|
|||
@Test
|
||||
public void testSync() throws Exception {
|
||||
mkdir(parserpkgdir);
|
||||
StringBuilder grammarBuilder = new StringBuilder(142);
|
||||
StringBuilder grammarBuilder = new StringBuilder(143);
|
||||
grammarBuilder.append("grammar T;\n");
|
||||
grammarBuilder.append("s\n");
|
||||
grammarBuilder.append("@init {\n");
|
||||
grammarBuilder.append("p.BuildParseTrees = true\n");
|
||||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append("@after {\n");
|
||||
grammarBuilder.append("fmt.Println($r.ctx.ToStringTree(nil,p))\n");
|
||||
grammarBuilder.append("fmt.Println($r.ctx.ToStringTree(nil, p))\n");
|
||||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append(" : r=a ;\n");
|
||||
grammarBuilder.append("a : 'x' 'y'* '!'\n");
|
||||
|
@ -164,8 +159,7 @@ public class TestParseTrees extends BaseTest {
|
|||
String grammar = grammarBuilder.toString();
|
||||
String input ="xzyy!";
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer",
|
||||
"TListener", "TVisitor",
|
||||
"s", input, false);
|
||||
"TListener", "TVisitor", "s", input, false);
|
||||
assertEquals("(a x z y y !)\n", found);
|
||||
|
||||
assertEquals("line 1:1 extraneous input 'z' expecting {'y', '!'}\n", this.stderrDuringParse);
|
||||
|
@ -175,14 +169,14 @@ public class TestParseTrees extends BaseTest {
|
|||
@Test
|
||||
public void testToken2() throws Exception {
|
||||
mkdir(parserpkgdir);
|
||||
StringBuilder grammarBuilder = new StringBuilder(124);
|
||||
StringBuilder grammarBuilder = new StringBuilder(125);
|
||||
grammarBuilder.append("grammar T;\n");
|
||||
grammarBuilder.append("s\n");
|
||||
grammarBuilder.append("@init {\n");
|
||||
grammarBuilder.append("p.BuildParseTrees = true\n");
|
||||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append("@after {\n");
|
||||
grammarBuilder.append("fmt.Println($r.ctx.ToStringTree(nil,p))\n");
|
||||
grammarBuilder.append("fmt.Println($r.ctx.ToStringTree(nil, p))\n");
|
||||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append(" : r=a ;\n");
|
||||
grammarBuilder.append("a : 'x' 'y'\n");
|
||||
|
@ -190,8 +184,7 @@ public class TestParseTrees extends BaseTest {
|
|||
String grammar = grammarBuilder.toString();
|
||||
String input ="xy";
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer",
|
||||
"TListener", "TVisitor",
|
||||
"s", input, false);
|
||||
"TListener", "TVisitor", "s", input, false);
|
||||
assertEquals("(a x y)\n", found);
|
||||
assertNull(this.stderrDuringParse);
|
||||
|
||||
|
@ -200,14 +193,14 @@ public class TestParseTrees extends BaseTest {
|
|||
@Test
|
||||
public void testTokenAndRuleContextString() throws Exception {
|
||||
mkdir(parserpkgdir);
|
||||
StringBuilder grammarBuilder = new StringBuilder(166);
|
||||
StringBuilder grammarBuilder = new StringBuilder(167);
|
||||
grammarBuilder.append("grammar T;\n");
|
||||
grammarBuilder.append("s\n");
|
||||
grammarBuilder.append("@init {\n");
|
||||
grammarBuilder.append("p.BuildParseTrees = true\n");
|
||||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append("@after {\n");
|
||||
grammarBuilder.append("fmt.Println($r.ctx.ToStringTree(nil,p))\n");
|
||||
grammarBuilder.append("fmt.Println($r.ctx.ToStringTree(nil, p))\n");
|
||||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append(" : r=a ;\n");
|
||||
grammarBuilder.append("a : 'x' { \n");
|
||||
|
@ -216,8 +209,7 @@ public class TestParseTrees extends BaseTest {
|
|||
String grammar = grammarBuilder.toString();
|
||||
String input ="x";
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer",
|
||||
"TListener", "TVisitor",
|
||||
"s", input, false);
|
||||
"TListener", "TVisitor", "s", input, false);
|
||||
assertEquals(
|
||||
"[a, s]\n" +
|
||||
"(a x)\n", found);
|
||||
|
|
|
@ -18,8 +18,7 @@ public class TestParserErrors extends BaseTest {
|
|||
String grammar = grammarBuilder.toString();
|
||||
String input ="ac";
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer",
|
||||
"TListener", "TVisitor",
|
||||
"a", input, false);
|
||||
"TListener", "TVisitor", "a", input, false);
|
||||
assertEquals("conjured=[@-1,-1:-1='<missing 'b'>',<2>,1:1]\n", found);
|
||||
|
||||
assertEquals("line 1:1 missing 'b' at 'c'\n", this.stderrDuringParse);
|
||||
|
@ -35,8 +34,7 @@ public class TestParserErrors extends BaseTest {
|
|||
String grammar = grammarBuilder.toString();
|
||||
String input ="ad";
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer",
|
||||
"TListener", "TVisitor",
|
||||
"a", input, false);
|
||||
"TListener", "TVisitor", "a", input, false);
|
||||
assertEquals("conjured=[@-1,-1:-1='<missing 'b'>',<2>,1:1]\n", found);
|
||||
|
||||
assertEquals("line 1:1 missing {'b', 'c'} at 'd'\n", this.stderrDuringParse);
|
||||
|
@ -46,13 +44,14 @@ public class TestParserErrors extends BaseTest {
|
|||
@Test
|
||||
public void testContextListGetters() throws Exception {
|
||||
mkdir(parserpkgdir);
|
||||
StringBuilder grammarBuilder = new StringBuilder(205);
|
||||
StringBuilder grammarBuilder = new StringBuilder(175);
|
||||
grammarBuilder.append("grammar T;\n");
|
||||
grammarBuilder.append("@parser::members{\n");
|
||||
grammarBuilder.append("func foo() {\n");
|
||||
grammarBuilder.append(" SContext s = null;\n");
|
||||
grammarBuilder.append(" List<? extends AContext> a = s.a();\n");
|
||||
grammarBuilder.append(" List<? extends BContext> b = s.b();\n");
|
||||
grammarBuilder.append(" // TODO\n");
|
||||
grammarBuilder.append(" // var s SContext\n");
|
||||
grammarBuilder.append(" // var a = s.A()\n");
|
||||
grammarBuilder.append(" // var b = s.B()\n");
|
||||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append("s : (a | b)+;\n");
|
||||
|
@ -61,8 +60,7 @@ public class TestParserErrors extends BaseTest {
|
|||
String grammar = grammarBuilder.toString();
|
||||
String input ="abab";
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer",
|
||||
"TListener", "TVisitor",
|
||||
"s", input, true);
|
||||
"TListener", "TVisitor", "s", input, true);
|
||||
assertEquals("abab\n", found);
|
||||
assertNull(this.stderrDuringParse);
|
||||
|
||||
|
@ -80,8 +78,7 @@ public class TestParserErrors extends BaseTest {
|
|||
String grammar = grammarBuilder.toString();
|
||||
String input ="x";
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer",
|
||||
"TListener", "TVisitor",
|
||||
"start", input, true);
|
||||
"TListener", "TVisitor", "start", input, true);
|
||||
assertEquals("", found);
|
||||
assertNull(this.stderrDuringParse);
|
||||
|
||||
|
@ -99,8 +96,7 @@ public class TestParserErrors extends BaseTest {
|
|||
String grammar = grammarBuilder.toString();
|
||||
String input ="xx";
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer",
|
||||
"TListener", "TVisitor",
|
||||
"start", input, true);
|
||||
"TListener", "TVisitor", "start", input, true);
|
||||
assertEquals("", found);
|
||||
assertNull(this.stderrDuringParse);
|
||||
|
||||
|
@ -118,8 +114,7 @@ public class TestParserErrors extends BaseTest {
|
|||
String grammar = grammarBuilder.toString();
|
||||
String input ="xxx";
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer",
|
||||
"TListener", "TVisitor",
|
||||
"start", input, true);
|
||||
"TListener", "TVisitor", "start", input, true);
|
||||
assertEquals("", found);
|
||||
assertNull(this.stderrDuringParse);
|
||||
|
||||
|
@ -137,8 +132,7 @@ public class TestParserErrors extends BaseTest {
|
|||
String grammar = grammarBuilder.toString();
|
||||
String input ="xxxx";
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer",
|
||||
"TListener", "TVisitor",
|
||||
"start", input, true);
|
||||
"TListener", "TVisitor", "start", input, true);
|
||||
assertEquals("", found);
|
||||
assertNull(this.stderrDuringParse);
|
||||
|
||||
|
@ -156,8 +150,7 @@ public class TestParserErrors extends BaseTest {
|
|||
String grammar = grammarBuilder.toString();
|
||||
String input ="x:x";
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer",
|
||||
"TListener", "TVisitor",
|
||||
"start", input, false);
|
||||
"TListener", "TVisitor", "start", input, false);
|
||||
assertEquals("", found);
|
||||
assertNull(this.stderrDuringParse);
|
||||
|
||||
|
@ -173,8 +166,7 @@ public class TestParserErrors extends BaseTest {
|
|||
String grammar = grammarBuilder.toString();
|
||||
String input ="";
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer",
|
||||
"TListener", "TVisitor",
|
||||
"start", input, true);
|
||||
"TListener", "TVisitor", "start", input, true);
|
||||
assertEquals("", found);
|
||||
|
||||
assertEquals("line 1:0 missing ID at '<EOF>'\n", this.stderrDuringParse);
|
||||
|
@ -202,8 +194,7 @@ public class TestParserErrors extends BaseTest {
|
|||
String grammar = grammarBuilder.toString();
|
||||
String input ="dog and software";
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer",
|
||||
"TListener", "TVisitor",
|
||||
"start", input, false);
|
||||
"TListener", "TVisitor", "start", input, false);
|
||||
assertEquals("{'hardware', 'software'}\n", found);
|
||||
assertNull(this.stderrDuringParse);
|
||||
|
||||
|
@ -221,8 +212,7 @@ public class TestParserErrors extends BaseTest {
|
|||
String grammar = grammarBuilder.toString();
|
||||
String input ="ae";
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer",
|
||||
"TListener", "TVisitor",
|
||||
"a", input, false);
|
||||
"TListener", "TVisitor", "a", input, false);
|
||||
assertEquals("", found);
|
||||
|
||||
assertEquals("line 1:1 no viable alternative at input 'ae'\n", this.stderrDuringParse);
|
||||
|
@ -241,8 +231,7 @@ public class TestParserErrors extends BaseTest {
|
|||
String grammar = grammarBuilder.toString();
|
||||
String input ="abe";
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer",
|
||||
"TListener", "TVisitor",
|
||||
"a", input, false);
|
||||
"TListener", "TVisitor", "a", input, false);
|
||||
assertEquals("", found);
|
||||
|
||||
assertEquals("line 1:2 no viable alternative at input 'abe'\n", this.stderrDuringParse);
|
||||
|
@ -261,8 +250,7 @@ public class TestParserErrors extends BaseTest {
|
|||
String grammar = grammarBuilder.toString();
|
||||
String input ="aaae";
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer",
|
||||
"TListener", "TVisitor",
|
||||
"a", input, false);
|
||||
"TListener", "TVisitor", "a", input, false);
|
||||
assertEquals("", found);
|
||||
|
||||
assertEquals("line 1:3 no viable alternative at input 'aaae'\n", this.stderrDuringParse);
|
||||
|
@ -278,8 +266,7 @@ public class TestParserErrors extends BaseTest {
|
|||
String grammar = grammarBuilder.toString();
|
||||
String input ="aacabc";
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer",
|
||||
"TListener", "TVisitor",
|
||||
"a", input, false);
|
||||
"TListener", "TVisitor", "a", input, false);
|
||||
assertEquals("", found);
|
||||
|
||||
assertEquals("line 1:1 extraneous input 'a' expecting {'b', 'c'}\n", this.stderrDuringParse);
|
||||
|
@ -295,8 +282,7 @@ public class TestParserErrors extends BaseTest {
|
|||
String grammar = grammarBuilder.toString();
|
||||
String input ="aacabc";
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer",
|
||||
"TListener", "TVisitor",
|
||||
"a", input, false);
|
||||
"TListener", "TVisitor", "a", input, false);
|
||||
assertEquals("", found);
|
||||
|
||||
assertEquals("line 1:1 extraneous input 'a' expecting {'b', 'z', 'c'}\n", this.stderrDuringParse);
|
||||
|
@ -312,8 +298,7 @@ public class TestParserErrors extends BaseTest {
|
|||
String grammar = grammarBuilder.toString();
|
||||
String input ="abaaababc";
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer",
|
||||
"TListener", "TVisitor",
|
||||
"a", input, false);
|
||||
"TListener", "TVisitor", "a", input, false);
|
||||
assertEquals("", found);
|
||||
|
||||
assertEquals(
|
||||
|
@ -331,8 +316,7 @@ public class TestParserErrors extends BaseTest {
|
|||
String grammar = grammarBuilder.toString();
|
||||
String input ="abaaababc";
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer",
|
||||
"TListener", "TVisitor",
|
||||
"a", input, false);
|
||||
"TListener", "TVisitor", "a", input, false);
|
||||
assertEquals("", found);
|
||||
|
||||
assertEquals(
|
||||
|
@ -355,8 +339,7 @@ public class TestParserErrors extends BaseTest {
|
|||
String grammar = grammarBuilder.toString();
|
||||
String input ="a.";
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer",
|
||||
"TListener", "TVisitor",
|
||||
"s", input, false);
|
||||
"TListener", "TVisitor", "s", input, false);
|
||||
assertEquals("", found);
|
||||
|
||||
assertEquals("line 1:1 mismatched input '.' expecting '!'\n", this.stderrDuringParse);
|
||||
|
@ -372,8 +355,7 @@ public class TestParserErrors extends BaseTest {
|
|||
String grammar = grammarBuilder.toString();
|
||||
String input ="ad";
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer",
|
||||
"TListener", "TVisitor",
|
||||
"a", input, false);
|
||||
"TListener", "TVisitor", "a", input, false);
|
||||
assertEquals("", found);
|
||||
|
||||
assertEquals("line 1:1 missing {'b', 'c'} at 'd'\n", this.stderrDuringParse);
|
||||
|
@ -390,8 +372,7 @@ public class TestParserErrors extends BaseTest {
|
|||
String grammar = grammarBuilder.toString();
|
||||
String input ="ad";
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer",
|
||||
"TListener", "TVisitor",
|
||||
"a", input, false);
|
||||
"TListener", "TVisitor", "a", input, false);
|
||||
assertEquals("[@0,0:0='a',<3>,1:0]\n", found);
|
||||
|
||||
assertEquals("line 1:1 missing {'b', 'c'} at 'd'\n", this.stderrDuringParse);
|
||||
|
@ -407,8 +388,7 @@ public class TestParserErrors extends BaseTest {
|
|||
String grammar = grammarBuilder.toString();
|
||||
String input ="aab";
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer",
|
||||
"TListener", "TVisitor",
|
||||
"a", input, false);
|
||||
"TListener", "TVisitor", "a", input, false);
|
||||
assertEquals("", found);
|
||||
|
||||
assertEquals("line 1:1 extraneous input 'a' expecting 'b'\n", this.stderrDuringParse);
|
||||
|
@ -427,8 +407,7 @@ public class TestParserErrors extends BaseTest {
|
|||
String grammar = grammarBuilder.toString();
|
||||
String input ="ac";
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer",
|
||||
"TListener", "TVisitor",
|
||||
"a", input, false);
|
||||
"TListener", "TVisitor", "a", input, false);
|
||||
assertEquals("", found);
|
||||
|
||||
assertEquals("line 1:0 extraneous input 'a' expecting {'b', 'c'}\n", this.stderrDuringParse);
|
||||
|
@ -444,8 +423,7 @@ public class TestParserErrors extends BaseTest {
|
|||
String grammar = grammarBuilder.toString();
|
||||
String input ="aabc";
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer",
|
||||
"TListener", "TVisitor",
|
||||
"a", input, false);
|
||||
"TListener", "TVisitor", "a", input, false);
|
||||
assertEquals("", found);
|
||||
|
||||
assertEquals(
|
||||
|
@ -463,8 +441,7 @@ public class TestParserErrors extends BaseTest {
|
|||
String grammar = grammarBuilder.toString();
|
||||
String input ="aabc";
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer",
|
||||
"TListener", "TVisitor",
|
||||
"a", input, false);
|
||||
"TListener", "TVisitor", "a", input, false);
|
||||
assertEquals("", found);
|
||||
|
||||
assertEquals(
|
||||
|
@ -485,8 +462,7 @@ public class TestParserErrors extends BaseTest {
|
|||
String grammar = grammarBuilder.toString();
|
||||
String input ="caaab";
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer",
|
||||
"TListener", "TVisitor",
|
||||
"a", input, false);
|
||||
"TListener", "TVisitor", "a", input, false);
|
||||
assertEquals("", found);
|
||||
|
||||
assertEquals("line 1:0 extraneous input 'c' expecting 'a'\n", this.stderrDuringParse);
|
||||
|
@ -503,8 +479,7 @@ public class TestParserErrors extends BaseTest {
|
|||
String grammar = grammarBuilder.toString();
|
||||
String input ="aabd";
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer",
|
||||
"TListener", "TVisitor",
|
||||
"a", input, false);
|
||||
"TListener", "TVisitor", "a", input, false);
|
||||
assertEquals("[@2,2:2='b',<1>,1:2]\n", found);
|
||||
|
||||
assertEquals("line 1:1 extraneous input 'a' expecting {'b', 'c'}\n", this.stderrDuringParse);
|
||||
|
@ -520,8 +495,7 @@ public class TestParserErrors extends BaseTest {
|
|||
String grammar = grammarBuilder.toString();
|
||||
String input ="ababbc";
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer",
|
||||
"TListener", "TVisitor",
|
||||
"a", input, false);
|
||||
"TListener", "TVisitor", "a", input, false);
|
||||
assertEquals("", found);
|
||||
|
||||
assertEquals("line 1:2 extraneous input 'a' expecting {'b', 'c'}\n", this.stderrDuringParse);
|
||||
|
@ -537,8 +511,7 @@ public class TestParserErrors extends BaseTest {
|
|||
String grammar = grammarBuilder.toString();
|
||||
String input ="ababbc";
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer",
|
||||
"TListener", "TVisitor",
|
||||
"a", input, false);
|
||||
"TListener", "TVisitor", "a", input, false);
|
||||
assertEquals("", found);
|
||||
|
||||
assertEquals("line 1:2 extraneous input 'a' expecting {'b', 'z', 'c'}\n", this.stderrDuringParse);
|
||||
|
@ -554,8 +527,7 @@ public class TestParserErrors extends BaseTest {
|
|||
String grammar = grammarBuilder.toString();
|
||||
String input ="aab";
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer",
|
||||
"TListener", "TVisitor",
|
||||
"a", input, false);
|
||||
"TListener", "TVisitor", "a", input, false);
|
||||
assertEquals("", found);
|
||||
|
||||
assertEquals("line 1:1 extraneous input 'a' expecting {'b', 'c'}\n", this.stderrDuringParse);
|
||||
|
@ -571,8 +543,7 @@ public class TestParserErrors extends BaseTest {
|
|||
String grammar = grammarBuilder.toString();
|
||||
String input ="ac";
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer",
|
||||
"TListener", "TVisitor",
|
||||
"a", input, false);
|
||||
"TListener", "TVisitor", "a", input, false);
|
||||
assertEquals("", found);
|
||||
|
||||
assertEquals("line 1:1 missing 'b' at 'c'\n", this.stderrDuringParse);
|
||||
|
@ -588,8 +559,7 @@ public class TestParserErrors extends BaseTest {
|
|||
String grammar = grammarBuilder.toString();
|
||||
String input ="aa";
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer",
|
||||
"TListener", "TVisitor",
|
||||
"a", input, false);
|
||||
"TListener", "TVisitor", "a", input, false);
|
||||
assertEquals("", found);
|
||||
|
||||
assertEquals("line 1:1 mismatched input 'a' expecting 'b'\n", this.stderrDuringParse);
|
||||
|
@ -612,8 +582,7 @@ public class TestParserErrors extends BaseTest {
|
|||
String grammar = grammarBuilder.toString();
|
||||
String input ="( ~FORCE_ERROR~ ";
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer",
|
||||
"TListener", "TVisitor",
|
||||
"stat", input, false);
|
||||
"TListener", "TVisitor", "stat", input, false);
|
||||
assertEquals("", found);
|
||||
|
||||
assertEquals("line 1:2 mismatched input '~FORCE_ERROR~' expecting ')'\n", this.stderrDuringParse);
|
||||
|
|
|
@ -22,8 +22,7 @@ public class TestParserExec extends BaseTest {
|
|||
String grammar = grammarBuilder.toString();
|
||||
String input ="a b c";
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer",
|
||||
"TListener", "TVisitor",
|
||||
"a", input, false);
|
||||
"TListener", "TVisitor", "a", input, false);
|
||||
assertEquals("abc\n", found);
|
||||
assertNull(this.stderrDuringParse);
|
||||
|
||||
|
@ -42,8 +41,7 @@ public class TestParserExec extends BaseTest {
|
|||
String grammar = grammarBuilder.toString();
|
||||
String input ="";
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer",
|
||||
"TListener", "TVisitor",
|
||||
"a", input, false);
|
||||
"TListener", "TVisitor", "a", input, false);
|
||||
assertEquals("\n", found);
|
||||
assertNull(this.stderrDuringParse);
|
||||
|
||||
|
@ -62,8 +60,7 @@ public class TestParserExec extends BaseTest {
|
|||
String grammar = grammarBuilder.toString();
|
||||
String input ="a b c";
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer",
|
||||
"TListener", "TVisitor",
|
||||
"a", input, false);
|
||||
"TListener", "TVisitor", "a", input, false);
|
||||
assertEquals("abc\n", found);
|
||||
assertNull(this.stderrDuringParse);
|
||||
|
||||
|
@ -82,8 +79,7 @@ public class TestParserExec extends BaseTest {
|
|||
String grammar = grammarBuilder.toString();
|
||||
String input ="a b c";
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer",
|
||||
"TListener", "TVisitor",
|
||||
"a", input, false);
|
||||
"TListener", "TVisitor", "a", input, false);
|
||||
assertEquals("abc\n", found);
|
||||
assertNull(this.stderrDuringParse);
|
||||
|
||||
|
@ -102,8 +98,7 @@ public class TestParserExec extends BaseTest {
|
|||
String grammar = grammarBuilder.toString();
|
||||
String input ="";
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer",
|
||||
"TListener", "TVisitor",
|
||||
"a", input, false);
|
||||
"TListener", "TVisitor", "a", input, false);
|
||||
assertEquals("\n", found);
|
||||
assertNull(this.stderrDuringParse);
|
||||
|
||||
|
@ -122,8 +117,7 @@ public class TestParserExec extends BaseTest {
|
|||
String grammar = grammarBuilder.toString();
|
||||
String input ="a b c";
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer",
|
||||
"TListener", "TVisitor",
|
||||
"a", input, false);
|
||||
"TListener", "TVisitor", "a", input, false);
|
||||
assertEquals("abc\n", found);
|
||||
assertNull(this.stderrDuringParse);
|
||||
|
||||
|
@ -145,8 +139,7 @@ public class TestParserExec extends BaseTest {
|
|||
String grammar = grammarBuilder.toString();
|
||||
String input ="34";
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer",
|
||||
"TListener", "TVisitor",
|
||||
"a", input, false);
|
||||
"TListener", "TVisitor", "a", input, false);
|
||||
assertEquals("alt 2\n", found);
|
||||
assertNull(this.stderrDuringParse);
|
||||
|
||||
|
@ -167,8 +160,7 @@ public class TestParserExec extends BaseTest {
|
|||
String grammar = grammarBuilder.toString();
|
||||
String input ="a 34 c";
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer",
|
||||
"TListener", "TVisitor",
|
||||
"a", input, false);
|
||||
"TListener", "TVisitor", "a", input, false);
|
||||
assertEquals("a34c\n", found);
|
||||
assertNull(this.stderrDuringParse);
|
||||
|
||||
|
@ -189,8 +181,7 @@ public class TestParserExec extends BaseTest {
|
|||
String grammar = grammarBuilder.toString();
|
||||
String input ="";
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer",
|
||||
"TListener", "TVisitor",
|
||||
"a", input, false);
|
||||
"TListener", "TVisitor", "a", input, false);
|
||||
assertEquals("\n", found);
|
||||
assertNull(this.stderrDuringParse);
|
||||
|
||||
|
@ -211,8 +202,7 @@ public class TestParserExec extends BaseTest {
|
|||
String grammar = grammarBuilder.toString();
|
||||
String input ="a 34 c";
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer",
|
||||
"TListener", "TVisitor",
|
||||
"a", input, false);
|
||||
"TListener", "TVisitor", "a", input, false);
|
||||
assertEquals("a34c\n", found);
|
||||
assertNull(this.stderrDuringParse);
|
||||
|
||||
|
@ -232,8 +222,7 @@ public class TestParserExec extends BaseTest {
|
|||
String grammar = grammarBuilder.toString();
|
||||
String input ="abc 34";
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer",
|
||||
"TListener", "TVisitor",
|
||||
"a", input, false);
|
||||
"TListener", "TVisitor", "a", input, false);
|
||||
assertEquals("abc34\n", found);
|
||||
assertNull(this.stderrDuringParse);
|
||||
|
||||
|
@ -249,8 +238,7 @@ public class TestParserExec extends BaseTest {
|
|||
String grammar = grammarBuilder.toString();
|
||||
String input ="x";
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer",
|
||||
"TListener", "TVisitor",
|
||||
"prog", input, false);
|
||||
"TListener", "TVisitor", "prog", input, false);
|
||||
assertEquals("", found);
|
||||
assertNull(this.stderrDuringParse);
|
||||
|
||||
|
@ -271,8 +259,7 @@ public class TestParserExec extends BaseTest {
|
|||
String grammar = grammarBuilder.toString();
|
||||
String input ="if y if y x else x";
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer",
|
||||
"TListener", "TVisitor",
|
||||
"start", input, false);
|
||||
"TListener", "TVisitor", "start", input, false);
|
||||
assertEquals(
|
||||
"if y x else x\n" +
|
||||
"if y if y x else x\n", found);
|
||||
|
@ -295,8 +282,7 @@ public class TestParserExec extends BaseTest {
|
|||
String grammar = grammarBuilder.toString();
|
||||
String input ="if y if y x else x";
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer",
|
||||
"TListener", "TVisitor",
|
||||
"start", input, false);
|
||||
"TListener", "TVisitor", "start", input, false);
|
||||
assertEquals(
|
||||
"if y x else x\n" +
|
||||
"if y if y x else x\n", found);
|
||||
|
@ -319,8 +305,7 @@ public class TestParserExec extends BaseTest {
|
|||
String grammar = grammarBuilder.toString();
|
||||
String input ="if y if y x else x";
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer",
|
||||
"TListener", "TVisitor",
|
||||
"start", input, false);
|
||||
"TListener", "TVisitor", "start", input, false);
|
||||
assertEquals(
|
||||
"if y x\n" +
|
||||
"if y if y x else x\n", found);
|
||||
|
@ -343,8 +328,7 @@ public class TestParserExec extends BaseTest {
|
|||
String grammar = grammarBuilder.toString();
|
||||
String input ="if y if y x else x";
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer",
|
||||
"TListener", "TVisitor",
|
||||
"start", input, false);
|
||||
"TListener", "TVisitor", "start", input, false);
|
||||
assertEquals(
|
||||
"if y x\n" +
|
||||
"if y if y x else x\n", found);
|
||||
|
@ -366,8 +350,7 @@ public class TestParserExec extends BaseTest {
|
|||
String grammar = grammarBuilder.toString();
|
||||
String input ="";
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer",
|
||||
"TListener", "TVisitor",
|
||||
"a", input, false);
|
||||
"TListener", "TVisitor", "a", input, false);
|
||||
assertEquals("\n", found);
|
||||
assertNull(this.stderrDuringParse);
|
||||
|
||||
|
@ -387,8 +370,7 @@ public class TestParserExec extends BaseTest {
|
|||
String grammar = grammarBuilder.toString();
|
||||
String input ="a";
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer",
|
||||
"TListener", "TVisitor",
|
||||
"a", input, false);
|
||||
"TListener", "TVisitor", "a", input, false);
|
||||
assertEquals("a\n", found);
|
||||
assertNull(this.stderrDuringParse);
|
||||
|
||||
|
@ -409,8 +391,7 @@ public class TestParserExec extends BaseTest {
|
|||
String grammar = grammarBuilder.toString();
|
||||
String input ="xy";
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer",
|
||||
"TListener", "TVisitor",
|
||||
"start", input, false);
|
||||
"TListener", "TVisitor", "start", input, false);
|
||||
assertEquals(
|
||||
"x\n" +
|
||||
"y\n", found);
|
||||
|
@ -431,8 +412,7 @@ public class TestParserExec extends BaseTest {
|
|||
String grammar = grammarBuilder.toString();
|
||||
String input ="abc 34;";
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer",
|
||||
"TListener", "TVisitor",
|
||||
"a", input, false);
|
||||
"TListener", "TVisitor", "a", input, false);
|
||||
assertEquals("", found);
|
||||
assertNull(this.stderrDuringParse);
|
||||
|
||||
|
@ -464,8 +444,7 @@ public class TestParserExec extends BaseTest {
|
|||
String grammar = grammarBuilder.toString();
|
||||
String input ="a";
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer",
|
||||
"TListener", "TVisitor",
|
||||
"expression", input, false);
|
||||
"TListener", "TVisitor", "expression", input, false);
|
||||
assertEquals("", found);
|
||||
assertNull(this.stderrDuringParse);
|
||||
|
||||
|
@ -485,8 +464,7 @@ public class TestParserExec extends BaseTest {
|
|||
String grammar = grammarBuilder.toString();
|
||||
String input ="abc 34;";
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer",
|
||||
"TListener", "TVisitor",
|
||||
"a", input, false);
|
||||
"TListener", "TVisitor", "a", input, false);
|
||||
assertEquals("", found);
|
||||
assertNull(this.stderrDuringParse);
|
||||
|
||||
|
@ -501,8 +479,7 @@ public class TestParserExec extends BaseTest {
|
|||
String grammar = grammarBuilder.toString();
|
||||
String input ="x";
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer",
|
||||
"TListener", "TVisitor",
|
||||
"prog", input, false);
|
||||
"TListener", "TVisitor", "prog", input, false);
|
||||
assertEquals("", found);
|
||||
assertNull(this.stderrDuringParse);
|
||||
|
||||
|
@ -519,8 +496,7 @@ public class TestParserExec extends BaseTest {
|
|||
String grammar = grammarBuilder.toString();
|
||||
String input ="x";
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer",
|
||||
"TListener", "TVisitor",
|
||||
"stat", input, false);
|
||||
"TListener", "TVisitor", "stat", input, false);
|
||||
assertEquals("", found);
|
||||
assertNull(this.stderrDuringParse);
|
||||
|
||||
|
@ -537,8 +513,7 @@ public class TestParserExec extends BaseTest {
|
|||
String grammar = grammarBuilder.toString();
|
||||
String input ="if x";
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer",
|
||||
"TListener", "TVisitor",
|
||||
"stat", input, false);
|
||||
"TListener", "TVisitor", "stat", input, false);
|
||||
assertEquals("", found);
|
||||
assertNull(this.stderrDuringParse);
|
||||
|
||||
|
@ -555,8 +530,7 @@ public class TestParserExec extends BaseTest {
|
|||
String grammar = grammarBuilder.toString();
|
||||
String input ="if x else x";
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer",
|
||||
"TListener", "TVisitor",
|
||||
"stat", input, false);
|
||||
"TListener", "TVisitor", "stat", input, false);
|
||||
assertEquals("", found);
|
||||
assertNull(this.stderrDuringParse);
|
||||
|
||||
|
@ -573,8 +547,7 @@ public class TestParserExec extends BaseTest {
|
|||
String grammar = grammarBuilder.toString();
|
||||
String input ="if if x else x";
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer",
|
||||
"TListener", "TVisitor",
|
||||
"stat", input, false);
|
||||
"TListener", "TVisitor", "stat", input, false);
|
||||
assertEquals("", found);
|
||||
assertNull(this.stderrDuringParse);
|
||||
|
||||
|
@ -583,11 +556,11 @@ public class TestParserExec extends BaseTest {
|
|||
@Test
|
||||
public void testParserProperty() throws Exception {
|
||||
mkdir(parserpkgdir);
|
||||
StringBuilder grammarBuilder = new StringBuilder(161);
|
||||
StringBuilder grammarBuilder = new StringBuilder(152);
|
||||
grammarBuilder.append("grammar T;\n");
|
||||
grammarBuilder.append("@members {\n");
|
||||
grammarBuilder.append("func Property() bool {\n");
|
||||
grammarBuilder.append(" return true\n");
|
||||
grammarBuilder.append(" return true\n");
|
||||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append("a : {Property()}? ID {fmt.Println(\"valid\")}\n");
|
||||
|
@ -597,8 +570,7 @@ public class TestParserExec extends BaseTest {
|
|||
String grammar = grammarBuilder.toString();
|
||||
String input ="abc";
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer",
|
||||
"TListener", "TVisitor",
|
||||
"a", input, false);
|
||||
"TListener", "TVisitor", "a", input, false);
|
||||
assertEquals("valid\n", found);
|
||||
assertNull(this.stderrDuringParse);
|
||||
|
||||
|
@ -607,19 +579,18 @@ public class TestParserExec extends BaseTest {
|
|||
@Test
|
||||
public void testPredicatedIfIfElse() throws Exception {
|
||||
mkdir(parserpkgdir);
|
||||
StringBuilder grammarBuilder = new StringBuilder(182);
|
||||
StringBuilder grammarBuilder = new StringBuilder(183);
|
||||
grammarBuilder.append("grammar T;\n");
|
||||
grammarBuilder.append("s : stmt EOF ;\n");
|
||||
grammarBuilder.append("stmt : ifStmt | ID;\n");
|
||||
grammarBuilder.append("ifStmt : 'if' ID stmt ('else' stmt | { p.GetTokenStream().LA(1)!=TParserELSE }?);\n");
|
||||
grammarBuilder.append("ifStmt : 'if' ID stmt ('else' stmt | { p.GetTokenStream().LA(1) != TParserELSE }?);\n");
|
||||
grammarBuilder.append("ELSE : 'else';\n");
|
||||
grammarBuilder.append("ID : [a-zA-Z]+;\n");
|
||||
grammarBuilder.append("WS : [ \\n\\t]+ -> skip;");
|
||||
String grammar = grammarBuilder.toString();
|
||||
String input ="if x if x a else b";
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer",
|
||||
"TListener", "TVisitor",
|
||||
"s", input, true);
|
||||
"TListener", "TVisitor", "s", input, true);
|
||||
assertEquals("", found);
|
||||
assertNull(this.stderrDuringParse);
|
||||
|
||||
|
@ -628,13 +599,13 @@ public class TestParserExec extends BaseTest {
|
|||
@Test
|
||||
public void testPredictionIssue334() throws Exception {
|
||||
mkdir(parserpkgdir);
|
||||
StringBuilder grammarBuilder = new StringBuilder(246);
|
||||
StringBuilder grammarBuilder = new StringBuilder(251);
|
||||
grammarBuilder.append("grammar T;\n");
|
||||
grammarBuilder.append("file_ @init{\n");
|
||||
grammarBuilder.append("SetErrorHandler(NewBailErrorStrategy())\n");
|
||||
grammarBuilder.append("p.SetErrorHandler(p.NewBailErrorStrategy())\n");
|
||||
grammarBuilder.append("} \n");
|
||||
grammarBuilder.append("@after {\n");
|
||||
grammarBuilder.append("fmt.Println($ctx.ToStringTree(nil,p))\n");
|
||||
grammarBuilder.append("fmt.Println($ctx.ToStringTree(nil, p))\n");
|
||||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append(" : item (SEMICOLON item)* SEMICOLON? EOF ;\n");
|
||||
grammarBuilder.append("item : A B?;\n");
|
||||
|
@ -645,8 +616,7 @@ public class TestParserExec extends BaseTest {
|
|||
String grammar = grammarBuilder.toString();
|
||||
String input ="a";
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer",
|
||||
"TListener", "TVisitor",
|
||||
"file_", input, false);
|
||||
"TListener", "TVisitor", "file_", input, false);
|
||||
assertEquals("(file_ (item a) <EOF>)\n", found);
|
||||
assertNull(this.stderrDuringParse);
|
||||
|
||||
|
@ -664,8 +634,7 @@ public class TestParserExec extends BaseTest {
|
|||
String grammar = grammarBuilder.toString();
|
||||
String input ="";
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer",
|
||||
"TListener", "TVisitor",
|
||||
"a", input, false);
|
||||
"TListener", "TVisitor", "a", input, false);
|
||||
assertEquals("\n", found);
|
||||
assertNull(this.stderrDuringParse);
|
||||
|
||||
|
@ -683,8 +652,7 @@ public class TestParserExec extends BaseTest {
|
|||
String grammar = grammarBuilder.toString();
|
||||
String input ="a 34 c";
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer",
|
||||
"TListener", "TVisitor",
|
||||
"a", input, false);
|
||||
"TListener", "TVisitor", "a", input, false);
|
||||
assertEquals("a34c\n", found);
|
||||
assertNull(this.stderrDuringParse);
|
||||
|
||||
|
|
|
@ -43,8 +43,7 @@ public class TestPerformance extends BaseTest {
|
|||
"not X1 and not X2 and not X3 and not X4 and not X5 and not X6 and not X7 and not X8 and not X9 and not X10 and X11 and not X12 or\n" +
|
||||
"not X1 and not X2 and not X3 and not X4 and not X5 and not X6 and not X7 and not X8 and not X9 and not X10 and not X11 and X12";
|
||||
String found = execParser("Expr.g4", grammar, "ExprParser", "ExprLexer",
|
||||
"ExprListener", "ExprVisitor",
|
||||
"program", input, false);
|
||||
"ExprListener", "ExprVisitor", "program", input, false);
|
||||
assertEquals("", found);
|
||||
assertNull(this.stderrDuringParse);
|
||||
|
||||
|
@ -201,8 +200,7 @@ public class TestPerformance extends BaseTest {
|
|||
"not X1 and not X2 and not X3 and not X4 and not X5 and not X6 and not X7 and not X8 and not X9 and not X10 and X11 and not X12 or\n" +
|
||||
"not X1 and not X2 and not X3 and not X4 and not X5 and not X6 and not X7 and not X8 and not X9 and not X10 and not X11 and X12";
|
||||
String found = execParser("Expr.g4", grammar, "ExprParser", "ExprLexer",
|
||||
"ExprListener", "ExprVisitor",
|
||||
"program", input, false);
|
||||
"ExprListener", "ExprVisitor", "program", input, false);
|
||||
assertEquals("", found);
|
||||
assertNull(this.stderrDuringParse);
|
||||
|
||||
|
|
|
@ -113,10 +113,10 @@ public class TestSemPredEvalLexer extends BaseTest {
|
|||
public void testIndent() throws Exception {
|
||||
mkdir(parserpkgdir);
|
||||
|
||||
StringBuilder grammarBuilder = new StringBuilder(137);
|
||||
StringBuilder grammarBuilder = new StringBuilder(139);
|
||||
grammarBuilder.append("lexer grammar L;\n");
|
||||
grammarBuilder.append("ID : [a-z]+ ;\n");
|
||||
grammarBuilder.append("INDENT : [ \\t]+ { p.TokenStartColumn==0 }?\n");
|
||||
grammarBuilder.append("INDENT : [ \\t]+ { p.TokenStartColumn == 0 }?\n");
|
||||
grammarBuilder.append(" { fmt.Println(\"INDENT\") } ;\n");
|
||||
grammarBuilder.append("NL : '\\n';\n");
|
||||
grammarBuilder.append("WS : [ \\t]+ ;");
|
||||
|
|
|
@ -12,7 +12,7 @@ public class TestSemPredEvalParser extends BaseTest {
|
|||
@Test
|
||||
public void test2UnpredicatedAlts() throws Exception {
|
||||
mkdir(parserpkgdir);
|
||||
StringBuilder grammarBuilder = new StringBuilder(300);
|
||||
StringBuilder grammarBuilder = new StringBuilder(299);
|
||||
grammarBuilder.append("grammar T;\n");
|
||||
grammarBuilder.append("s : {p.Interpreter.SetPredictionMode(antlr.PredictionModeLLExactAmbigDetection);} a ';' a; // do 2x: once in ATN, next in DFA\n");
|
||||
grammarBuilder.append("a : ID {fmt.Println(\"alt 1\")}\n");
|
||||
|
@ -25,8 +25,7 @@ public class TestSemPredEvalParser extends BaseTest {
|
|||
String grammar = grammarBuilder.toString();
|
||||
String input ="x; y";
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer",
|
||||
"TListener", "TVisitor",
|
||||
"s", input, true);
|
||||
"TListener", "TVisitor", "s", input, true);
|
||||
assertEquals(
|
||||
"alt 1\n" +
|
||||
"alt 1\n", found);
|
||||
|
@ -42,7 +41,7 @@ public class TestSemPredEvalParser extends BaseTest {
|
|||
@Test
|
||||
public void test2UnpredicatedAltsAndOneOrthogonalAlt() throws Exception {
|
||||
mkdir(parserpkgdir);
|
||||
StringBuilder grammarBuilder = new StringBuilder(351);
|
||||
StringBuilder grammarBuilder = new StringBuilder(350);
|
||||
grammarBuilder.append("grammar T;\n");
|
||||
grammarBuilder.append("s : {p.Interpreter.SetPredictionMode(antlr.PredictionModeLLExactAmbigDetection);} a ';' a ';' a;\n");
|
||||
grammarBuilder.append("a : INT {fmt.Println(\"alt 1\")}\n");
|
||||
|
@ -56,8 +55,7 @@ public class TestSemPredEvalParser extends BaseTest {
|
|||
String grammar = grammarBuilder.toString();
|
||||
String input ="34; x; y";
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer",
|
||||
"TListener", "TVisitor",
|
||||
"s", input, true);
|
||||
"TListener", "TVisitor", "s", input, true);
|
||||
assertEquals(
|
||||
"alt 1\n" +
|
||||
"alt 2\n" +
|
||||
|
@ -87,8 +85,7 @@ public class TestSemPredEvalParser extends BaseTest {
|
|||
String grammar = grammarBuilder.toString();
|
||||
String input ="x x y";
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer",
|
||||
"TListener", "TVisitor",
|
||||
"s", input, false);
|
||||
"TListener", "TVisitor", "s", input, false);
|
||||
assertEquals(
|
||||
"alt 1\n" +
|
||||
"alt 1\n" +
|
||||
|
@ -100,11 +97,12 @@ public class TestSemPredEvalParser extends BaseTest {
|
|||
@Test
|
||||
public void testActionsHidePredsInGlobalFOLLOW() throws Exception {
|
||||
mkdir(parserpkgdir);
|
||||
StringBuilder grammarBuilder = new StringBuilder(279);
|
||||
StringBuilder grammarBuilder = new StringBuilder(278);
|
||||
grammarBuilder.append("grammar T;\n");
|
||||
grammarBuilder.append("@members {\n");
|
||||
grammarBuilder.append("func pred(v bool) bool {\n");
|
||||
grammarBuilder.append(" fmt.Println(\"eval=\"+fmt.Sprint(v))\n");
|
||||
grammarBuilder.append(" fmt.Println(\"eval=\" + fmt.Sprint(v))\n");
|
||||
grammarBuilder.append("\n");
|
||||
grammarBuilder.append(" return v\n");
|
||||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append("}\n");
|
||||
|
@ -117,8 +115,7 @@ public class TestSemPredEvalParser extends BaseTest {
|
|||
String grammar = grammarBuilder.toString();
|
||||
String input ="a!";
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer",
|
||||
"TListener", "TVisitor",
|
||||
"s", input, false);
|
||||
"TListener", "TVisitor", "s", input, false);
|
||||
assertEquals(
|
||||
"eval=true\n" +
|
||||
"parse\n", found);
|
||||
|
@ -138,8 +135,7 @@ public class TestSemPredEvalParser extends BaseTest {
|
|||
String grammar = grammarBuilder.toString();
|
||||
String input ="a+b+a";
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer",
|
||||
"TListener", "TVisitor",
|
||||
"start", input, false);
|
||||
"TListener", "TVisitor", "start", input, false);
|
||||
assertEquals("", found);
|
||||
assertNull(this.stderrDuringParse);
|
||||
|
||||
|
@ -148,17 +144,18 @@ public class TestSemPredEvalParser extends BaseTest {
|
|||
@Test
|
||||
public void testDepedentPredsInGlobalFOLLOW() throws Exception {
|
||||
mkdir(parserpkgdir);
|
||||
StringBuilder grammarBuilder = new StringBuilder(302);
|
||||
StringBuilder grammarBuilder = new StringBuilder(305);
|
||||
grammarBuilder.append("grammar T;\n");
|
||||
grammarBuilder.append("@members {\n");
|
||||
grammarBuilder.append("func pred(v bool) bool {\n");
|
||||
grammarBuilder.append(" fmt.Println(\"eval=\"+fmt.Sprint(v))\n");
|
||||
grammarBuilder.append(" fmt.Println(\"eval=\" + fmt.Sprint(v))\n");
|
||||
grammarBuilder.append("\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)}? {fmt.Println(\"parse\")} '!' ;\n");
|
||||
grammarBuilder.append("b[int i] : e {pred($i==99)}? ID ;\n");
|
||||
grammarBuilder.append("a[int i] : e {pred($i == 99)}? {fmt.Println(\"parse\")} '!' ;\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");
|
||||
|
@ -166,8 +163,7 @@ public class TestSemPredEvalParser extends BaseTest {
|
|||
String grammar = grammarBuilder.toString();
|
||||
String input ="a!";
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer",
|
||||
"TListener", "TVisitor",
|
||||
"s", input, false);
|
||||
"TListener", "TVisitor", "s", input, false);
|
||||
assertEquals(
|
||||
"eval=true\n" +
|
||||
"parse\n", found);
|
||||
|
@ -178,13 +174,13 @@ public class TestSemPredEvalParser extends BaseTest {
|
|||
@Test
|
||||
public void testDependentPredNotInOuterCtxShouldBeIgnored() throws Exception {
|
||||
mkdir(parserpkgdir);
|
||||
StringBuilder grammarBuilder = new StringBuilder(268);
|
||||
StringBuilder grammarBuilder = new StringBuilder(272);
|
||||
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 {fmt.Println(\"alt 1\")}\n");
|
||||
grammarBuilder.append(" | {$i==2}? ID {fmt.Println(\"alt 2\")}\n");
|
||||
grammarBuilder.append(" : {$i == 1}? ID {fmt.Println(\"alt 1\")}\n");
|
||||
grammarBuilder.append(" | {$i == 2}? ID {fmt.Println(\"alt 2\")}\n");
|
||||
grammarBuilder.append(" ;\n");
|
||||
grammarBuilder.append("ID : 'a'..'z'+ ;\n");
|
||||
grammarBuilder.append("INT : '0'..'9'+;\n");
|
||||
|
@ -192,8 +188,7 @@ public class TestSemPredEvalParser extends BaseTest {
|
|||
String grammar = grammarBuilder.toString();
|
||||
String input ="a;";
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer",
|
||||
"TListener", "TVisitor",
|
||||
"s", input, false);
|
||||
"TListener", "TVisitor", "s", input, false);
|
||||
assertEquals("alt 2\n", found);
|
||||
assertNull(this.stderrDuringParse);
|
||||
|
||||
|
@ -211,8 +206,7 @@ public class TestSemPredEvalParser extends BaseTest {
|
|||
String grammar = grammarBuilder.toString();
|
||||
String input ="hello";
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer",
|
||||
"TListener", "TVisitor",
|
||||
"cppCompilationUnit", input, false);
|
||||
"TListener", "TVisitor", "cppCompilationUnit", input, false);
|
||||
assertEquals("", found);
|
||||
assertNull(this.stderrDuringParse);
|
||||
|
||||
|
@ -235,8 +229,7 @@ public class TestSemPredEvalParser extends BaseTest {
|
|||
String grammar = grammarBuilder.toString();
|
||||
String input ="a;";
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer",
|
||||
"TListener", "TVisitor",
|
||||
"s", input, false);
|
||||
"TListener", "TVisitor", "s", input, false);
|
||||
assertEquals("alt 2\n", found);
|
||||
assertNull(this.stderrDuringParse);
|
||||
|
||||
|
@ -257,8 +250,7 @@ public class TestSemPredEvalParser extends BaseTest {
|
|||
String grammar = grammarBuilder.toString();
|
||||
String input ="y 3 x 4";
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer",
|
||||
"TListener", "TVisitor",
|
||||
"s", input, false);
|
||||
"TListener", "TVisitor", "s", input, false);
|
||||
assertEquals("", found);
|
||||
|
||||
assertEquals("line 1:0 no viable alternative at input 'y'\n", this.stderrDuringParse);
|
||||
|
@ -282,8 +274,7 @@ public class TestSemPredEvalParser extends BaseTest {
|
|||
String grammar = grammarBuilder.toString();
|
||||
String input ="x y";
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer",
|
||||
"TListener", "TVisitor",
|
||||
"s", input, false);
|
||||
"TListener", "TVisitor", "s", input, false);
|
||||
assertEquals(
|
||||
"alt 1\n" +
|
||||
"alt 1\n", found);
|
||||
|
@ -294,13 +285,13 @@ public class TestSemPredEvalParser extends BaseTest {
|
|||
@Test
|
||||
public void testPredFromAltTestedInLoopBack_1() throws Exception {
|
||||
mkdir(parserpkgdir);
|
||||
StringBuilder grammarBuilder = new StringBuilder(211);
|
||||
StringBuilder grammarBuilder = new StringBuilder(213);
|
||||
grammarBuilder.append("grammar T;\n");
|
||||
grammarBuilder.append("file_\n");
|
||||
grammarBuilder.append("@after {fmt.Println($ctx.ToStringTree(nil,p))}\n");
|
||||
grammarBuilder.append("@after {fmt.Println($ctx.ToStringTree(nil, p))}\n");
|
||||
grammarBuilder.append(" : para para EOF ;\n");
|
||||
grammarBuilder.append("para: paraContent NL NL ;\n");
|
||||
grammarBuilder.append("paraContent : ('s'|'x'|{p.GetTokenStream().LA(2)!=TParserNL}? NL)+ ;\n");
|
||||
grammarBuilder.append("paraContent : ('s'|'x'|{p.GetTokenStream().LA(2) != TParserNL}? NL)+ ;\n");
|
||||
grammarBuilder.append("NL : '\\n' ;\n");
|
||||
grammarBuilder.append("s : 's' ;\n");
|
||||
grammarBuilder.append("X : 'x' ;");
|
||||
|
@ -311,8 +302,7 @@ public class TestSemPredEvalParser extends BaseTest {
|
|||
"\n" +
|
||||
"x\n";
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer",
|
||||
"TListener", "TVisitor",
|
||||
"file_", input, true);
|
||||
"TListener", "TVisitor", "file_", input, true);
|
||||
assertEquals("(file_ (para (paraContent s) \\n \\n) (para (paraContent \\n x \\n)) <EOF>)\n", found);
|
||||
|
||||
assertEquals(
|
||||
|
@ -324,13 +314,13 @@ public class TestSemPredEvalParser extends BaseTest {
|
|||
@Test
|
||||
public void testPredFromAltTestedInLoopBack_2() throws Exception {
|
||||
mkdir(parserpkgdir);
|
||||
StringBuilder grammarBuilder = new StringBuilder(211);
|
||||
StringBuilder grammarBuilder = new StringBuilder(213);
|
||||
grammarBuilder.append("grammar T;\n");
|
||||
grammarBuilder.append("file_\n");
|
||||
grammarBuilder.append("@after {fmt.Println($ctx.ToStringTree(nil,p))}\n");
|
||||
grammarBuilder.append("@after {fmt.Println($ctx.ToStringTree(nil, p))}\n");
|
||||
grammarBuilder.append(" : para para EOF ;\n");
|
||||
grammarBuilder.append("para: paraContent NL NL ;\n");
|
||||
grammarBuilder.append("paraContent : ('s'|'x'|{p.GetTokenStream().LA(2)!=TParserNL}? NL)+ ;\n");
|
||||
grammarBuilder.append("paraContent : ('s'|'x'|{p.GetTokenStream().LA(2) != TParserNL}? NL)+ ;\n");
|
||||
grammarBuilder.append("NL : '\\n' ;\n");
|
||||
grammarBuilder.append("s : 's' ;\n");
|
||||
grammarBuilder.append("X : 'x' ;");
|
||||
|
@ -342,8 +332,7 @@ public class TestSemPredEvalParser extends BaseTest {
|
|||
"x\n" +
|
||||
"\n";
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer",
|
||||
"TListener", "TVisitor",
|
||||
"file_", input, true);
|
||||
"TListener", "TVisitor", "file_", input, true);
|
||||
assertEquals("(file_ (para (paraContent s) \\n \\n) (para (paraContent \\n x) \\n \\n) <EOF>)\n", found);
|
||||
assertNull(this.stderrDuringParse);
|
||||
|
||||
|
@ -352,9 +341,9 @@ public class TestSemPredEvalParser extends BaseTest {
|
|||
@Test
|
||||
public void testPredTestedEvenWhenUnAmbig_1() throws Exception {
|
||||
mkdir(parserpkgdir);
|
||||
StringBuilder grammarBuilder = new StringBuilder(224);
|
||||
StringBuilder grammarBuilder = new StringBuilder(225);
|
||||
grammarBuilder.append("grammar T;\n");
|
||||
grammarBuilder.append("@members {var enumKeyword bool= true; var _ bool = enumKeyword; }\n");
|
||||
grammarBuilder.append("@members {var enumKeyword bool = true; var _ bool = enumKeyword; }\n");
|
||||
grammarBuilder.append("primary\n");
|
||||
grammarBuilder.append(" : ID {fmt.Println(\"ID \"+$ID.text)}\n");
|
||||
grammarBuilder.append(" | {!enumKeyword}? 'enum' {fmt.Println(\"enum\")}\n");
|
||||
|
@ -364,8 +353,7 @@ public class TestSemPredEvalParser extends BaseTest {
|
|||
String grammar = grammarBuilder.toString();
|
||||
String input ="abc";
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer",
|
||||
"TListener", "TVisitor",
|
||||
"primary", input, false);
|
||||
"TListener", "TVisitor", "primary", input, false);
|
||||
assertEquals("ID abc\n", found);
|
||||
assertNull(this.stderrDuringParse);
|
||||
|
||||
|
@ -374,9 +362,9 @@ public class TestSemPredEvalParser extends BaseTest {
|
|||
@Test
|
||||
public void testPredTestedEvenWhenUnAmbig_2() throws Exception {
|
||||
mkdir(parserpkgdir);
|
||||
StringBuilder grammarBuilder = new StringBuilder(224);
|
||||
StringBuilder grammarBuilder = new StringBuilder(225);
|
||||
grammarBuilder.append("grammar T;\n");
|
||||
grammarBuilder.append("@members {var enumKeyword bool= true; var _ bool = enumKeyword; }\n");
|
||||
grammarBuilder.append("@members {var enumKeyword bool = true; var _ bool = enumKeyword; }\n");
|
||||
grammarBuilder.append("primary\n");
|
||||
grammarBuilder.append(" : ID {fmt.Println(\"ID \"+$ID.text)}\n");
|
||||
grammarBuilder.append(" | {!enumKeyword}? 'enum' {fmt.Println(\"enum\")}\n");
|
||||
|
@ -386,8 +374,7 @@ public class TestSemPredEvalParser extends BaseTest {
|
|||
String grammar = grammarBuilder.toString();
|
||||
String input ="enum";
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer",
|
||||
"TListener", "TVisitor",
|
||||
"primary", input, false);
|
||||
"TListener", "TVisitor", "primary", input, false);
|
||||
assertEquals("", found);
|
||||
|
||||
assertEquals("line 1:0 no viable alternative at input 'enum'\n", this.stderrDuringParse);
|
||||
|
@ -397,13 +384,13 @@ public class TestSemPredEvalParser extends BaseTest {
|
|||
@Test
|
||||
public void testPredicateDependentOnArg() throws Exception {
|
||||
mkdir(parserpkgdir);
|
||||
StringBuilder grammarBuilder = new StringBuilder(218);
|
||||
StringBuilder grammarBuilder = new StringBuilder(222);
|
||||
grammarBuilder.append("grammar T;\n");
|
||||
grammarBuilder.append("@members {var i int = 0; var _ int = i; }\n");
|
||||
grammarBuilder.append("s : a[2] a[1];\n");
|
||||
grammarBuilder.append("a[int i]\n");
|
||||
grammarBuilder.append(" : {$i==1}? ID {fmt.Println(\"alt 1\")}\n");
|
||||
grammarBuilder.append(" | {$i==2}? ID {fmt.Println(\"alt 2\")}\n");
|
||||
grammarBuilder.append(" : {$i == 1}? ID {fmt.Println(\"alt 1\")}\n");
|
||||
grammarBuilder.append(" | {$i == 2}? ID {fmt.Println(\"alt 2\")}\n");
|
||||
grammarBuilder.append(" ;\n");
|
||||
grammarBuilder.append("ID : 'a'..'z'+ ;\n");
|
||||
grammarBuilder.append("INT : '0'..'9'+;\n");
|
||||
|
@ -411,8 +398,7 @@ public class TestSemPredEvalParser extends BaseTest {
|
|||
String grammar = grammarBuilder.toString();
|
||||
String input ="a b";
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer",
|
||||
"TListener", "TVisitor",
|
||||
"s", input, false);
|
||||
"TListener", "TVisitor", "s", input, false);
|
||||
assertEquals(
|
||||
"alt 2\n" +
|
||||
"alt 1\n", found);
|
||||
|
@ -423,13 +409,13 @@ public class TestSemPredEvalParser extends BaseTest {
|
|||
@Test
|
||||
public void testPredicateDependentOnArg2() throws Exception {
|
||||
mkdir(parserpkgdir);
|
||||
StringBuilder grammarBuilder = new StringBuilder(174);
|
||||
StringBuilder grammarBuilder = new StringBuilder(178);
|
||||
grammarBuilder.append("grammar T;\n");
|
||||
grammarBuilder.append("@members {var i int = 0; var _ int = i; }\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");
|
||||
|
@ -437,8 +423,7 @@ public class TestSemPredEvalParser extends BaseTest {
|
|||
String grammar = grammarBuilder.toString();
|
||||
String input ="a b";
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer",
|
||||
"TListener", "TVisitor",
|
||||
"s", input, false);
|
||||
"TListener", "TVisitor", "s", input, false);
|
||||
assertEquals("", found);
|
||||
assertNull(this.stderrDuringParse);
|
||||
|
||||
|
@ -447,11 +432,12 @@ public class TestSemPredEvalParser extends BaseTest {
|
|||
@Test
|
||||
public void testPredsInGlobalFOLLOW() throws Exception {
|
||||
mkdir(parserpkgdir);
|
||||
StringBuilder grammarBuilder = new StringBuilder(273);
|
||||
StringBuilder grammarBuilder = new StringBuilder(272);
|
||||
grammarBuilder.append("grammar T;\n");
|
||||
grammarBuilder.append("@members {\n");
|
||||
grammarBuilder.append("func pred(v bool) bool {\n");
|
||||
grammarBuilder.append(" fmt.Println(\"eval=\"+fmt.Sprint(v))\n");
|
||||
grammarBuilder.append(" fmt.Println(\"eval=\" + fmt.Sprint(v))\n");
|
||||
grammarBuilder.append("\n");
|
||||
grammarBuilder.append(" return v\n");
|
||||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append("}\n");
|
||||
|
@ -464,8 +450,7 @@ public class TestSemPredEvalParser extends BaseTest {
|
|||
String grammar = grammarBuilder.toString();
|
||||
String input ="a!";
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer",
|
||||
"TListener", "TVisitor",
|
||||
"s", input, false);
|
||||
"TListener", "TVisitor", "s", input, false);
|
||||
assertEquals(
|
||||
"eval=true\n" +
|
||||
"parse\n", found);
|
||||
|
@ -488,8 +473,7 @@ public class TestSemPredEvalParser extends BaseTest {
|
|||
String grammar = grammarBuilder.toString();
|
||||
String input ="y 3 x 4";
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer",
|
||||
"TListener", "TVisitor",
|
||||
"s", input, false);
|
||||
"TListener", "TVisitor", "s", input, false);
|
||||
assertEquals(
|
||||
"alt 2\n" +
|
||||
"alt 1\n", found);
|
||||
|
@ -513,8 +497,7 @@ public class TestSemPredEvalParser extends BaseTest {
|
|||
String grammar = grammarBuilder.toString();
|
||||
String input ="x y 3";
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer",
|
||||
"TListener", "TVisitor",
|
||||
"s", input, false);
|
||||
"TListener", "TVisitor", "s", input, false);
|
||||
assertEquals(
|
||||
"alt 2\n" +
|
||||
"alt 2\n" +
|
||||
|
@ -538,8 +521,7 @@ public class TestSemPredEvalParser extends BaseTest {
|
|||
String grammar = grammarBuilder.toString();
|
||||
String input ="x";
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer",
|
||||
"TListener", "TVisitor",
|
||||
"s", input, false);
|
||||
"TListener", "TVisitor", "s", input, false);
|
||||
assertEquals("", found);
|
||||
|
||||
assertEquals("line 1:0 no viable alternative at input 'x'\n", this.stderrDuringParse);
|
||||
|
@ -561,8 +543,7 @@ public class TestSemPredEvalParser extends BaseTest {
|
|||
String grammar = grammarBuilder.toString();
|
||||
String input ="3 4 x";
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer",
|
||||
"TListener", "TVisitor",
|
||||
"s", input, false);
|
||||
"TListener", "TVisitor", "s", input, false);
|
||||
assertEquals(
|
||||
"alt 2\n" +
|
||||
"alt 2\n", found);
|
||||
|
@ -586,8 +567,7 @@ public class TestSemPredEvalParser extends BaseTest {
|
|||
String grammar = grammarBuilder.toString();
|
||||
String input ="x x y";
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer",
|
||||
"TListener", "TVisitor",
|
||||
"s", input, false);
|
||||
"TListener", "TVisitor", "s", input, false);
|
||||
assertEquals(
|
||||
"alt 2\n" +
|
||||
"alt 2\n" +
|
||||
|
@ -613,8 +593,7 @@ public class TestSemPredEvalParser extends BaseTest {
|
|||
String grammar = grammarBuilder.toString();
|
||||
String input ="x x y";
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer",
|
||||
"TListener", "TVisitor",
|
||||
"s", input, false);
|
||||
"TListener", "TVisitor", "s", input, false);
|
||||
assertEquals(
|
||||
"i=1\n" +
|
||||
"alt 2\n" +
|
||||
|
@ -645,8 +624,7 @@ public class TestSemPredEvalParser extends BaseTest {
|
|||
String grammar = grammarBuilder.toString();
|
||||
String input ="x 4";
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer",
|
||||
"TListener", "TVisitor",
|
||||
"s", input, false);
|
||||
"TListener", "TVisitor", "s", input, false);
|
||||
assertEquals("alt 1\n", found);
|
||||
assertNull(this.stderrDuringParse);
|
||||
|
||||
|
@ -670,8 +648,7 @@ public class TestSemPredEvalParser extends BaseTest {
|
|||
String grammar = grammarBuilder.toString();
|
||||
String input ="x ; y";
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer",
|
||||
"TListener", "TVisitor",
|
||||
"s", input, false);
|
||||
"TListener", "TVisitor", "s", input, false);
|
||||
assertEquals("", found);
|
||||
|
||||
assertEquals(
|
||||
|
|
|
@ -20,8 +20,7 @@ public class TestSets extends BaseTest {
|
|||
String grammar = grammarBuilder.toString();
|
||||
String input ="A a B b";
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer",
|
||||
"TListener", "TVisitor",
|
||||
"a", input, false);
|
||||
"TListener", "TVisitor", "a", input, false);
|
||||
assertEquals(
|
||||
"A\n" +
|
||||
"a\n" +
|
||||
|
@ -41,8 +40,7 @@ public class TestSets extends BaseTest {
|
|||
String grammar = grammarBuilder.toString();
|
||||
String input ="a";
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer",
|
||||
"TListener", "TVisitor",
|
||||
"parse", input, false);
|
||||
"TListener", "TVisitor", "parse", input, false);
|
||||
assertEquals("", found);
|
||||
|
||||
assertEquals(
|
||||
|
@ -61,8 +59,7 @@ public class TestSets extends BaseTest {
|
|||
String grammar = grammarBuilder.toString();
|
||||
String input ="ac";
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer",
|
||||
"TListener", "TVisitor",
|
||||
"a", input, false);
|
||||
"TListener", "TVisitor", "a", input, false);
|
||||
assertEquals("ac\n", found);
|
||||
assertNull(this.stderrDuringParse);
|
||||
|
||||
|
@ -78,8 +75,7 @@ public class TestSets extends BaseTest {
|
|||
String grammar = grammarBuilder.toString();
|
||||
String input ="abaac";
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer",
|
||||
"TListener", "TVisitor",
|
||||
"a", input, false);
|
||||
"TListener", "TVisitor", "a", input, false);
|
||||
assertEquals("abaac\n", found);
|
||||
assertNull(this.stderrDuringParse);
|
||||
|
||||
|
@ -95,8 +91,7 @@ public class TestSets extends BaseTest {
|
|||
String grammar = grammarBuilder.toString();
|
||||
String input ="abaac";
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer",
|
||||
"TListener", "TVisitor",
|
||||
"a", input, false);
|
||||
"TListener", "TVisitor", "a", input, false);
|
||||
assertEquals("abaac\n", found);
|
||||
assertNull(this.stderrDuringParse);
|
||||
|
||||
|
@ -112,8 +107,7 @@ public class TestSets extends BaseTest {
|
|||
String grammar = grammarBuilder.toString();
|
||||
String input ="x";
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer",
|
||||
"TListener", "TVisitor",
|
||||
"a", input, false);
|
||||
"TListener", "TVisitor", "a", input, false);
|
||||
assertEquals("x\n", found);
|
||||
assertNull(this.stderrDuringParse);
|
||||
|
||||
|
@ -129,8 +123,7 @@ public class TestSets extends BaseTest {
|
|||
String grammar = grammarBuilder.toString();
|
||||
String input ="x";
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer",
|
||||
"TListener", "TVisitor",
|
||||
"a", input, false);
|
||||
"TListener", "TVisitor", "a", input, false);
|
||||
assertEquals("x\n", found);
|
||||
assertNull(this.stderrDuringParse);
|
||||
|
||||
|
@ -146,8 +139,7 @@ public class TestSets extends BaseTest {
|
|||
String grammar = grammarBuilder.toString();
|
||||
String input ="x";
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer",
|
||||
"TListener", "TVisitor",
|
||||
"a", input, false);
|
||||
"TListener", "TVisitor", "a", input, false);
|
||||
assertEquals("x\n", found);
|
||||
assertNull(this.stderrDuringParse);
|
||||
|
||||
|
@ -165,8 +157,7 @@ public class TestSets extends BaseTest {
|
|||
String grammar = grammarBuilder.toString();
|
||||
String input ="x";
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer",
|
||||
"TListener", "TVisitor",
|
||||
"a", input, false);
|
||||
"TListener", "TVisitor", "a", input, false);
|
||||
assertEquals("x\n", found);
|
||||
assertNull(this.stderrDuringParse);
|
||||
|
||||
|
@ -182,8 +173,7 @@ public class TestSets extends BaseTest {
|
|||
String grammar = grammarBuilder.toString();
|
||||
String input ="bc";
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer",
|
||||
"TListener", "TVisitor",
|
||||
"a", input, false);
|
||||
"TListener", "TVisitor", "a", input, false);
|
||||
assertEquals("bc\n", found);
|
||||
assertNull(this.stderrDuringParse);
|
||||
|
||||
|
@ -198,8 +188,7 @@ public class TestSets extends BaseTest {
|
|||
String grammar = grammarBuilder.toString();
|
||||
String input ="ac";
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer",
|
||||
"TListener", "TVisitor",
|
||||
"a", input, false);
|
||||
"TListener", "TVisitor", "a", input, false);
|
||||
assertEquals("ac\n", found);
|
||||
assertNull(this.stderrDuringParse);
|
||||
|
||||
|
@ -215,8 +204,7 @@ public class TestSets extends BaseTest {
|
|||
String grammar = grammarBuilder.toString();
|
||||
String input ="bc";
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer",
|
||||
"TListener", "TVisitor",
|
||||
"a", input, false);
|
||||
"TListener", "TVisitor", "a", input, false);
|
||||
assertEquals("bc\n", found);
|
||||
assertNull(this.stderrDuringParse);
|
||||
|
||||
|
@ -231,8 +219,7 @@ public class TestSets extends BaseTest {
|
|||
String grammar = grammarBuilder.toString();
|
||||
String input ="zz";
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer",
|
||||
"TListener", "TVisitor",
|
||||
"a", input, false);
|
||||
"TListener", "TVisitor", "a", input, false);
|
||||
assertEquals("z\n", found);
|
||||
assertNull(this.stderrDuringParse);
|
||||
|
||||
|
@ -247,8 +234,7 @@ public class TestSets extends BaseTest {
|
|||
String grammar = grammarBuilder.toString();
|
||||
String input ="zz";
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer",
|
||||
"TListener", "TVisitor",
|
||||
"a", input, false);
|
||||
"TListener", "TVisitor", "a", input, false);
|
||||
assertEquals("zz\n", found);
|
||||
assertNull(this.stderrDuringParse);
|
||||
|
||||
|
@ -263,8 +249,7 @@ public class TestSets extends BaseTest {
|
|||
String grammar = grammarBuilder.toString();
|
||||
String input ="zz";
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer",
|
||||
"TListener", "TVisitor",
|
||||
"a", input, false);
|
||||
"TListener", "TVisitor", "a", input, false);
|
||||
assertEquals("z\n", found);
|
||||
assertNull(this.stderrDuringParse);
|
||||
|
||||
|
@ -279,8 +264,7 @@ public class TestSets extends BaseTest {
|
|||
String grammar = grammarBuilder.toString();
|
||||
String input ="x";
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer",
|
||||
"TListener", "TVisitor",
|
||||
"a", input, false);
|
||||
"TListener", "TVisitor", "a", input, false);
|
||||
assertEquals("x\n", found);
|
||||
assertNull(this.stderrDuringParse);
|
||||
|
||||
|
@ -296,8 +280,7 @@ public class TestSets extends BaseTest {
|
|||
String grammar = grammarBuilder.toString();
|
||||
String input ="bbbbc";
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer",
|
||||
"TListener", "TVisitor",
|
||||
"a", input, false);
|
||||
"TListener", "TVisitor", "a", input, false);
|
||||
assertEquals("bbbbc\n", found);
|
||||
assertNull(this.stderrDuringParse);
|
||||
|
||||
|
@ -312,8 +295,7 @@ public class TestSets extends BaseTest {
|
|||
String grammar = grammarBuilder.toString();
|
||||
String input ="abaac";
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer",
|
||||
"TListener", "TVisitor",
|
||||
"a", input, false);
|
||||
"TListener", "TVisitor", "a", input, false);
|
||||
assertEquals("abaac\n", found);
|
||||
assertNull(this.stderrDuringParse);
|
||||
|
||||
|
@ -328,8 +310,7 @@ public class TestSets extends BaseTest {
|
|||
String grammar = grammarBuilder.toString();
|
||||
String input ="b";
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer",
|
||||
"TListener", "TVisitor",
|
||||
"a", input, false);
|
||||
"TListener", "TVisitor", "a", input, false);
|
||||
assertEquals("b\n", found);
|
||||
assertNull(this.stderrDuringParse);
|
||||
|
||||
|
@ -347,8 +328,7 @@ public class TestSets extends BaseTest {
|
|||
String grammar = grammarBuilder.toString();
|
||||
String input ="34";
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer",
|
||||
"TListener", "TVisitor",
|
||||
"a", input, false);
|
||||
"TListener", "TVisitor", "a", input, false);
|
||||
assertEquals("34\n", found);
|
||||
assertNull(this.stderrDuringParse);
|
||||
|
||||
|
@ -364,8 +344,7 @@ public class TestSets extends BaseTest {
|
|||
String grammar = grammarBuilder.toString();
|
||||
String input ="bbbbc";
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer",
|
||||
"TListener", "TVisitor",
|
||||
"a", input, false);
|
||||
"TListener", "TVisitor", "a", input, false);
|
||||
assertEquals("bbbbc\n", found);
|
||||
assertNull(this.stderrDuringParse);
|
||||
|
||||
|
@ -381,8 +360,7 @@ public class TestSets extends BaseTest {
|
|||
String grammar = grammarBuilder.toString();
|
||||
String input ="c";
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer",
|
||||
"TListener", "TVisitor",
|
||||
"a", input, false);
|
||||
"TListener", "TVisitor", "a", input, false);
|
||||
assertEquals("c\n", found);
|
||||
assertNull(this.stderrDuringParse);
|
||||
|
||||
|
@ -397,8 +375,7 @@ public class TestSets extends BaseTest {
|
|||
String grammar = grammarBuilder.toString();
|
||||
String input ="abaac";
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer",
|
||||
"TListener", "TVisitor",
|
||||
"a", input, false);
|
||||
"TListener", "TVisitor", "a", input, false);
|
||||
assertEquals("abaac\n", found);
|
||||
assertNull(this.stderrDuringParse);
|
||||
|
||||
|
|
|
@ -72,18 +72,18 @@ public class TestCompositeParsers extends BaseTest {
|
|||
public void testDelegatesSeeSameTokenType() throws Exception {
|
||||
mkdir(tmpdir);
|
||||
|
||||
String slave_T =
|
||||
"parser grammar T;\n" +
|
||||
"tokens { C, B, A } // reverse order\n" +
|
||||
"y : A {System.out.println(\"T.y\");};";
|
||||
writeFile(tmpdir, "T.g4", slave_T);
|
||||
|
||||
String slave_S =
|
||||
"parser grammar S;\n" +
|
||||
"tokens { A, B, C }\n" +
|
||||
"x : A {System.out.println(\"S.x\");};";
|
||||
writeFile(tmpdir, "S.g4", slave_S);
|
||||
|
||||
String slave_T =
|
||||
"parser grammar T;\n" +
|
||||
"tokens { C, B, A } // reverse order\n" +
|
||||
"y : A {System.out.println(\"T.y\");};";
|
||||
writeFile(tmpdir, "T.g4", slave_T);
|
||||
|
||||
StringBuilder grammarBuilder = new StringBuilder(598);
|
||||
grammarBuilder.append("// The lexer will create rules to match letters a, b, c.\n");
|
||||
grammarBuilder.append("// The associated token types A, B, C must have the same value\n");
|
||||
|
@ -236,17 +236,17 @@ public class TestCompositeParsers extends BaseTest {
|
|||
public void testDelegatorInvokesFirstVersionOfDelegateRule() throws Exception {
|
||||
mkdir(tmpdir);
|
||||
|
||||
String slave_T =
|
||||
"parser grammar T;\n" +
|
||||
"a : B {System.out.println(\"T.a\");};";
|
||||
writeFile(tmpdir, "T.g4", slave_T);
|
||||
|
||||
String slave_S =
|
||||
"parser grammar S;\n" +
|
||||
"a : b {System.out.println(\"S.a\");};\n" +
|
||||
"b : B;";
|
||||
writeFile(tmpdir, "S.g4", slave_S);
|
||||
|
||||
String slave_T =
|
||||
"parser grammar T;\n" +
|
||||
"a : B {System.out.println(\"T.a\");};";
|
||||
writeFile(tmpdir, "T.g4", slave_T);
|
||||
|
||||
StringBuilder grammarBuilder = new StringBuilder(106);
|
||||
grammarBuilder.append("grammar M;\n");
|
||||
grammarBuilder.append("import S,T;\n");
|
||||
|
@ -294,18 +294,18 @@ public class TestCompositeParsers extends BaseTest {
|
|||
public void testDelegatorRuleOverridesDelegates() throws Exception {
|
||||
mkdir(tmpdir);
|
||||
|
||||
String slave_T =
|
||||
"parser grammar T;\n" +
|
||||
"tokens { A }\n" +
|
||||
"b : 'b' {System.out.println(\"T.b\");};";
|
||||
writeFile(tmpdir, "T.g4", slave_T);
|
||||
|
||||
String slave_S =
|
||||
"parser grammar S;\n" +
|
||||
"a : b {System.out.println(\"S.a\");};\n" +
|
||||
"b : 'b' ;";
|
||||
writeFile(tmpdir, "S.g4", slave_S);
|
||||
|
||||
String slave_T =
|
||||
"parser grammar T;\n" +
|
||||
"tokens { A }\n" +
|
||||
"b : 'b' {System.out.println(\"T.b\");};";
|
||||
writeFile(tmpdir, "T.g4", slave_T);
|
||||
|
||||
StringBuilder grammarBuilder = new StringBuilder(95);
|
||||
grammarBuilder.append("grammar M;\n");
|
||||
grammarBuilder.append("import S, T;\n");
|
||||
|
|
|
@ -639,14 +639,14 @@ public class TestParserExec extends BaseTest {
|
|||
public void testParserProperty() throws Exception {
|
||||
mkdir(tmpdir);
|
||||
|
||||
StringBuilder grammarBuilder = new StringBuilder(168);
|
||||
StringBuilder grammarBuilder = new StringBuilder(160);
|
||||
grammarBuilder.append("grammar T;\n");
|
||||
grammarBuilder.append("@members {\n");
|
||||
grammarBuilder.append("boolean Property() {\n");
|
||||
grammarBuilder.append(" return true;\n");
|
||||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append("a : {$parser.Property()}? ID {System.out.println(\"valid\");}\n");
|
||||
grammarBuilder.append("a : {Property()}? ID {System.out.println(\"valid\");}\n");
|
||||
grammarBuilder.append(" ;\n");
|
||||
grammarBuilder.append("ID : 'a'..'z'+ ;\n");
|
||||
grammarBuilder.append("WS : (' '|'\\n') -> skip ;");
|
||||
|
|
|
@ -64,18 +64,18 @@ public class TestCompositeParsers extends BaseTest {
|
|||
@Test
|
||||
public void testDelegatesSeeSameTokenType() throws Exception {
|
||||
mkdir(tmpdir);
|
||||
String slave_T =
|
||||
"parser grammar T;\n" +
|
||||
"tokens { C, B, A } // reverse order\n" +
|
||||
"y : A {console.log(\"T.y\");};";
|
||||
writeFile(tmpdir, "T.g4", slave_T);
|
||||
|
||||
String slave_S =
|
||||
"parser grammar S;\n" +
|
||||
"tokens { A, B, C }\n" +
|
||||
"x : A {console.log(\"S.x\");};";
|
||||
writeFile(tmpdir, "S.g4", slave_S);
|
||||
|
||||
String slave_T =
|
||||
"parser grammar T;\n" +
|
||||
"tokens { C, B, A } // reverse order\n" +
|
||||
"y : A {console.log(\"T.y\");};";
|
||||
writeFile(tmpdir, "T.g4", slave_T);
|
||||
|
||||
StringBuilder grammarBuilder = new StringBuilder(598);
|
||||
grammarBuilder.append("// The lexer will create rules to match letters a, b, c.\n");
|
||||
grammarBuilder.append("// The associated token types A, B, C must have the same value\n");
|
||||
|
@ -207,17 +207,17 @@ public class TestCompositeParsers extends BaseTest {
|
|||
@Test
|
||||
public void testDelegatorInvokesFirstVersionOfDelegateRule() throws Exception {
|
||||
mkdir(tmpdir);
|
||||
String slave_T =
|
||||
"parser grammar T;\n" +
|
||||
"a : B {console.log(\"T.a\");};";
|
||||
writeFile(tmpdir, "T.g4", slave_T);
|
||||
|
||||
String slave_S =
|
||||
"parser grammar S;\n" +
|
||||
"a : b {console.log(\"S.a\");};\n" +
|
||||
"b : B;";
|
||||
writeFile(tmpdir, "S.g4", slave_S);
|
||||
|
||||
String slave_T =
|
||||
"parser grammar T;\n" +
|
||||
"a : B {console.log(\"T.a\");};";
|
||||
writeFile(tmpdir, "T.g4", slave_T);
|
||||
|
||||
StringBuilder grammarBuilder = new StringBuilder(106);
|
||||
grammarBuilder.append("grammar M;\n");
|
||||
grammarBuilder.append("import S,T;\n");
|
||||
|
@ -261,18 +261,18 @@ public class TestCompositeParsers extends BaseTest {
|
|||
@Test
|
||||
public void testDelegatorRuleOverridesDelegates() throws Exception {
|
||||
mkdir(tmpdir);
|
||||
String slave_T =
|
||||
"parser grammar T;\n" +
|
||||
"tokens { A }\n" +
|
||||
"b : 'b' {console.log(\"T.b\");};";
|
||||
writeFile(tmpdir, "T.g4", slave_T);
|
||||
|
||||
String slave_S =
|
||||
"parser grammar S;\n" +
|
||||
"a : b {console.log(\"S.a\");};\n" +
|
||||
"b : 'b' ;";
|
||||
writeFile(tmpdir, "S.g4", slave_S);
|
||||
|
||||
String slave_T =
|
||||
"parser grammar T;\n" +
|
||||
"tokens { A }\n" +
|
||||
"b : 'b' {console.log(\"T.b\");};";
|
||||
writeFile(tmpdir, "T.g4", slave_T);
|
||||
|
||||
StringBuilder grammarBuilder = new StringBuilder(88);
|
||||
grammarBuilder.append("grammar M;\n");
|
||||
grammarBuilder.append("import S, T;\n");
|
||||
|
|
|
@ -585,14 +585,14 @@ public class TestParserExec extends BaseTest {
|
|||
@Test
|
||||
public void testParserProperty() throws Exception {
|
||||
mkdir(tmpdir);
|
||||
StringBuilder grammarBuilder = new StringBuilder(171);
|
||||
StringBuilder grammarBuilder = new StringBuilder(163);
|
||||
grammarBuilder.append("grammar T;\n");
|
||||
grammarBuilder.append("@members {\n");
|
||||
grammarBuilder.append("this.Property = function() {\n");
|
||||
grammarBuilder.append(" return true;\n");
|
||||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append("a : {$parser.Property()}? ID {console.log(\"valid\");}\n");
|
||||
grammarBuilder.append("a : {Property()}? ID {console.log(\"valid\");}\n");
|
||||
grammarBuilder.append(" ;\n");
|
||||
grammarBuilder.append("ID : 'a'..'z'+ ;\n");
|
||||
grammarBuilder.append("WS : (' '|'\\n') -> skip ;");
|
||||
|
|
|
@ -75,18 +75,18 @@ public class TestCompositeParsers extends BasePython2Test {
|
|||
public void testDelegatesSeeSameTokenType() throws Exception {
|
||||
mkdir(tmpdir);
|
||||
|
||||
String slave_T =
|
||||
"parser grammar T;\n" +
|
||||
"tokens { C, B, A } // reverse order\n" +
|
||||
"y : A {print(\"T.y\")};";
|
||||
writeFile(tmpdir, "T.g4", slave_T);
|
||||
|
||||
String slave_S =
|
||||
"parser grammar S;\n" +
|
||||
"tokens { A, B, C }\n" +
|
||||
"x : A {print(\"S.x\")};";
|
||||
writeFile(tmpdir, "S.g4", slave_S);
|
||||
|
||||
String slave_T =
|
||||
"parser grammar T;\n" +
|
||||
"tokens { C, B, A } // reverse order\n" +
|
||||
"y : A {print(\"T.y\")};";
|
||||
writeFile(tmpdir, "T.g4", slave_T);
|
||||
|
||||
StringBuilder grammarBuilder = new StringBuilder(598);
|
||||
grammarBuilder.append("// The lexer will create rules to match letters a, b, c.\n");
|
||||
grammarBuilder.append("// The associated token types A, B, C must have the same value\n");
|
||||
|
@ -245,17 +245,17 @@ public class TestCompositeParsers extends BasePython2Test {
|
|||
public void testDelegatorInvokesFirstVersionOfDelegateRule() throws Exception {
|
||||
mkdir(tmpdir);
|
||||
|
||||
String slave_T =
|
||||
"parser grammar T;\n" +
|
||||
"a : B {print(\"T.a\")};";
|
||||
writeFile(tmpdir, "T.g4", slave_T);
|
||||
|
||||
String slave_S =
|
||||
"parser grammar S;\n" +
|
||||
"a : b {print(\"S.a\")};\n" +
|
||||
"b : B;";
|
||||
writeFile(tmpdir, "S.g4", slave_S);
|
||||
|
||||
String slave_T =
|
||||
"parser grammar T;\n" +
|
||||
"a : B {print(\"T.a\")};";
|
||||
writeFile(tmpdir, "T.g4", slave_T);
|
||||
|
||||
StringBuilder grammarBuilder = new StringBuilder(106);
|
||||
grammarBuilder.append("grammar M;\n");
|
||||
grammarBuilder.append("import S,T;\n");
|
||||
|
@ -305,18 +305,18 @@ public class TestCompositeParsers extends BasePython2Test {
|
|||
public void testDelegatorRuleOverridesDelegates() throws Exception {
|
||||
mkdir(tmpdir);
|
||||
|
||||
String slave_T =
|
||||
"parser grammar T;\n" +
|
||||
"tokens { A }\n" +
|
||||
"b : 'b' {print(\"T.b\")};";
|
||||
writeFile(tmpdir, "T.g4", slave_T);
|
||||
|
||||
String slave_S =
|
||||
"parser grammar S;\n" +
|
||||
"a : b {print(\"S.a\")};\n" +
|
||||
"b : 'b' ;";
|
||||
writeFile(tmpdir, "S.g4", slave_S);
|
||||
|
||||
String slave_T =
|
||||
"parser grammar T;\n" +
|
||||
"tokens { A }\n" +
|
||||
"b : 'b' {print(\"T.b\")};";
|
||||
writeFile(tmpdir, "T.g4", slave_T);
|
||||
|
||||
StringBuilder grammarBuilder = new StringBuilder(81);
|
||||
grammarBuilder.append("grammar M;\n");
|
||||
grammarBuilder.append("import S, T;\n");
|
||||
|
|
|
@ -666,14 +666,14 @@ public class TestParserExec extends BasePython2Test {
|
|||
public void testParserProperty() throws Exception {
|
||||
mkdir(tmpdir);
|
||||
|
||||
StringBuilder grammarBuilder = new StringBuilder(153);
|
||||
StringBuilder grammarBuilder = new StringBuilder(145);
|
||||
grammarBuilder.append("grammar T;\n");
|
||||
grammarBuilder.append("@members {\n");
|
||||
grammarBuilder.append("def Property(self):\n");
|
||||
grammarBuilder.append(" return True\n");
|
||||
grammarBuilder.append("\n");
|
||||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append("a : {$parser.Property()}? ID {print(\"valid\")}\n");
|
||||
grammarBuilder.append("a : {Property()}? ID {print(\"valid\")}\n");
|
||||
grammarBuilder.append(" ;\n");
|
||||
grammarBuilder.append("ID : 'a'..'z'+ ;\n");
|
||||
grammarBuilder.append("WS : (' '|'\\n') -> skip ;");
|
||||
|
|
|
@ -75,18 +75,18 @@ public class TestCompositeParsers extends BasePython3Test {
|
|||
public void testDelegatesSeeSameTokenType() throws Exception {
|
||||
mkdir(tmpdir);
|
||||
|
||||
String slave_T =
|
||||
"parser grammar T;\n" +
|
||||
"tokens { C, B, A } // reverse order\n" +
|
||||
"y : A {print(\"T.y\")};";
|
||||
writeFile(tmpdir, "T.g4", slave_T);
|
||||
|
||||
String slave_S =
|
||||
"parser grammar S;\n" +
|
||||
"tokens { A, B, C }\n" +
|
||||
"x : A {print(\"S.x\")};";
|
||||
writeFile(tmpdir, "S.g4", slave_S);
|
||||
|
||||
String slave_T =
|
||||
"parser grammar T;\n" +
|
||||
"tokens { C, B, A } // reverse order\n" +
|
||||
"y : A {print(\"T.y\")};";
|
||||
writeFile(tmpdir, "T.g4", slave_T);
|
||||
|
||||
StringBuilder grammarBuilder = new StringBuilder(598);
|
||||
grammarBuilder.append("// The lexer will create rules to match letters a, b, c.\n");
|
||||
grammarBuilder.append("// The associated token types A, B, C must have the same value\n");
|
||||
|
@ -245,17 +245,17 @@ public class TestCompositeParsers extends BasePython3Test {
|
|||
public void testDelegatorInvokesFirstVersionOfDelegateRule() throws Exception {
|
||||
mkdir(tmpdir);
|
||||
|
||||
String slave_T =
|
||||
"parser grammar T;\n" +
|
||||
"a : B {print(\"T.a\")};";
|
||||
writeFile(tmpdir, "T.g4", slave_T);
|
||||
|
||||
String slave_S =
|
||||
"parser grammar S;\n" +
|
||||
"a : b {print(\"S.a\")};\n" +
|
||||
"b : B;";
|
||||
writeFile(tmpdir, "S.g4", slave_S);
|
||||
|
||||
String slave_T =
|
||||
"parser grammar T;\n" +
|
||||
"a : B {print(\"T.a\")};";
|
||||
writeFile(tmpdir, "T.g4", slave_T);
|
||||
|
||||
StringBuilder grammarBuilder = new StringBuilder(106);
|
||||
grammarBuilder.append("grammar M;\n");
|
||||
grammarBuilder.append("import S,T;\n");
|
||||
|
@ -305,18 +305,18 @@ public class TestCompositeParsers extends BasePython3Test {
|
|||
public void testDelegatorRuleOverridesDelegates() throws Exception {
|
||||
mkdir(tmpdir);
|
||||
|
||||
String slave_T =
|
||||
"parser grammar T;\n" +
|
||||
"tokens { A }\n" +
|
||||
"b : 'b' {print(\"T.b\")};";
|
||||
writeFile(tmpdir, "T.g4", slave_T);
|
||||
|
||||
String slave_S =
|
||||
"parser grammar S;\n" +
|
||||
"a : b {print(\"S.a\")};\n" +
|
||||
"b : 'b' ;";
|
||||
writeFile(tmpdir, "S.g4", slave_S);
|
||||
|
||||
String slave_T =
|
||||
"parser grammar T;\n" +
|
||||
"tokens { A }\n" +
|
||||
"b : 'b' {print(\"T.b\")};";
|
||||
writeFile(tmpdir, "T.g4", slave_T);
|
||||
|
||||
StringBuilder grammarBuilder = new StringBuilder(81);
|
||||
grammarBuilder.append("grammar M;\n");
|
||||
grammarBuilder.append("import S, T;\n");
|
||||
|
|
|
@ -666,14 +666,14 @@ public class TestParserExec extends BasePython3Test {
|
|||
public void testParserProperty() throws Exception {
|
||||
mkdir(tmpdir);
|
||||
|
||||
StringBuilder grammarBuilder = new StringBuilder(153);
|
||||
StringBuilder grammarBuilder = new StringBuilder(145);
|
||||
grammarBuilder.append("grammar T;\n");
|
||||
grammarBuilder.append("@members {\n");
|
||||
grammarBuilder.append("def Property(self):\n");
|
||||
grammarBuilder.append(" return True\n");
|
||||
grammarBuilder.append("\n");
|
||||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append("a : {$parser.Property()}? ID {print(\"valid\")}\n");
|
||||
grammarBuilder.append("a : {Property()}? ID {print(\"valid\")}\n");
|
||||
grammarBuilder.append(" ;\n");
|
||||
grammarBuilder.append("ID : 'a'..'z'+ ;\n");
|
||||
grammarBuilder.append("WS : (' '|'\\n') -> skip ;");
|
||||
|
|
Loading…
Reference in New Issue