Updated unit tests to use .g4 as the preferred grammar extension

This commit is contained in:
Sam Harwell 2012-03-30 11:44:34 -05:00
parent e5d7c27b09
commit f166df7b94
22 changed files with 374 additions and 374 deletions

View File

@ -649,9 +649,9 @@ public abstract class BaseTest {
int semi = line.lastIndexOf(';'); int semi = line.lastIndexOf(';');
if ( grIndex>=0 && semi>=0 ) { if ( grIndex>=0 && semi>=0 ) {
int space = line.indexOf(' ', grIndex); int space = line.indexOf(' ', grIndex);
fileName = line.substring(space+1, semi)+".g"; fileName = line.substring(space+1, semi)+Tool.GRAMMAR_EXTENSION;
} }
if ( fileName.length()==".g".length() ) fileName = "<string>"; if ( fileName.length()==Tool.GRAMMAR_EXTENSION.length() ) fileName = "<string>";
return fileName; return fileName;
} }

View File

@ -24,8 +24,8 @@ public class TestAttributeChecks extends BaseTest {
"d : ;\n"; "d : ;\n";
String[] membersChecks = { String[] membersChecks = {
"$a", "error(29): A.g:2:11: unknown attribute reference a in $a\n", "$a", "error(29): A.g4:2:11: unknown attribute reference a in $a\n",
"$a.y", "error(29): A.g:2:11: unknown attribute reference a in $a.y\n", "$a.y", "error(29): A.g4:2:11: unknown attribute reference a in $a.y\n",
}; };
String[] initChecks = { String[] initChecks = {
@ -36,8 +36,8 @@ public class TestAttributeChecks extends BaseTest {
"$lab.e", "", "$lab.e", "",
"$ids", "", "$ids", "",
"$c", "error(29): A.g:4:8: unknown attribute reference c in $c\n", "$c", "error(29): A.g4:4:8: unknown attribute reference c in $c\n",
"$a.q", "error(31): A.g:4:10: unknown attribute q for rule a in $a.q\n", "$a.q", "error(31): A.g4:4:10: unknown attribute q for rule a in $a.q\n",
}; };
String[] inlineChecks = { String[] inlineChecks = {
@ -58,19 +58,19 @@ public class TestAttributeChecks extends BaseTest {
}; };
String[] bad_inlineChecks = { String[] bad_inlineChecks = {
"$lab", "error(33): A.g:6:4: missing attribute access on rule reference lab in $lab\n", "$lab", "error(33): A.g4:6:4: missing attribute access on rule reference lab in $lab\n",
"$q", "error(29): A.g:6:4: unknown attribute reference q in $q\n", "$q", "error(29): A.g4:6:4: unknown attribute reference q in $q\n",
"$q.y", "error(29): A.g:6:4: unknown attribute reference q in $q.y\n", "$q.y", "error(29): A.g4:6:4: unknown attribute reference q in $q.y\n",
"$q = 3", "error(29): A.g:6:4: unknown attribute reference q in $q\n", "$q = 3", "error(29): A.g4:6:4: unknown attribute reference q in $q\n",
"$q = 3;", "error(29): A.g:6:4: unknown attribute reference q in $q = 3;\n", "$q = 3;", "error(29): A.g4:6:4: unknown attribute reference q in $q = 3;\n",
"$q.y = 3;", "error(29): A.g:6:4: unknown attribute reference q in $q.y = 3;\n", "$q.y = 3;", "error(29): A.g4:6:4: unknown attribute reference q in $q.y = 3;\n",
"$q = $blort;", "error(29): A.g:6:4: unknown attribute reference q in $q = $blort;\n" + "$q = $blort;", "error(29): A.g4:6:4: unknown attribute reference q in $q = $blort;\n" +
"error(29): A.g:6:9: unknown attribute reference blort in $blort\n", "error(29): A.g4:6:9: unknown attribute reference blort in $blort\n",
"$a.ick", "error(31): A.g:6:6: unknown attribute ick for rule a in $a.ick\n", "$a.ick", "error(31): A.g4:6:6: unknown attribute ick for rule a in $a.ick\n",
"$a.ick = 3;", "error(31): A.g:6:6: unknown attribute ick for rule a in $a.ick = 3;\n", "$a.ick = 3;", "error(31): A.g4:6:6: unknown attribute ick for rule a in $a.ick = 3;\n",
"$b.d", "error(30): A.g:6:6: cannot access rule d's parameter: $b.d\n", // can't see rule ref's arg "$b.d", "error(30): A.g4:6:6: cannot access rule d's parameter: $b.d\n", // can't see rule ref's arg
"$d.text", "error(29): A.g:6:4: unknown attribute reference d in $d.text\n", // valid rule, but no ref "$d.text", "error(29): A.g4:6:4: unknown attribute reference d in $d.text\n", // valid rule, but no ref
"$lab.d", "error(30): A.g:6:8: cannot access rule d's parameter: $lab.d\n", "$lab.d", "error(30): A.g4:6:8: cannot access rule d's parameter: $lab.d\n",
}; };
String[] finallyChecks = { String[] finallyChecks = {
@ -84,20 +84,20 @@ public class TestAttributeChecks extends BaseTest {
"$id.text", "", "$id.text", "",
"$ids", "", "$ids", "",
"$lab", "error(33): A.g:9:14: missing attribute access on rule reference lab in $lab\n", "$lab", "error(33): A.g4:9:14: missing attribute access on rule reference lab in $lab\n",
"$q", "error(29): A.g:9:14: unknown attribute reference q in $q\n", "$q", "error(29): A.g4:9:14: unknown attribute reference q in $q\n",
"$q.y", "error(29): A.g:9:14: unknown attribute reference q in $q.y\n", "$q.y", "error(29): A.g4:9:14: unknown attribute reference q in $q.y\n",
"$q = 3", "error(29): A.g:9:14: unknown attribute reference q in $q\n", "$q = 3", "error(29): A.g4:9:14: unknown attribute reference q in $q\n",
"$q = 3;", "error(29): A.g:9:14: unknown attribute reference q in $q = 3;\n", "$q = 3;", "error(29): A.g4:9:14: unknown attribute reference q in $q = 3;\n",
"$q.y = 3;", "error(29): A.g:9:14: unknown attribute reference q in $q.y = 3;\n", "$q.y = 3;", "error(29): A.g4:9:14: unknown attribute reference q in $q.y = 3;\n",
"$q = $blort;", "error(29): A.g:9:14: unknown attribute reference q in $q = $blort;\n" + "$q = $blort;", "error(29): A.g4:9:14: unknown attribute reference q in $q = $blort;\n" +
"error(29): A.g:9:19: unknown attribute reference blort in $blort\n", "error(29): A.g4:9:19: unknown attribute reference blort in $blort\n",
"$a.ick", "error(31): A.g:9:16: unknown attribute ick for rule a in $a.ick\n", "$a.ick", "error(31): A.g4:9:16: unknown attribute ick for rule a in $a.ick\n",
"$a.ick = 3;", "error(31): A.g:9:16: unknown attribute ick for rule a in $a.ick = 3;\n", "$a.ick = 3;", "error(31): A.g4:9:16: unknown attribute ick for rule a in $a.ick = 3;\n",
"$b.e", "error(29): A.g:9:14: unknown attribute reference b in $b.e\n", // can't see rule refs outside alts "$b.e", "error(29): A.g4:9:14: unknown attribute reference b in $b.e\n", // can't see rule refs outside alts
"$b.d", "error(29): A.g:9:14: unknown attribute reference b in $b.d\n", "$b.d", "error(29): A.g4:9:14: unknown attribute reference b in $b.d\n",
"$c.text", "error(29): A.g:9:14: unknown attribute reference c in $c.text\n", "$c.text", "error(29): A.g4:9:14: unknown attribute reference c in $c.text\n",
"$lab.d", "error(30): A.g:9:18: cannot access rule d's parameter: $lab.d\n", "$lab.d", "error(30): A.g4:9:18: cannot access rule d's parameter: $lab.d\n",
}; };
String[] dynMembersChecks = { String[] dynMembersChecks = {
@ -105,11 +105,11 @@ public class TestAttributeChecks extends BaseTest {
"$S::i", "", "$S::i", "",
"$S::i=$S::i", "", "$S::i=$S::i", "",
"$b::f", "error(54): A.g:3:1: unknown dynamic scope: b in $b::f\n", "$b::f", "error(54): A.g4:3:1: unknown dynamic scope: b in $b::f\n",
"$S::j", "error(55): A.g:3:4: unknown dynamically-scoped attribute for scope S: j in $S::j\n", "$S::j", "error(55): A.g4:3:4: unknown dynamically-scoped attribute for scope S: j in $S::j\n",
"$S::j = 3;", "error(55): A.g:3:4: unknown dynamically-scoped attribute for scope S: j in $S::j = 3;\n", "$S::j = 3;", "error(55): A.g4:3:4: unknown dynamically-scoped attribute for scope S: j in $S::j = 3;\n",
"$S::j = $S::k;", "error(55): A.g:3:4: unknown dynamically-scoped attribute for scope S: j in $S::j = $S::k;\n" + "$S::j = $S::k;", "error(55): A.g4:3:4: unknown dynamically-scoped attribute for scope S: j in $S::j = $S::k;\n" +
"error(55): A.g:3:12: unknown dynamically-scoped attribute for scope S: k in $S::k\n", "error(55): A.g4:3:12: unknown dynamically-scoped attribute for scope S: k in $S::k\n",
}; };
String[] dynInitChecks = { String[] dynInitChecks = {
@ -122,10 +122,10 @@ public class TestAttributeChecks extends BaseTest {
"$a::z", "", "$a::z", "",
"$S", "", "$S", "",
"$S::j", "error(55): A.g:8:11: unknown dynamically-scoped attribute for scope S: j in $S::j\n", "$S::j", "error(55): A.g4:8:11: unknown dynamically-scoped attribute for scope S: j in $S::j\n",
"$S::j = 3;", "error(55): A.g:8:11: unknown dynamically-scoped attribute for scope S: j in $S::j = 3;\n", "$S::j = 3;", "error(55): A.g4:8:11: unknown dynamically-scoped attribute for scope S: j in $S::j = 3;\n",
"$S::j = $S::k;", "error(55): A.g:8:11: unknown dynamically-scoped attribute for scope S: j in $S::j = $S::k;\n" + "$S::j = $S::k;", "error(55): A.g4:8:11: unknown dynamically-scoped attribute for scope S: j in $S::j = $S::k;\n" +
"error(55): A.g:8:19: unknown dynamically-scoped attribute for scope S: k in $S::k\n", "error(55): A.g4:8:19: unknown dynamically-scoped attribute for scope S: k in $S::k\n",
}; };
String[] dynInlineChecks = { String[] dynInlineChecks = {
@ -138,27 +138,27 @@ public class TestAttributeChecks extends BaseTest {
"$S::i=$S::i", "", "$S::i=$S::i", "",
"$a::z", "", "$a::z", "",
"$S::j", "error(55): A.g:10:7: unknown dynamically-scoped attribute for scope S: j in $S::j\n", "$S::j", "error(55): A.g4:10:7: unknown dynamically-scoped attribute for scope S: j in $S::j\n",
"$S::j = 3;", "error(55): A.g:10:7: unknown dynamically-scoped attribute for scope S: j in $S::j = 3;\n", "$S::j = 3;", "error(55): A.g4:10:7: unknown dynamically-scoped attribute for scope S: j in $S::j = 3;\n",
"$S::j = $S::k;", "error(55): A.g:10:7: unknown dynamically-scoped attribute for scope S: j in $S::j = $S::k;\n" + "$S::j = $S::k;", "error(55): A.g4:10:7: unknown dynamically-scoped attribute for scope S: j in $S::j = $S::k;\n" +
"error(55): A.g:10:15: unknown dynamically-scoped attribute for scope S: k in $S::k\n", "error(55): A.g4:10:15: unknown dynamically-scoped attribute for scope S: k in $S::k\n",
"$Q[-1]::y", "error(54): A.g:10:4: unknown dynamic scope: Q in $Q[-1]::y\n", "$Q[-1]::y", "error(54): A.g4:10:4: unknown dynamic scope: Q in $Q[-1]::y\n",
"$Q[-i]::y", "error(54): A.g:10:4: unknown dynamic scope: Q in $Q[-i]::y\n", "$Q[-i]::y", "error(54): A.g4:10:4: unknown dynamic scope: Q in $Q[-i]::y\n",
"$Q[i]::y", "error(54): A.g:10:4: unknown dynamic scope: Q in $Q[i]::y\n", "$Q[i]::y", "error(54): A.g4:10:4: unknown dynamic scope: Q in $Q[i]::y\n",
"$Q[0]::y", "error(54): A.g:10:4: unknown dynamic scope: Q in $Q[0]::y\n", "$Q[0]::y", "error(54): A.g4:10:4: unknown dynamic scope: Q in $Q[0]::y\n",
"$Q[-1]::y = 23;", "error(54): A.g:10:4: unknown dynamic scope: Q in $Q[-1]::y = 23;\n", "$Q[-1]::y = 23;", "error(54): A.g4:10:4: unknown dynamic scope: Q in $Q[-1]::y = 23;\n",
"$Q[-i]::y = 23;", "error(54): A.g:10:4: unknown dynamic scope: Q in $Q[-i]::y = 23;\n", "$Q[-i]::y = 23;", "error(54): A.g4:10:4: unknown dynamic scope: Q in $Q[-i]::y = 23;\n",
"$Q[i]::y = 23;", "error(54): A.g:10:4: unknown dynamic scope: Q in $Q[i]::y = 23;\n", "$Q[i]::y = 23;", "error(54): A.g4:10:4: unknown dynamic scope: Q in $Q[i]::y = 23;\n",
"$Q[0]::y = 23;", "error(54): A.g:10:4: unknown dynamic scope: Q in $Q[0]::y = 23;\n", "$Q[0]::y = 23;", "error(54): A.g4:10:4: unknown dynamic scope: Q in $Q[0]::y = 23;\n",
"$S[-1]::y", "error(55): A.g:10:11: unknown dynamically-scoped attribute for scope S: y in $S[-1]::y\n", "$S[-1]::y", "error(55): A.g4:10:11: unknown dynamically-scoped attribute for scope S: y in $S[-1]::y\n",
"$S[-i]::y", "error(55): A.g:10:11: unknown dynamically-scoped attribute for scope S: y in $S[-i]::y\n", "$S[-i]::y", "error(55): A.g4:10:11: unknown dynamically-scoped attribute for scope S: y in $S[-i]::y\n",
"$S[i]::y", "error(55): A.g:10:10: unknown dynamically-scoped attribute for scope S: y in $S[i]::y\n", "$S[i]::y", "error(55): A.g4:10:10: unknown dynamically-scoped attribute for scope S: y in $S[i]::y\n",
"$S[0]::y", "error(55): A.g:10:10: unknown dynamically-scoped attribute for scope S: y in $S[0]::y\n", "$S[0]::y", "error(55): A.g4:10:10: unknown dynamically-scoped attribute for scope S: y in $S[0]::y\n",
"$S[-1]::y = 23;", "error(55): A.g:10:11: unknown dynamically-scoped attribute for scope S: y in $S[-1]::y = 23;\n", "$S[-1]::y = 23;", "error(55): A.g4:10:11: unknown dynamically-scoped attribute for scope S: y in $S[-1]::y = 23;\n",
"$S[-i]::y = 23;", "error(55): A.g:10:11: unknown dynamically-scoped attribute for scope S: y in $S[-i]::y = 23;\n", "$S[-i]::y = 23;", "error(55): A.g4:10:11: unknown dynamically-scoped attribute for scope S: y in $S[-i]::y = 23;\n",
"$S[i]::y = 23;", "error(55): A.g:10:10: unknown dynamically-scoped attribute for scope S: y in $S[i]::y = 23;\n", "$S[i]::y = 23;", "error(55): A.g4:10:10: unknown dynamically-scoped attribute for scope S: y in $S[i]::y = 23;\n",
"$S[0]::y = 23;", "error(55): A.g:10:10: unknown dynamically-scoped attribute for scope S: y in $S[0]::y = 23;\n", "$S[0]::y = 23;", "error(55): A.g4:10:10: unknown dynamically-scoped attribute for scope S: y in $S[0]::y = 23;\n",
"$S[$S::y]::i", "error(55): A.g:10:10: unknown dynamically-scoped attribute for scope S: y in $S::y\n" "$S[$S::y]::i", "error(55): A.g4:10:10: unknown dynamically-scoped attribute for scope S: y in $S::y\n"
}; };
String[] dynFinallyChecks = { String[] dynFinallyChecks = {
@ -171,10 +171,10 @@ public class TestAttributeChecks extends BaseTest {
"$S::i=$S::i", "", "$S::i=$S::i", "",
"$a::z", "", "$a::z", "",
"$S::j", "error(55): A.g:12:17: unknown dynamically-scoped attribute for scope S: j in $S::j\n", "$S::j", "error(55): A.g4:12:17: unknown dynamically-scoped attribute for scope S: j in $S::j\n",
"$S::j = 3;", "error(55): A.g:12:17: unknown dynamically-scoped attribute for scope S: j in $S::j = 3;\n", "$S::j = 3;", "error(55): A.g4:12:17: unknown dynamically-scoped attribute for scope S: j in $S::j = 3;\n",
"$S::j = $S::k;", "error(55): A.g:12:17: unknown dynamically-scoped attribute for scope S: j in $S::j = $S::k;\n" + "$S::j = $S::k;", "error(55): A.g4:12:17: unknown dynamically-scoped attribute for scope S: j in $S::j = $S::k;\n" +
"error(55): A.g:12:25: unknown dynamically-scoped attribute for scope S: k in $S::k\n", "error(55): A.g4:12:25: unknown dynamically-scoped attribute for scope S: k in $S::k\n",
}; };
@Test public void testMembersActions() throws RecognitionException { @Test public void testMembersActions() throws RecognitionException {

View File

@ -50,18 +50,18 @@ public class TestBasicSemanticErrors extends BaseTest {
"b : ( options { ick=bar; greedy=true; } : ID )+ ;\n" + "b : ( options { ick=bar; greedy=true; } : ID )+ ;\n" +
"c : ID<blue> ID<x=y> ;", "c : ID<blue> ID<x=y> ;",
// YIELDS // YIELDS
"warning(48): U.g:2:10: illegal option foo\n" + "warning(48): U.g4:2:10: illegal option foo\n" +
"warning(48): U.g:2:19: illegal option k\n" + "warning(48): U.g4:2:19: illegal option k\n" +
"error(26): U.g:4:8: token names must start with an uppercase letter: f\n" + "error(26): U.g4:4:8: token names must start with an uppercase letter: f\n" +
"error(25): U.g:4:8: can't assign string value to token name f in non-combined grammar\n" + "error(25): U.g4:4:8: can't assign string value to token name f in non-combined grammar\n" +
"error(25): U.g:5:8: can't assign string value to token name S in non-combined grammar\n" + "error(25): U.g4:5:8: can't assign string value to token name S in non-combined grammar\n" +
"warning(48): U.g:8:10: illegal option x\n" + "warning(48): U.g4:8:10: illegal option x\n" +
"error(20): U.g:8:0: repeated grammar prequel spec (option, token, or import); please merge\n" + "error(20): U.g4:8:0: repeated grammar prequel spec (option, token, or import); please merge\n" +
"error(20): U.g:7:0: repeated grammar prequel spec (option, token, or import); please merge\n" + "error(20): U.g4:7:0: repeated grammar prequel spec (option, token, or import); please merge\n" +
"warning(48): U.g:11:10: illegal option blech\n" + "warning(48): U.g4:11:10: illegal option blech\n" +
"warning(48): U.g:11:21: illegal option greedy\n" + "warning(48): U.g4:11:21: illegal option greedy\n" +
"warning(48): U.g:14:16: illegal option ick\n" + "warning(48): U.g4:14:16: illegal option ick\n" +
"warning(48): U.g:15:16: illegal option x\n", "warning(48): U.g4:15:16: illegal option x\n",
}; };
@Test public void testU() { super.testErrors(U, false); } @Test public void testU() { super.testErrors(U, false); }

View File

@ -43,7 +43,7 @@ public class TestCompositeGrammars extends BaseTest {
"parser grammar S;\n" + "parser grammar S;\n" +
"a : B . C ;\n"; // not qualified ID "a : B . C ;\n"; // not qualified ID
mkdir(tmpdir); mkdir(tmpdir);
Grammar g = new Grammar(tmpdir + "/S.g", grammar); Grammar g = new Grammar(tmpdir + "/S.g4", grammar);
g.name = "S"; g.name = "S";
ErrorQueue equeue = new ErrorQueue(); ErrorQueue equeue = new ErrorQueue();
@ -61,14 +61,14 @@ public class TestCompositeGrammars extends BaseTest {
"parser grammar S;\n" + "parser grammar S;\n" +
"a : B {System.out.println(\"S.a\");} ;\n"; "a : B {System.out.println(\"S.a\");} ;\n";
mkdir(tmpdir); mkdir(tmpdir);
writeFile(tmpdir, "S.g", slave); writeFile(tmpdir, "S.g4", slave);
String master = String master =
"grammar M;\n" + "grammar M;\n" +
"import S;\n" + "import S;\n" +
"s : a ;\n" + "s : a ;\n" +
"B : 'b' ;" + // defines B from inherited token space "B : 'b' ;" + // defines B from inherited token space
"WS : (' '|'\\n') {skip();} ;\n" ; "WS : (' '|'\\n') {skip();} ;\n" ;
String found = execParser("M.g", master, "MParser", "MLexer", String found = execParser("M.g4", master, "MParser", "MLexer",
"s", "b", debug); "s", "b", debug);
assertEquals("S.a\n", found); assertEquals("S.a\n", found);
} }
@ -78,13 +78,13 @@ public class TestCompositeGrammars extends BaseTest {
"parser grammar S;\n" + "parser grammar S;\n" +
"a : '=' 'a' {System.out.println(\"S.a\");} ;\n"; "a : '=' 'a' {System.out.println(\"S.a\");} ;\n";
mkdir(tmpdir); mkdir(tmpdir);
writeFile(tmpdir, "S.g", slave); writeFile(tmpdir, "S.g4", slave);
String master = String master =
"grammar M;\n" + "grammar M;\n" +
"import S;\n" + "import S;\n" +
"s : a ;\n" + "s : a ;\n" +
"WS : (' '|'\\n') {skip();} ;\n" ; "WS : (' '|'\\n') {skip();} ;\n" ;
String found = execParser("M.g", master, "MParser", "MLexer", String found = execParser("M.g4", master, "MParser", "MLexer",
"s", "=a", debug); "s", "=a", debug);
assertEquals("S.a\n", found); assertEquals("S.a\n", found);
} }
@ -97,14 +97,14 @@ public class TestCompositeGrammars extends BaseTest {
"parser grammar S;\n" + "parser grammar S;\n" +
"a[int x] returns [int y] : B {System.out.print(\"S.a\"); $y=1000;} ;\n"; "a[int x] returns [int y] : B {System.out.print(\"S.a\"); $y=1000;} ;\n";
mkdir(tmpdir); mkdir(tmpdir);
writeFile(tmpdir, "S.g", slave); writeFile(tmpdir, "S.g4", slave);
String master = String master =
"grammar M;\n" + "grammar M;\n" +
"import S;\n" + "import S;\n" +
"s : label=a[3] {System.out.println($label.y);} ;\n" + "s : label=a[3] {System.out.println($label.y);} ;\n" +
"B : 'b' ;" + // defines B from inherited token space "B : 'b' ;" + // defines B from inherited token space
"WS : (' '|'\\n') {skip();} ;\n" ; "WS : (' '|'\\n') {skip();} ;\n" ;
String found = execParser("M.g", master, "MParser", "MLexer", String found = execParser("M.g4", master, "MParser", "MLexer",
"s", "b", debug); "s", "b", debug);
assertEquals("S.a1000\n", found); assertEquals("S.a1000\n", found);
} }
@ -117,14 +117,14 @@ public class TestCompositeGrammars extends BaseTest {
"parser grammar S;\n" + "parser grammar S;\n" +
"a : B {System.out.print(\"S.a\");} ;\n"; "a : B {System.out.print(\"S.a\");} ;\n";
mkdir(tmpdir); mkdir(tmpdir);
writeFile(tmpdir, "S.g", slave); writeFile(tmpdir, "S.g4", slave);
String master = String master =
"grammar M;\n" + "grammar M;\n" +
"import S;\n" + "import S;\n" +
"s : a {System.out.println($a.text);} ;\n" + "s : a {System.out.println($a.text);} ;\n" +
"B : 'b' ;" + // defines B from inherited token space "B : 'b' ;" + // defines B from inherited token space
"WS : (' '|'\\n') {skip();} ;\n" ; "WS : (' '|'\\n') {skip();} ;\n" ;
String found = execParser("M.g", master, "MParser", "MLexer", String found = execParser("M.g4", master, "MParser", "MLexer",
"s", "b", debug); "s", "b", debug);
assertEquals("S.ab\n", found); assertEquals("S.ab\n", found);
} }
@ -137,13 +137,13 @@ public class TestCompositeGrammars extends BaseTest {
"}\n" + "}\n" +
"a : B ;\n"; "a : B ;\n";
mkdir(tmpdir); mkdir(tmpdir);
writeFile(tmpdir, "S.g", slave); writeFile(tmpdir, "S.g4", slave);
String master = String master =
"grammar M;\n" + // uses no rules from the import "grammar M;\n" + // uses no rules from the import
"import S;\n" + "import S;\n" +
"s : 'b' {foo();} ;\n" + // gS is import pointer "s : 'b' {foo();} ;\n" + // gS is import pointer
"WS : (' '|'\\n') {skip();} ;\n" ; "WS : (' '|'\\n') {skip();} ;\n" ;
String found = execParser("M.g", master, "MParser", "MLexer", String found = execParser("M.g4", master, "MParser", "MLexer",
"s", "b", debug); "s", "b", debug);
assertEquals("foo\n", found); assertEquals("foo\n", found);
} }
@ -154,18 +154,18 @@ public class TestCompositeGrammars extends BaseTest {
"a : b {System.out.println(\"S.a\");} ;\n" + "a : b {System.out.println(\"S.a\");} ;\n" +
"b : B ;\n" ; "b : B ;\n" ;
mkdir(tmpdir); mkdir(tmpdir);
writeFile(tmpdir, "S.g", slave); writeFile(tmpdir, "S.g4", slave);
String slave2 = String slave2 =
"parser grammar T;\n" + "parser grammar T;\n" +
"a : B {System.out.println(\"T.a\");} ;\n"; // hidden by S.a "a : B {System.out.println(\"T.a\");} ;\n"; // hidden by S.a
writeFile(tmpdir, "T.g", slave2); writeFile(tmpdir, "T.g4", slave2);
String master = String master =
"grammar M;\n" + "grammar M;\n" +
"import S,T;\n" + "import S,T;\n" +
"s : a ;\n" + "s : a ;\n" +
"B : 'b' ;\n" + "B : 'b' ;\n" +
"WS : (' '|'\\n') {skip();} ;\n" ; "WS : (' '|'\\n') {skip();} ;\n" ;
String found = execParser("M.g", master, "MParser", "MLexer", String found = execParser("M.g4", master, "MParser", "MLexer",
"s", "b", debug); "s", "b", debug);
assertEquals("S.a\n", found); assertEquals("S.a\n", found);
} }
@ -176,13 +176,13 @@ public class TestCompositeGrammars extends BaseTest {
"tokens { A; B; C; }\n" + "tokens { A; B; C; }\n" +
"x : A {System.out.println(\"S.x\");} ;\n"; "x : A {System.out.println(\"S.x\");} ;\n";
mkdir(tmpdir); mkdir(tmpdir);
writeFile(tmpdir, "S.g", slave); writeFile(tmpdir, "S.g4", slave);
String slave2 = String slave2 =
"parser grammar T;\n" + "parser grammar T;\n" +
"tokens { C; B; A; }\n" + // reverse order "tokens { C; B; A; }\n" + // reverse order
"y : A {System.out.println(\"T.y\");} ;\n"; "y : A {System.out.println(\"T.y\");} ;\n";
mkdir(tmpdir); mkdir(tmpdir);
writeFile(tmpdir, "T.g", slave2); writeFile(tmpdir, "T.g4", slave2);
// The lexer will create rules to match letters a, b, c. // The lexer will create rules to match letters a, b, c.
// The associated token types A, B, C must have the same value // The associated token types A, B, C must have the same value
// and all import'd parsers. Since ANTLR regenerates all imports // and all import'd parsers. Since ANTLR regenerates all imports
@ -202,7 +202,7 @@ public class TestCompositeGrammars extends BaseTest {
"A : 'a' ;\n" + "A : 'a' ;\n" +
"C : 'c' ;\n" + "C : 'c' ;\n" +
"WS : (' '|'\\n') {skip();} ;\n" ; "WS : (' '|'\\n') {skip();} ;\n" ;
String found = execParser("M.g", master, "MParser", "MLexer", String found = execParser("M.g4", master, "MParser", "MLexer",
"s", "aa", debug); "s", "aa", debug);
assertEquals("S.x\n" + assertEquals("S.x\n" +
"T.y\n", found); "T.y\n", found);
@ -215,13 +215,13 @@ public class TestCompositeGrammars extends BaseTest {
"tokens { A; B; C; }\n" + "tokens { A; B; C; }\n" +
"x : A {System.out.println(\"S.x\");} ;\n"; "x : A {System.out.println(\"S.x\");} ;\n";
mkdir(tmpdir); mkdir(tmpdir);
writeFile(tmpdir, "S.g", slave); writeFile(tmpdir, "S.g4", slave);
String slave2 = String slave2 =
"parser grammar T;\n" + "parser grammar T;\n" +
"tokens { C; B; A; }\n" + // reverse order "tokens { C; B; A; }\n" + // reverse order
"y : A {System.out.println(\"T.y\");} ;\n"; "y : A {System.out.println(\"T.y\");} ;\n";
mkdir(tmpdir); mkdir(tmpdir);
writeFile(tmpdir, "T.g", slave2); writeFile(tmpdir, "T.g4", slave2);
String master = String master =
"grammar M;\n" + "grammar M;\n" +
@ -231,8 +231,8 @@ public class TestCompositeGrammars extends BaseTest {
"A : 'a' ;\n" + "A : 'a' ;\n" +
"C : 'c' ;\n" + "C : 'c' ;\n" +
"WS : (' '|'\\n') {skip();} ;\n" ; "WS : (' '|'\\n') {skip();} ;\n" ;
writeFile(tmpdir, "M.g", master); writeFile(tmpdir, "M.g4", master);
Grammar g = new Grammar(tmpdir+"/M.g", master, equeue); Grammar g = new Grammar(tmpdir+"/M.g4", master, equeue);
String expectedTokenIDToTypeMap = "{EOF=-1, B=3, A=4, C=5, WS=6}"; String expectedTokenIDToTypeMap = "{EOF=-1, B=3, A=4, C=5, WS=6}";
String expectedStringLiteralToTypeMap = "{'c'=5, 'a'=4, 'b'=3}"; String expectedStringLiteralToTypeMap = "{'c'=5, 'a'=4, 'b'=3}";
@ -244,7 +244,7 @@ public class TestCompositeGrammars extends BaseTest {
assertEquals("unexpected errors: "+equeue, 0, equeue.errors.size()); assertEquals("unexpected errors: "+equeue, 0, equeue.errors.size());
String found = execParser("M.g", master, "MParser", "MLexer", String found = execParser("M.g4", master, "MParser", "MLexer",
"s", "aa", debug); "s", "aa", debug);
assertEquals("S.x\n" + assertEquals("S.x\n" +
"T.y\n", found); "T.y\n", found);
@ -260,18 +260,18 @@ public class TestCompositeGrammars extends BaseTest {
"INT : '0'..'9'+ ;\n" + "INT : '0'..'9'+ ;\n" +
"WS : (' '|'\\n') {skip();} ;\n"; "WS : (' '|'\\n') {skip();} ;\n";
mkdir(tmpdir); mkdir(tmpdir);
writeFile(tmpdir, "S.g", slave); writeFile(tmpdir, "S.g4", slave);
String master = String master =
"grammar M;\n" + "grammar M;\n" +
"import S;\n" + "import S;\n" +
"s : x INT ;\n"; "s : x INT ;\n";
writeFile(tmpdir, "M.g", master); writeFile(tmpdir, "M.g4", master);
Grammar g = new Grammar(tmpdir+"/M.g", master, equeue); Grammar g = new Grammar(tmpdir+"/M.g4", master, equeue);
assertEquals("unexpected errors: "+equeue, 0, equeue.errors.size()); assertEquals("unexpected errors: "+equeue, 0, equeue.errors.size());
String found = execParser("M.g", master, "MParser", "MLexer", String found = execParser("M.g4", master, "MParser", "MLexer",
"s", "x 34 9", debug); "s", "x 34 9", debug);
assertEquals("S.x\n", found); assertEquals("S.x\n", found);
} }
@ -284,15 +284,15 @@ public class TestCompositeGrammars extends BaseTest {
"tokens { A='a'; }\n" + "tokens { A='a'; }\n" +
"x : A {System.out.println(\"S.x\");} ;\n"; "x : A {System.out.println(\"S.x\");} ;\n";
mkdir(tmpdir); mkdir(tmpdir);
writeFile(tmpdir, "S.g", slave); writeFile(tmpdir, "S.g4", slave);
String master = String master =
"grammar M;\n" + "grammar M;\n" +
"import S;\n" + "import S;\n" +
"s : x ;\n" + "s : x ;\n" +
"WS : (' '|'\\n') {skip();} ;\n" ; "WS : (' '|'\\n') {skip();} ;\n" ;
writeFile(tmpdir, "M.g", master); writeFile(tmpdir, "M.g4", master);
Grammar g = new Grammar(tmpdir+"/M.g", master, equeue); Grammar g = new Grammar(tmpdir+"/M.g4", master, equeue);
Object expectedArg = "S"; Object expectedArg = "S";
ErrorType expectedMsgID = ErrorType.OPTIONS_IN_DELEGATE; ErrorType expectedMsgID = ErrorType.OPTIONS_IN_DELEGATE;
@ -310,15 +310,15 @@ public class TestCompositeGrammars extends BaseTest {
"parser grammar S;\n" + "parser grammar S;\n" +
"options {toke\n"; "options {toke\n";
mkdir(tmpdir); mkdir(tmpdir);
writeFile(tmpdir, "S.g", slave); writeFile(tmpdir, "S.g4", slave);
String master = String master =
"grammar M;\n" + "grammar M;\n" +
"import S;\n" + "import S;\n" +
"s : x ;\n" + "s : x ;\n" +
"WS : (' '|'\\n') {skip();} ;\n" ; "WS : (' '|'\\n') {skip();} ;\n" ;
writeFile(tmpdir, "M.g", master); writeFile(tmpdir, "M.g4", master);
Grammar g = new Grammar(tmpdir+"/M.g", master, equeue); Grammar g = new Grammar(tmpdir+"/M.g4", master, equeue);
assertEquals(ErrorType.SYNTAX_ERROR, equeue.errors.get(0).errorType); assertEquals(ErrorType.SYNTAX_ERROR, equeue.errors.get(0).errorType);
} }
@ -329,13 +329,13 @@ public class TestCompositeGrammars extends BaseTest {
"a : b {System.out.println(\"S.a\");} ;\n" + "a : b {System.out.println(\"S.a\");} ;\n" +
"b : B ;\n" ; "b : B ;\n" ;
mkdir(tmpdir); mkdir(tmpdir);
writeFile(tmpdir, "S.g", slave); writeFile(tmpdir, "S.g4", slave);
String master = String master =
"grammar M;\n" + "grammar M;\n" +
"import S;\n" + "import S;\n" +
"b : 'b'|'c' ;\n" + "b : 'b'|'c' ;\n" +
"WS : (' '|'\\n') {skip();} ;\n" ; "WS : (' '|'\\n') {skip();} ;\n" ;
String found = execParser("M.g", master, "MParser", "MLexer", String found = execParser("M.g4", master, "MParser", "MLexer",
"a", "c", debug); "a", "c", debug);
assertEquals("S.a\n", found); assertEquals("S.a\n", found);
} }
@ -349,7 +349,7 @@ public class TestCompositeGrammars extends BaseTest {
" ;\n" + " ;\n" +
"init : '=' INT ;\n"; "init : '=' INT ;\n";
mkdir(tmpdir); mkdir(tmpdir);
writeFile(tmpdir, "JavaDecl.g", slave); writeFile(tmpdir, "JavaDecl.g4", slave);
String master = String master =
"grammar Java;\n" + "grammar Java;\n" +
"import JavaDecl;\n" + "import JavaDecl;\n" +
@ -360,7 +360,7 @@ public class TestCompositeGrammars extends BaseTest {
"INT : '0'..'9'+ ;\n" + "INT : '0'..'9'+ ;\n" +
"WS : (' '|'\\n') {skip();} ;\n" ; "WS : (' '|'\\n') {skip();} ;\n" ;
// for float to work in decl, type must be overridden // for float to work in decl, type must be overridden
String found = execParser("Java.g", master, "JavaParser", "JavaLexer", String found = execParser("Java.g4", master, "JavaParser", "JavaLexer",
"prog", "float x = 3;", debug); "prog", "float x = 3;", debug);
assertEquals("JavaDecl: floatx=3;\n", found); assertEquals("JavaDecl: floatx=3;\n", found);
} }
@ -371,20 +371,20 @@ public class TestCompositeGrammars extends BaseTest {
"a : b {System.out.println(\"S.a\");} ;\n" + "a : b {System.out.println(\"S.a\");} ;\n" +
"b : B ;\n" ; "b : B ;\n" ;
mkdir(tmpdir); mkdir(tmpdir);
writeFile(tmpdir, "S.g", slave); writeFile(tmpdir, "S.g4", slave);
String slave2 = String slave2 =
"parser grammar T;\n" + "parser grammar T;\n" +
"tokens { A='x'; }\n" + "tokens { A='x'; }\n" +
"b : B {System.out.println(\"T.b\");} ;\n"; "b : B {System.out.println(\"T.b\");} ;\n";
writeFile(tmpdir, "T.g", slave2); writeFile(tmpdir, "T.g4", slave2);
String master = String master =
"grammar M;\n" + "grammar M;\n" +
"import S, T;\n" + "import S, T;\n" +
"b : 'b'|'c' {System.out.println(\"M.b\");}|B|A ;\n" + "b : 'b'|'c' {System.out.println(\"M.b\");}|B|A ;\n" +
"WS : (' '|'\\n') {skip();} ;\n" ; "WS : (' '|'\\n') {skip();} ;\n" ;
String found = execParser("M.g", master, "MParser", "MLexer", String found = execParser("M.g4", master, "MParser", "MLexer",
"a", "c", debug); "a", "c", debug);
assertEquals("M.b\n" + assertEquals("M.b\n" +
"S.a\n", found); "S.a\n", found);
@ -397,7 +397,7 @@ public class TestCompositeGrammars extends BaseTest {
"A : 'a' {System.out.println(\"S.A\");} ;\n" + "A : 'a' {System.out.println(\"S.A\");} ;\n" +
"C : 'c' ;\n"; "C : 'c' ;\n";
mkdir(tmpdir); mkdir(tmpdir);
writeFile(tmpdir, "S.g", slave); writeFile(tmpdir, "S.g4", slave);
String master = String master =
"lexer grammar M;\n" + "lexer grammar M;\n" +
"import S;\n" + "import S;\n" +
@ -409,7 +409,7 @@ public class TestCompositeGrammars extends BaseTest {
"[@1,1:1='b',<3>,1:1]\n" + "[@1,1:1='b',<3>,1:1]\n" +
"[@2,2:2='c',<6>,1:2]\n" + "[@2,2:2='c',<6>,1:2]\n" +
"[@3,3:2='<EOF>',<-1>,1:3]\n"; "[@3,3:2='<EOF>',<-1>,1:3]\n";
String found = execLexer("M.g", master, "M", "abc", debug); String found = execLexer("M.g4", master, "M", "abc", debug);
assertEquals(expecting, found); assertEquals(expecting, found);
} }
@ -419,13 +419,13 @@ public class TestCompositeGrammars extends BaseTest {
"A : 'a' {System.out.println(\"S.A\");} ;\n" + "A : 'a' {System.out.println(\"S.A\");} ;\n" +
"B : 'b' {System.out.println(\"S.B\");} ;\n"; "B : 'b' {System.out.println(\"S.B\");} ;\n";
mkdir(tmpdir); mkdir(tmpdir);
writeFile(tmpdir, "S.g", slave); writeFile(tmpdir, "S.g4", slave);
String master = String master =
"lexer grammar M;\n" + "lexer grammar M;\n" +
"import S;\n" + "import S;\n" +
"A : 'a' B {System.out.println(\"M.A\");} ;\n" + "A : 'a' B {System.out.println(\"M.A\");} ;\n" +
"WS : (' '|'\\n') {skip();} ;\n" ; "WS : (' '|'\\n') {skip();} ;\n" ;
String found = execLexer("M.g", master, "M", "ab", debug); String found = execLexer("M.g4", master, "M", "ab", debug);
assertEquals("M.A\n" + assertEquals("M.A\n" +
"[@0,0:1='ab',<3>,1:0]\n" + "[@0,0:1='ab',<3>,1:0]\n" +
"[@1,2:1='<EOF>',<-1>,1:2]\n", found); "[@1,2:1='<EOF>',<-1>,1:2]\n", found);
@ -440,14 +440,14 @@ public class TestCompositeGrammars extends BaseTest {
"lexer grammar S;\n" + "lexer grammar S;\n" +
"ID : 'a'..'z'+ ;\n"; "ID : 'a'..'z'+ ;\n";
mkdir(tmpdir); mkdir(tmpdir);
writeFile(tmpdir, "S.g", slave); writeFile(tmpdir, "S.g4", slave);
String master = String master =
"grammar M;\n" + "grammar M;\n" +
"import S;\n" + "import S;\n" +
"a : A {System.out.println(\"M.a: \"+$A);} ;\n" + "a : A {System.out.println(\"M.a: \"+$A);} ;\n" +
"A : 'abc' {System.out.println(\"M.A\");} ;\n" + "A : 'abc' {System.out.println(\"M.A\");} ;\n" +
"WS : (' '|'\\n') {skip();} ;\n" ; "WS : (' '|'\\n') {skip();} ;\n" ;
String found = execParser("M.g", master, "MParser", "MLexer", String found = execParser("M.g4", master, "MParser", "MLexer",
"a", "abc", debug); "a", "abc", debug);
assertEquals("unexpected errors: "+equeue, 0, equeue.errors.size()); assertEquals("unexpected errors: "+equeue, 0, equeue.errors.size());
@ -464,20 +464,20 @@ public class TestCompositeGrammars extends BaseTest {
"parser grammar T;\n" + "parser grammar T;\n" +
"a : T ;\n" ; "a : T ;\n" ;
mkdir(tmpdir); mkdir(tmpdir);
writeFile(tmpdir, "T.g", slave); writeFile(tmpdir, "T.g4", slave);
String slave2 = String slave2 =
"parser grammar S;\n" + "parser grammar S;\n" +
"import T;\n" + "import T;\n" +
"a : S ;\n" ; "a : S ;\n" ;
mkdir(tmpdir); mkdir(tmpdir);
writeFile(tmpdir, "S.g", slave2); writeFile(tmpdir, "S.g4", slave2);
String master = String master =
"grammar M;\n" + "grammar M;\n" +
"import S;\n" + "import S;\n" +
"a : M ;\n" ; "a : M ;\n" ;
writeFile(tmpdir, "M.g", master); writeFile(tmpdir, "M.g4", master);
Grammar g = new Grammar(tmpdir+"/M.g", master, equeue); Grammar g = new Grammar(tmpdir+"/M.g4", master, equeue);
String expectedTokenIDToTypeMap = "{EOF=-1, M=3}"; // S and T aren't imported; overridden String expectedTokenIDToTypeMap = "{EOF=-1, M=3}"; // S and T aren't imported; overridden
String expectedStringLiteralToTypeMap = "{}"; String expectedStringLiteralToTypeMap = "{}";
@ -492,7 +492,7 @@ public class TestCompositeGrammars extends BaseTest {
assertEquals("unexpected errors: "+equeue, 0, equeue.errors.size()); assertEquals("unexpected errors: "+equeue, 0, equeue.errors.size());
boolean ok = boolean ok =
rawGenerateAndBuildRecognizer("M.g", master, "MParser", null); rawGenerateAndBuildRecognizer("M.g4", master, "MParser", null);
boolean expecting = true; // should be ok boolean expecting = true; // should be ok
assertEquals(expecting, ok); assertEquals(expecting, ok);
} }
@ -503,37 +503,37 @@ public class TestCompositeGrammars extends BaseTest {
"parser grammar T;\n" + "parser grammar T;\n" +
"x : T ;\n" ; "x : T ;\n" ;
mkdir(tmpdir); mkdir(tmpdir);
writeFile(tmpdir, "T.g", slave); writeFile(tmpdir, "T.g4", slave);
slave = slave =
"parser grammar S;\n" + "parser grammar S;\n" +
"import T;\n" + "import T;\n" +
"y : S ;\n" ; "y : S ;\n" ;
mkdir(tmpdir); mkdir(tmpdir);
writeFile(tmpdir, "S.g", slave); writeFile(tmpdir, "S.g4", slave);
slave = slave =
"parser grammar C;\n" + "parser grammar C;\n" +
"i : C ;\n" ; "i : C ;\n" ;
mkdir(tmpdir); mkdir(tmpdir);
writeFile(tmpdir, "C.g", slave); writeFile(tmpdir, "C.g4", slave);
slave = slave =
"parser grammar B;\n" + "parser grammar B;\n" +
"j : B ;\n" ; "j : B ;\n" ;
mkdir(tmpdir); mkdir(tmpdir);
writeFile(tmpdir, "B.g", slave); writeFile(tmpdir, "B.g4", slave);
slave = slave =
"parser grammar A;\n" + "parser grammar A;\n" +
"import B,C;\n" + "import B,C;\n" +
"k : A ;\n" ; "k : A ;\n" ;
mkdir(tmpdir); mkdir(tmpdir);
writeFile(tmpdir, "A.g", slave); writeFile(tmpdir, "A.g4", slave);
String master = String master =
"grammar M;\n" + "grammar M;\n" +
"import S,A;\n" + "import S,A;\n" +
"a : M ;\n" ; "a : M ;\n" ;
writeFile(tmpdir, "M.g", master); writeFile(tmpdir, "M.g4", master);
Grammar g = new Grammar(tmpdir+"/M.g", master, equeue); Grammar g = new Grammar(tmpdir+"/M.g4", master, equeue);
assertEquals(equeue.errors.toString(), "[]"); assertEquals(equeue.errors.toString(), "[]");
assertEquals(equeue.warnings.toString(), "[]"); assertEquals(equeue.warnings.toString(), "[]");
@ -548,7 +548,7 @@ public class TestCompositeGrammars extends BaseTest {
realElements(g.typeToTokenList).toString()); realElements(g.typeToTokenList).toString());
boolean ok = boolean ok =
rawGenerateAndBuildRecognizer("M.g", master, "MParser", null); rawGenerateAndBuildRecognizer("M.g4", master, "MParser", null);
boolean expecting = true; // should be ok boolean expecting = true; // should be ok
assertEquals(expecting, ok); assertEquals(expecting, ok);
} }
@ -559,20 +559,20 @@ public class TestCompositeGrammars extends BaseTest {
"parser grammar T;\n" + "parser grammar T;\n" +
"x : T ;\n" ; "x : T ;\n" ;
mkdir(tmpdir); mkdir(tmpdir);
writeFile(tmpdir, "T.g", slave); writeFile(tmpdir, "T.g4", slave);
String slave2 = String slave2 =
"parser grammar S;\n" + // A, B, C token type order "parser grammar S;\n" + // A, B, C token type order
"import T;\n" + "import T;\n" +
"a : S ;\n" ; "a : S ;\n" ;
mkdir(tmpdir); mkdir(tmpdir);
writeFile(tmpdir, "S.g", slave2); writeFile(tmpdir, "S.g4", slave2);
String master = String master =
"grammar M;\n" + "grammar M;\n" +
"import S;\n" + "import S;\n" +
"a : M x ;\n" ; // x MUST BE VISIBLE TO M "a : M x ;\n" ; // x MUST BE VISIBLE TO M
writeFile(tmpdir, "M.g", master); writeFile(tmpdir, "M.g4", master);
Grammar g = new Grammar(tmpdir+"/M.g", master, equeue); Grammar g = new Grammar(tmpdir+"/M.g4", master, equeue);
String expectedTokenIDToTypeMap = "{EOF=-1, M=3, T=4}"; String expectedTokenIDToTypeMap = "{EOF=-1, M=3, T=4}";
String expectedStringLiteralToTypeMap = "{}"; String expectedStringLiteralToTypeMap = "{}";
@ -597,29 +597,29 @@ public class TestCompositeGrammars extends BaseTest {
"T3: '3';\n" + "T3: '3';\n" +
"T4: '4';\n" ; "T4: '4';\n" ;
mkdir(tmpdir); mkdir(tmpdir);
writeFile(tmpdir, "L.g", gstr); writeFile(tmpdir, "L.g4", gstr);
gstr = gstr =
"parser grammar G1;\n" + "parser grammar G1;\n" +
"s: a | b;\n" + "s: a | b;\n" +
"a: T1;\n" + "a: T1;\n" +
"b: T2;\n" ; "b: T2;\n" ;
mkdir(tmpdir); mkdir(tmpdir);
writeFile(tmpdir, "G1.g", gstr); writeFile(tmpdir, "G1.g4", gstr);
gstr = gstr =
"parser grammar G2;\n" + "parser grammar G2;\n" +
"import G1;\n" + "import G1;\n" +
"a: T3;\n" ; "a: T3;\n" ;
mkdir(tmpdir); mkdir(tmpdir);
writeFile(tmpdir, "G2.g", gstr); writeFile(tmpdir, "G2.g4", gstr);
String G3str = String G3str =
"grammar G3;\n" + "grammar G3;\n" +
"import G2;\n" + "import G2;\n" +
"b: T4;\n" ; "b: T4;\n" ;
mkdir(tmpdir); mkdir(tmpdir);
writeFile(tmpdir, "G3.g", G3str); writeFile(tmpdir, "G3.g4", G3str);
Grammar g = new Grammar(tmpdir+"/G3.g", G3str, equeue); Grammar g = new Grammar(tmpdir+"/G3.g4", G3str, equeue);
String expectedTokenIDToTypeMap = "{EOF=-1, T4=3, T3=4}"; String expectedTokenIDToTypeMap = "{EOF=-1, T4=3, T3=4}";
String expectedStringLiteralToTypeMap = "{}"; String expectedStringLiteralToTypeMap = "{}";
@ -634,7 +634,7 @@ public class TestCompositeGrammars extends BaseTest {
assertEquals("unexpected errors: "+equeue, 0, equeue.errors.size()); assertEquals("unexpected errors: "+equeue, 0, equeue.errors.size());
boolean ok = boolean ok =
rawGenerateAndBuildRecognizer("G3.g", G3str, "G3Parser", null); rawGenerateAndBuildRecognizer("G3.g4", G3str, "G3Parser", null);
boolean expecting = true; // should be ok boolean expecting = true; // should be ok
assertEquals(expecting, ok); assertEquals(expecting, ok);
} }
@ -644,7 +644,7 @@ public class TestCompositeGrammars extends BaseTest {
"parser grammar S;\n" + "parser grammar S;\n" +
"a : B {System.out.print(\"S.a\");} ;\n"; "a : B {System.out.print(\"S.a\");} ;\n";
mkdir(tmpdir); mkdir(tmpdir);
writeFile(tmpdir, "S.g", slave); writeFile(tmpdir, "S.g4", slave);
String master = String master =
"grammar M;\n" + "grammar M;\n" +
"import S;\n" + "import S;\n" +
@ -653,7 +653,7 @@ public class TestCompositeGrammars extends BaseTest {
"s : a ;\n" + "s : a ;\n" +
"B : 'b' ;" + // defines B from inherited token space "B : 'b' ;" + // defines B from inherited token space
"WS : (' '|'\\n') {skip();} ;\n" ; "WS : (' '|'\\n') {skip();} ;\n" ;
boolean ok = antlr("M.g", "M.g", master); boolean ok = antlr("M.g4", "M.g4", master);
boolean expecting = true; // should be ok boolean expecting = true; // should be ok
assertEquals(expecting, ok); assertEquals(expecting, ok);
} }

View File

@ -49,7 +49,7 @@ public class TestFullContextParsing extends BaseTest {
" : ID | ID {;} ;\n" + " : ID | ID {;} ;\n" +
"ID : 'a'..'z'+ ;\n"+ "ID : 'a'..'z'+ ;\n"+
"WS : (' '|'\\t'|'\\n')+ {skip();} ;\n"; "WS : (' '|'\\t'|'\\n')+ {skip();} ;\n";
String result = execParser("T.g", grammar, "TParser", "TLexer", "s", String result = execParser("T.g4", grammar, "TParser", "TLexer", "s",
"abc", true); "abc", true);
String expecting = String expecting =
"Decision 0:\n" + "Decision 0:\n" +
@ -70,7 +70,7 @@ public class TestFullContextParsing extends BaseTest {
"ID : 'a'..'z'+ ;\n"+ "ID : 'a'..'z'+ ;\n"+
"INT : '0'..'9'+ ;\n"+ "INT : '0'..'9'+ ;\n"+
"WS : (' '|'\\t'|'\\n')+ {skip();} ;\n"; "WS : (' '|'\\t'|'\\n')+ {skip();} ;\n";
String result = execParser("T.g", grammar, "TParser", "TLexer", "s", String result = execParser("T.g4", grammar, "TParser", "TLexer", "s",
"$ 34 abc", true); "$ 34 abc", true);
String expecting = String expecting =
"Decision 1:\n" + "Decision 1:\n" +
@ -81,7 +81,7 @@ public class TestFullContextParsing extends BaseTest {
"line 1:2 reportContextSensitivity d=1, input='34'\n", "line 1:2 reportContextSensitivity d=1, input='34'\n",
this.stderrDuringParse); this.stderrDuringParse);
result = execParser("T.g", grammar, "TParser", "TLexer", "s", result = execParser("T.g4", grammar, "TParser", "TLexer", "s",
"@ 34 abc", true); "@ 34 abc", true);
expecting = expecting =
"Decision 1:\n" + "Decision 1:\n" +
@ -104,7 +104,7 @@ public class TestFullContextParsing extends BaseTest {
"ID : 'a'..'z'+ ;\n"+ "ID : 'a'..'z'+ ;\n"+
"INT : '0'..'9'+ ;\n"+ "INT : '0'..'9'+ ;\n"+
"WS : (' '|'\\t'|'\\n')+ {skip();} ;\n"; "WS : (' '|'\\t'|'\\n')+ {skip();} ;\n";
String result = execParser("T.g", grammar, "TParser", "TLexer", "s", String result = execParser("T.g4", grammar, "TParser", "TLexer", "s",
"$ 34 abc @ 34 abc", true); "$ 34 abc @ 34 abc", true);
String expecting = String expecting =
"Decision 2:\n" + "Decision 2:\n" +
@ -131,7 +131,7 @@ public class TestFullContextParsing extends BaseTest {
"ID : 'a'..'z'+ ;\n"+ "ID : 'a'..'z'+ ;\n"+
"WS : (' '|'\\t'|'\\n')+ {skip();} ;\n"; "WS : (' '|'\\t'|'\\n')+ {skip();} ;\n";
String input = "{ if x then return }"; String input = "{ if x then return }";
String result = execParser("T.g", grammar, "TParser", "TLexer", "s", String result = execParser("T.g4", grammar, "TParser", "TLexer", "s",
input, true); input, true);
String expecting = String expecting =
"Decision 1:\n" + "Decision 1:\n" +
@ -141,7 +141,7 @@ public class TestFullContextParsing extends BaseTest {
input = input =
"{ if x then if y then return else foo }"; "{ if x then if y then return else foo }";
result = execParser("T.g", grammar, "TParser", "TLexer", "s", result = execParser("T.g4", grammar, "TParser", "TLexer", "s",
input, true); input, true);
expecting = expecting =
"Decision 1:\n" + "Decision 1:\n" +
@ -153,7 +153,7 @@ public class TestFullContextParsing extends BaseTest {
this.stderrDuringParse); this.stderrDuringParse);
input = "{ if x then return else foo }"; input = "{ if x then return else foo }";
result = execParser("T.g", grammar, "TParser", "TLexer", "s", result = execParser("T.g4", grammar, "TParser", "TLexer", "s",
input, true); input, true);
expecting = expecting =
"Decision 1:\n" + "Decision 1:\n" +
@ -170,7 +170,7 @@ public class TestFullContextParsing extends BaseTest {
this.stderrDuringParse); this.stderrDuringParse);
input = "{ if x then return else foo }"; input = "{ if x then return else foo }";
result = execParser("T.g", grammar, "TParser", "TLexer", "s", result = execParser("T.g4", grammar, "TParser", "TLexer", "s",
input, true); input, true);
expecting = expecting =
"Decision 1:\n" + "Decision 1:\n" +
@ -183,7 +183,7 @@ public class TestFullContextParsing extends BaseTest {
input = input =
"{ if x then return else foo\n" + "{ if x then return else foo\n" +
"if x then if y then return else foo }"; "if x then if y then return else foo }";
result = execParser("T.g", grammar, "TParser", "TLexer", "s", result = execParser("T.g4", grammar, "TParser", "TLexer", "s",
input, true); input, true);
expecting = expecting =
"Decision 1:\n" + "Decision 1:\n" +
@ -199,7 +199,7 @@ public class TestFullContextParsing extends BaseTest {
input = input =
"{ if x then return else foo\n" + "{ if x then return else foo\n" +
"if x then if y then return else foo }"; "if x then if y then return else foo }";
result = execParser("T.g", grammar, "TParser", "TLexer", "s", result = execParser("T.g4", grammar, "TParser", "TLexer", "s",
input, true); input, true);
expecting = expecting =
"Decision 1:\n" + "Decision 1:\n" +
@ -235,7 +235,7 @@ public class TestFullContextParsing extends BaseTest {
"ID : [a-z]+ ;\n" + "ID : [a-z]+ ;\n" +
""; "";
String found = execParser("T.g", grammar, "TParser", "TLexer", "prog", "a(i)<-x", true); String found = execParser("T.g4", grammar, "TParser", "TLexer", "prog", "a(i)<-x", true);
assertEquals("pass.\n", found); assertEquals("pass.\n", found);
String expecting = String expecting =

View File

@ -15,17 +15,17 @@ public class TestLeftRecursion extends BaseTest {
" ;\n" + " ;\n" +
"ID : 'a'..'z'+ ;\n" + "ID : 'a'..'z'+ ;\n" +
"WS : (' '|'\\n') {skip();} ;\n"; "WS : (' '|'\\n') {skip();} ;\n";
String found = execParser("T.g", grammar, "TParser", "TLexer", String found = execParser("T.g4", grammar, "TParser", "TLexer",
"s", "x", debug); "s", "x", debug);
String expecting = "(s (a x))\n"; String expecting = "(s (a x))\n";
assertEquals(expecting, found); assertEquals(expecting, found);
found = execParser("T.g", grammar, "TParser", "TLexer", found = execParser("T.g4", grammar, "TParser", "TLexer",
"s", "x y", debug); "s", "x y", debug);
expecting = "(s (a (a x) y))\n"; expecting = "(s (a (a x) y))\n";
assertEquals(expecting, found); assertEquals(expecting, found);
found = execParser("T.g", grammar, "TParser", "TLexer", found = execParser("T.g4", grammar, "TParser", "TLexer",
"s", "x y z", debug); "s", "x y z", debug);
expecting = "(s (a (a (a x) y) z))\n"; expecting = "(s (a (a (a x) y) z))\n";
assertEquals(expecting, found); assertEquals(expecting, found);
@ -40,7 +40,7 @@ public class TestLeftRecursion extends BaseTest {
" ;\n" + " ;\n" +
"ID : 'a'..'z'+ ;\n" + "ID : 'a'..'z'+ ;\n" +
"WS : (' '|'\\n') {skip();} ;\n"; "WS : (' '|'\\n') {skip();} ;\n";
String found = execParser("T.g", grammar, "TParser", "TLexer", String found = execParser("T.g4", grammar, "TParser", "TLexer",
"s", "x y z", debug); "s", "x y z", debug);
String expecting = "(s (a (a (a x) y) z))\n"; String expecting = "(s (a (a (a x) y) z))\n";
assertEquals(expecting, found); assertEquals(expecting, found);
@ -358,7 +358,7 @@ public class TestLeftRecursion extends BaseTest {
} }
public void runTests(String grammar, String[] tests, String startRule) { public void runTests(String grammar, String[] tests, String startRule) {
rawGenerateAndBuildRecognizer("T.g", grammar, "TParser", "TLexer"); rawGenerateAndBuildRecognizer("T.g4", grammar, "TParser", "TLexer");
writeRecognizerAndCompile("TParser", writeRecognizerAndCompile("TParser",
"TLexer", "TLexer",
startRule, startRule,

View File

@ -37,7 +37,7 @@ public class TestLexerErrors extends BaseTest {
String grammar = String grammar =
"lexer grammar L;\n" + "lexer grammar L;\n" +
"A : 'a' 'b' ;\n"; "A : 'a' 'b' ;\n";
String tokens = execLexer("L.g", grammar, "L", "x"); String tokens = execLexer("L.g4", grammar, "L", "x");
String expectingTokens = String expectingTokens =
"[@0,1:0='<EOF>',<-1>,1:1]\n"; "[@0,1:0='<EOF>',<-1>,1:1]\n";
assertEquals(expectingTokens, tokens); assertEquals(expectingTokens, tokens);
@ -50,7 +50,7 @@ public class TestLexerErrors extends BaseTest {
String grammar = String grammar =
"lexer grammar L;\n" + "lexer grammar L;\n" +
"A : 'a' 'b' ;\n"; "A : 'a' 'b' ;\n";
String tokens = execLexer("L.g", grammar, "L", "abx"); String tokens = execLexer("L.g4", grammar, "L", "abx");
String expectingTokens = String expectingTokens =
"[@0,0:1='ab',<3>,1:0]\n" + "[@0,0:1='ab',<3>,1:0]\n" +
"[@1,3:2='<EOF>',<-1>,1:3]\n"; "[@1,3:2='<EOF>',<-1>,1:3]\n";
@ -64,7 +64,7 @@ public class TestLexerErrors extends BaseTest {
String grammar = String grammar =
"lexer grammar L;\n" + "lexer grammar L;\n" +
"A : 'a' 'b' ;\n"; "A : 'a' 'b' ;\n";
String tokens = execLexer("L.g", grammar, "L", "ax"); String tokens = execLexer("L.g4", grammar, "L", "ax");
String expectingTokens = String expectingTokens =
"[@0,2:1='<EOF>',<-1>,1:2]\n"; "[@0,2:1='<EOF>',<-1>,1:2]\n";
assertEquals(expectingTokens, tokens); assertEquals(expectingTokens, tokens);
@ -77,7 +77,7 @@ public class TestLexerErrors extends BaseTest {
String grammar = String grammar =
"lexer grammar L;\n" + "lexer grammar L;\n" +
"A : 'a' 'b' ;\n"; "A : 'a' 'b' ;\n";
String tokens = execLexer("L.g", grammar, "L", "abax"); String tokens = execLexer("L.g4", grammar, "L", "abax");
String expectingTokens = String expectingTokens =
"[@0,0:1='ab',<3>,1:0]\n" + "[@0,0:1='ab',<3>,1:0]\n" +
"[@1,4:3='<EOF>',<-1>,1:4]\n"; "[@1,4:3='<EOF>',<-1>,1:4]\n";
@ -95,7 +95,7 @@ public class TestLexerErrors extends BaseTest {
// The first ab caches the DFA then abx goes through the DFA but // The first ab caches the DFA then abx goes through the DFA but
// into the ATN for the x, which fails. Must go back into DFA // into the ATN for the x, which fails. Must go back into DFA
// and return to previous dfa accept state // and return to previous dfa accept state
String tokens = execLexer("L.g", grammar, "L", "ababx"); String tokens = execLexer("L.g4", grammar, "L", "ababx");
String expectingTokens = String expectingTokens =
"[@0,0:1='ab',<3>,1:0]\n" + "[@0,0:1='ab',<3>,1:0]\n" +
"[@1,2:3='ab',<3>,1:2]\n" + "[@1,2:3='ab',<3>,1:2]\n" +
@ -116,7 +116,7 @@ public class TestLexerErrors extends BaseTest {
// into the ATN for the c. It marks that hasn't except state // into the ATN for the c. It marks that hasn't except state
// and then keeps going in the ATN. It fails on the x, but // and then keeps going in the ATN. It fails on the x, but
// uses the previous accepted in the ATN not DFA // uses the previous accepted in the ATN not DFA
String tokens = execLexer("L.g", grammar, "L", "ababcx"); String tokens = execLexer("L.g4", grammar, "L", "ababcx");
String expectingTokens = String expectingTokens =
"[@0,0:1='ab',<3>,1:0]\n" + "[@0,0:1='ab',<3>,1:0]\n" +
"[@1,2:4='abc',<4>,1:2]\n" + "[@1,2:4='abc',<4>,1:2]\n" +
@ -131,7 +131,7 @@ public class TestLexerErrors extends BaseTest {
String grammar = String grammar =
"lexer grammar L;\n" + "lexer grammar L;\n" +
"A : 'abc' ;\n"; "A : 'abc' ;\n";
String tokens = execLexer("L.g", grammar, "L", "abx"); String tokens = execLexer("L.g4", grammar, "L", "abx");
String expectingTokens = String expectingTokens =
"[@0,3:2='<EOF>',<-1>,1:3]\n"; "[@0,3:2='<EOF>',<-1>,1:3]\n";
assertEquals(expectingTokens, tokens); assertEquals(expectingTokens, tokens);
@ -155,7 +155,7 @@ public class TestLexerErrors extends BaseTest {
"primary : ID;\n" + "primary : ID;\n" +
"ID : [a-z]+;\n" + "ID : [a-z]+;\n" +
"\n"; "\n";
String result = execLexer("T.g", grammar, "TLexer", "x : x", false); String result = execLexer("T.g4", grammar, "TLexer", "x : x", false);
String expecting = String expecting =
"[@0,0:0='x',<5>,1:0]\n" + "[@0,0:0='x',<5>,1:0]\n" +
"[@1,2:2=':',<4>,1:2]\n" + "[@1,2:2=':',<4>,1:2]\n" +

View File

@ -7,7 +7,7 @@ public class TestLexerExec extends BaseTest {
String grammar = String grammar =
"lexer grammar L;\n"+ "lexer grammar L;\n"+
"QUOTE : '\"' ;\n"; // make sure this compiles "QUOTE : '\"' ;\n"; // make sure this compiles
String found = execLexer("L.g", grammar, "L", "\""); String found = execLexer("L.g4", grammar, "L", "\"");
String expecting = String expecting =
"[@0,0:0='\"',<3>,1:0]\n" + "[@0,0:0='\"',<3>,1:0]\n" +
"[@1,1:0='<EOF>',<-1>,1:1]\n"; "[@1,1:0='<EOF>',<-1>,1:1]\n";
@ -20,7 +20,7 @@ public class TestLexerExec extends BaseTest {
"A : '-' I ;\n" + "A : '-' I ;\n" +
"I : '0'..'9'+ ;\n"+ "I : '0'..'9'+ ;\n"+
"WS : (' '|'\\n') {skip();} ;"; "WS : (' '|'\\n') {skip();} ;";
String found = execLexer("L.g", grammar, "L", "34 -21 3"); String found = execLexer("L.g4", grammar, "L", "34 -21 3");
String expecting = String expecting =
"[@0,0:1='34',<4>,1:0]\n" + "[@0,0:1='34',<4>,1:0]\n" +
"[@1,3:5='-21',<3>,1:3]\n" + "[@1,3:5='-21',<3>,1:3]\n" +
@ -34,7 +34,7 @@ public class TestLexerExec extends BaseTest {
"lexer grammar L;\n"+ "lexer grammar L;\n"+
"I : '0'..'9'+ {System.out.println(\"I\");} ;\n"+ "I : '0'..'9'+ {System.out.println(\"I\");} ;\n"+
"WS : (' '|'\\n') {skip();} ;"; "WS : (' '|'\\n') {skip();} ;";
String found = execLexer("L.g", grammar, "L", "34 34"); String found = execLexer("L.g4", grammar, "L", "34 34");
String expecting = String expecting =
"I\n" + "I\n" +
"I\n" + "I\n" +
@ -49,7 +49,7 @@ public class TestLexerExec extends BaseTest {
"lexer grammar L;\n"+ "lexer grammar L;\n"+
"I : '0'..'9'+ {System.out.println(\"I\");} ;\n"+ "I : '0'..'9'+ {System.out.println(\"I\");} ;\n"+
"WS : (' '|'\\n') -> skip ;"; "WS : (' '|'\\n') -> skip ;";
String found = execLexer("L.g", grammar, "L", "34 34"); String found = execLexer("L.g4", grammar, "L", "34 34");
String expecting = String expecting =
"I\n" + "I\n" +
"I\n" + "I\n" +
@ -64,7 +64,7 @@ public class TestLexerExec extends BaseTest {
"lexer grammar L;\n"+ "lexer grammar L;\n"+
"I : '0'..'9'+ {System.out.println(\"I\");} ;\n"+ "I : '0'..'9'+ {System.out.println(\"I\");} ;\n"+
"WS : '#' -> more ;"; "WS : '#' -> more ;";
String found = execLexer("L.g", grammar, "L", "34#10"); String found = execLexer("L.g4", grammar, "L", "34#10");
String expecting = String expecting =
"I\n" + "I\n" +
"I\n" + "I\n" +
@ -79,7 +79,7 @@ public class TestLexerExec extends BaseTest {
"lexer grammar L;\n"+ "lexer grammar L;\n"+
"I : '0'..'9'+ {System.out.println(\"I\");} ;\n"+ "I : '0'..'9'+ {System.out.println(\"I\");} ;\n"+
"HASH : '#' -> type(HASH) ;"; "HASH : '#' -> type(HASH) ;";
String found = execLexer("L.g", grammar, "L", "34#"); String found = execLexer("L.g4", grammar, "L", "34#");
String expecting = String expecting =
"I\n" + "I\n" +
"[@0,0:1='34',<3>,1:0]\n" + "[@0,0:1='34',<3>,1:0]\n" +
@ -93,7 +93,7 @@ public class TestLexerExec extends BaseTest {
"lexer grammar L;\n"+ "lexer grammar L;\n"+
"I : '0'..'9'+ {System.out.println(\"I\");} ;\n"+ "I : '0'..'9'+ {System.out.println(\"I\");} ;\n"+
"HASH : '#' -> type(HASH), skip, more ;"; "HASH : '#' -> type(HASH), skip, more ;";
String found = execLexer("L.g", grammar, "L", "34#11"); String found = execLexer("L.g4", grammar, "L", "34#11");
String expecting = String expecting =
"I\n" + "I\n" +
"I\n" + "I\n" +
@ -111,7 +111,7 @@ public class TestLexerExec extends BaseTest {
"mode STRING_MODE;\n"+ "mode STRING_MODE;\n"+
"STRING : '\"' {popMode();} ;\n"+ "STRING : '\"' {popMode();} ;\n"+
"ANY : . {more();} ;\n"; "ANY : . {more();} ;\n";
String found = execLexer("L.g", grammar, "L", "\"abc\" \"ab\""); String found = execLexer("L.g4", grammar, "L", "\"abc\" \"ab\"");
String expecting = String expecting =
"[@0,0:4='\"abc\"',<5>,1:0]\n" + "[@0,0:4='\"abc\"',<5>,1:0]\n" +
"[@1,6:9='\"ab\"',<5>,1:6]\n" + "[@1,6:9='\"ab\"',<5>,1:6]\n" +
@ -127,7 +127,7 @@ public class TestLexerExec extends BaseTest {
"mode STRING_MODE;\n"+ "mode STRING_MODE;\n"+
"STRING : '\"' -> popMode ;\n"+ "STRING : '\"' -> popMode ;\n"+
"ANY : . -> more ;\n"; "ANY : . -> more ;\n";
String found = execLexer("L.g", grammar, "L", "\"abc\" \"ab\""); String found = execLexer("L.g4", grammar, "L", "\"abc\" \"ab\"");
String expecting = String expecting =
"[@0,0:4='\"abc\"',<5>,1:0]\n" + "[@0,0:4='\"abc\"',<5>,1:0]\n" +
"[@1,6:9='\"ab\"',<5>,1:6]\n" + "[@1,6:9='\"ab\"',<5>,1:6]\n" +
@ -143,7 +143,7 @@ public class TestLexerExec extends BaseTest {
"mode STRING_MODE;\n"+ "mode STRING_MODE;\n"+
"STRING : '\"' -> mode(DEFAULT_MODE) ;\n"+ "STRING : '\"' -> mode(DEFAULT_MODE) ;\n"+
"ANY : . -> more ;\n"; "ANY : . -> more ;\n";
String found = execLexer("L.g", grammar, "L", "\"abc\" \"ab\""); String found = execLexer("L.g4", grammar, "L", "\"abc\" \"ab\"");
String expecting = String expecting =
"[@0,0:4='\"abc\"',<5>,1:0]\n" + "[@0,0:4='\"abc\"',<5>,1:0]\n" +
"[@1,6:9='\"ab\"',<5>,1:6]\n" + "[@1,6:9='\"ab\"',<5>,1:6]\n" +
@ -157,7 +157,7 @@ public class TestLexerExec extends BaseTest {
"KEND : 'end' ;\n" + // has priority "KEND : 'end' ;\n" + // has priority
"ID : 'a'..'z'+ ;\n" + "ID : 'a'..'z'+ ;\n" +
"WS : (' '|'\n')+ ;"; "WS : (' '|'\n')+ ;";
String found = execLexer("L.g", grammar, "L", "end eend ending a"); String found = execLexer("L.g4", grammar, "L", "end eend ending a");
String expecting = String expecting =
"[@0,0:2='end',<3>,1:0]\n" + "[@0,0:2='end',<3>,1:0]\n" +
"[@1,3:3=' ',<5>,1:3]\n" + "[@1,3:3=' ',<5>,1:3]\n" +
@ -180,7 +180,7 @@ public class TestLexerExec extends BaseTest {
"ID : 'a'..'z'+ ;\n" + "ID : 'a'..'z'+ ;\n" +
"fragment HexDigit : ('0'..'9'|'a'..'f'|'A'..'F') ;\n" + "fragment HexDigit : ('0'..'9'|'a'..'f'|'A'..'F') ;\n" +
"WS : (' '|'\n')+ ;"; "WS : (' '|'\n')+ ;";
String found = execLexer("L.g", grammar, "L", "x 0 1 a.b a.l"); String found = execLexer("L.g4", grammar, "L", "x 0 1 a.b a.l");
String expecting = String expecting =
"[@0,0:0='x',<7>,1:0]\n" + "[@0,0:0='x',<7>,1:0]\n" +
"[@1,1:1=' ',<8>,1:1]\n" + "[@1,1:1=' ',<8>,1:1]\n" +
@ -205,7 +205,7 @@ public class TestLexerExec extends BaseTest {
"lexer grammar L;\n" + "lexer grammar L;\n" +
"DONE : EOF ;\n" + "DONE : EOF ;\n" +
"A : 'a';\n"; "A : 'a';\n";
String found = execLexer("L.g", grammar, "L", ""); String found = execLexer("L.g4", grammar, "L", "");
String expecting = String expecting =
"[@0,0:-1='<EOF>',<3>,1:0]\n" + "[@0,0:-1='<EOF>',<3>,1:0]\n" +
"[@1,0:-1='<EOF>',<-1>,1:0]\n"; "[@1,0:-1='<EOF>',<-1>,1:0]\n";
@ -218,12 +218,12 @@ public class TestLexerExec extends BaseTest {
"A : 'a' EOF ;\n"+ "A : 'a' EOF ;\n"+
"B : 'a';\n"+ "B : 'a';\n"+
"C : 'c';\n"; "C : 'c';\n";
String found = execLexer("L.g", grammar, "L", ""); String found = execLexer("L.g4", grammar, "L", "");
String expecting = String expecting =
"[@0,0:-1='<EOF>',<-1>,1:0]\n"; "[@0,0:-1='<EOF>',<-1>,1:0]\n";
assertEquals(expecting, found); assertEquals(expecting, found);
found = execLexer("L.g", grammar, "L", "a"); found = execLexer("L.g4", grammar, "L", "a");
expecting = expecting =
"[@0,0:0='a',<3>,1:0]\n" + "[@0,0:0='a',<3>,1:0]\n" +
"[@1,1:0='<EOF>',<-1>,1:1]\n"; "[@1,1:0='<EOF>',<-1>,1:1]\n";
@ -235,7 +235,7 @@ public class TestLexerExec extends BaseTest {
"lexer grammar L;\n"+ "lexer grammar L;\n"+
"I : '0'..'9'+ {System.out.println(\"I\");} ;\n"+ "I : '0'..'9'+ {System.out.println(\"I\");} ;\n"+
"WS : [ \\n\\u000D] -> skip ;"; "WS : [ \\n\\u000D] -> skip ;";
String found = execLexer("L.g", grammar, "L", "34\r\n 34"); String found = execLexer("L.g4", grammar, "L", "34\r\n 34");
String expecting = String expecting =
"I\n" + "I\n" +
"I\n" + "I\n" +
@ -250,7 +250,7 @@ public class TestLexerExec extends BaseTest {
"lexer grammar L;\n"+ "lexer grammar L;\n"+
"I : '0'..'9'+ {System.out.println(\"I\");} ;\n"+ "I : '0'..'9'+ {System.out.println(\"I\");} ;\n"+
"WS : [ \\n\\u000D]+ -> skip ;"; "WS : [ \\n\\u000D]+ -> skip ;";
String found = execLexer("L.g", grammar, "L", "34\r\n 34"); String found = execLexer("L.g4", grammar, "L", "34\r\n 34");
String expecting = String expecting =
"I\n" + "I\n" +
"I\n" + "I\n" +
@ -265,7 +265,7 @@ public class TestLexerExec extends BaseTest {
"lexer grammar L;\n"+ "lexer grammar L;\n"+
"I : ~[ab \n] ~[ \ncd]* {System.out.println(\"I\");} ;\n"+ "I : ~[ab \n] ~[ \ncd]* {System.out.println(\"I\");} ;\n"+
"WS : [ \\n\\u000D]+ -> skip ;"; "WS : [ \\n\\u000D]+ -> skip ;";
String found = execLexer("L.g", grammar, "L", "xaf"); String found = execLexer("L.g4", grammar, "L", "xaf");
String expecting = String expecting =
"I\n" + "I\n" +
"[@0,0:2='xaf',<3>,1:0]\n" + "[@0,0:2='xaf',<3>,1:0]\n" +
@ -278,7 +278,7 @@ public class TestLexerExec extends BaseTest {
"lexer grammar L;\n"+ "lexer grammar L;\n"+
"I : (~[ab \n]|'a') {System.out.println(\"I\");} ;\n"+ "I : (~[ab \n]|'a') {System.out.println(\"I\");} ;\n"+
"WS : [ \\n\\u000D]+ -> skip ;"; "WS : [ \\n\\u000D]+ -> skip ;";
String found = execLexer("L.g", grammar, "L", "a x"); String found = execLexer("L.g4", grammar, "L", "a x");
String expecting = String expecting =
"I\n" + "I\n" +
"I\n" + "I\n" +
@ -294,7 +294,7 @@ public class TestLexerExec extends BaseTest {
"I : [0-9]+ {System.out.println(\"I\");} ;\n"+ "I : [0-9]+ {System.out.println(\"I\");} ;\n"+
"ID : [a-zA-Z] [a-zA-Z0-9]* {System.out.println(\"ID\");} ;\n"+ "ID : [a-zA-Z] [a-zA-Z0-9]* {System.out.println(\"ID\");} ;\n"+
"WS : [ \\n\\u0009\r]+ -> skip ;"; "WS : [ \\n\\u0009\r]+ -> skip ;";
String found = execLexer("L.g", grammar, "L", "34\r 34 a2 abc \n "); String found = execLexer("L.g4", grammar, "L", "34\r 34 a2 abc \n ");
String expecting = String expecting =
"I\n" + "I\n" +
"I\n" + "I\n" +
@ -313,7 +313,7 @@ public class TestLexerExec extends BaseTest {
"lexer grammar L;\n"+ "lexer grammar L;\n"+
"I : [0-]+ {System.out.println(\"I\");} ;\n"+ "I : [0-]+ {System.out.println(\"I\");} ;\n"+
"WS : [ \\n\\u000D]+ -> skip ;"; "WS : [ \\n\\u000D]+ -> skip ;";
String found = execLexer("L.g", grammar, "L", "00\r\n"); String found = execLexer("L.g4", grammar, "L", "00\r\n");
String expecting = String expecting =
"I\n" + "I\n" +
"[@0,0:1='00',<3>,1:0]\n" + "[@0,0:1='00',<3>,1:0]\n" +
@ -326,7 +326,7 @@ public class TestLexerExec extends BaseTest {
"lexer grammar L;\n"+ "lexer grammar L;\n"+
"I : [0-9]+ {System.out.println(\"I\");} ;\n"+ "I : [0-9]+ {System.out.println(\"I\");} ;\n"+
"WS : [ \\u]+ -> skip ;"; "WS : [ \\u]+ -> skip ;";
String found = execLexer("L.g", grammar, "L", "34 "); String found = execLexer("L.g4", grammar, "L", "34 ");
String expecting = String expecting =
"I\n" + "I\n" +
"[@0,0:1='34',<3>,1:0]\n" + "[@0,0:1='34',<3>,1:0]\n" +
@ -339,7 +339,7 @@ public class TestLexerExec extends BaseTest {
"lexer grammar L;\n"+ "lexer grammar L;\n"+
"DASHBRACK : [\\-\\]]+ {System.out.println(\"DASHBRACK\");} ;\n"+ "DASHBRACK : [\\-\\]]+ {System.out.println(\"DASHBRACK\");} ;\n"+
"WS : [ \\u]+ -> skip ;"; "WS : [ \\u]+ -> skip ;";
String found = execLexer("L.g", grammar, "L", "- ] "); String found = execLexer("L.g4", grammar, "L", "- ] ");
String expecting = String expecting =
"DASHBRACK\n" + "DASHBRACK\n" +
"DASHBRACK\n" + "DASHBRACK\n" +
@ -354,7 +354,7 @@ public class TestLexerExec extends BaseTest {
"lexer grammar L;\n"+ "lexer grammar L;\n"+
"A : [z-a9]+ {System.out.println(\"A\");} ;\n"+ "A : [z-a9]+ {System.out.println(\"A\");} ;\n"+
"WS : [ \\u]+ -> skip ;"; "WS : [ \\u]+ -> skip ;";
String found = execLexer("L.g", grammar, "L", "9"); String found = execLexer("L.g4", grammar, "L", "9");
String expecting = String expecting =
"A\n" + "A\n" +
"[@0,0:0='9',<3>,1:0]\n" + "[@0,0:0='9',<3>,1:0]\n" +
@ -367,7 +367,7 @@ public class TestLexerExec extends BaseTest {
"lexer grammar L;\n"+ "lexer grammar L;\n"+
"A : [\"a-z]+ {System.out.println(\"A\");} ;\n"+ "A : [\"a-z]+ {System.out.println(\"A\");} ;\n"+
"WS : [ \n\t]+ -> skip ;"; "WS : [ \n\t]+ -> skip ;";
String found = execLexer("L.g", grammar, "L", "b\"a"); String found = execLexer("L.g4", grammar, "L", "b\"a");
String expecting = String expecting =
"A\n" + "A\n" +
"[@0,0:2='b\"a',<3>,1:0]\n" + "[@0,0:2='b\"a',<3>,1:0]\n" +
@ -380,7 +380,7 @@ public class TestLexerExec extends BaseTest {
"lexer grammar L;\n"+ "lexer grammar L;\n"+
"A : [\"\\\\ab]+ {System.out.println(\"A\");} ;\n"+ "A : [\"\\\\ab]+ {System.out.println(\"A\");} ;\n"+
"WS : [ \n\t]+ -> skip ;"; "WS : [ \n\t]+ -> skip ;";
String found = execLexer("L.g", grammar, "L", "b\"\\a"); String found = execLexer("L.g4", grammar, "L", "b\"\\a");
String expecting = String expecting =
"A\n" + "A\n" +
"[@0,0:3='b\"\\a',<3>,1:0]\n" + "[@0,0:3='b\"\\a',<3>,1:0]\n" +

View File

@ -28,7 +28,7 @@ public class TestListeners extends BaseTest {
"INT : [0-9]+ ;\n" + "INT : [0-9]+ ;\n" +
"ID : [a-z]+ ;\n" + "ID : [a-z]+ ;\n" +
"WS : [ \\t\\n]+ -> skip ;\n"; "WS : [ \\t\\n]+ -> skip ;\n";
String result = execParser("T.g", grammar, "TParser", "TLexer", "s", "1 2", false); String result = execParser("T.g4", grammar, "TParser", "TLexer", "s", "1 2", false);
String expecting = "(a 1 2)\n" + String expecting = "(a 1 2)\n" +
"1\n" + "1\n" +
"2\n"; "2\n";
@ -61,13 +61,13 @@ public class TestListeners extends BaseTest {
"INT : [0-9]+ ;\n" + "INT : [0-9]+ ;\n" +
"ID : [a-z]+ ;\n" + "ID : [a-z]+ ;\n" +
"WS : [ \\t\\n]+ -> skip ;\n"; "WS : [ \\t\\n]+ -> skip ;\n";
String result = execParser("T.g", grammar, "TParser", "TLexer", "s", "1 2", false); String result = execParser("T.g4", grammar, "TParser", "TLexer", "s", "1 2", false);
String expecting = String expecting =
"(a 1 2)\n" + "(a 1 2)\n" +
"1 2 [1, 2]\n"; "1 2 [1, 2]\n";
assertEquals(expecting, result); assertEquals(expecting, result);
result = execParser("T.g", grammar, "TParser", "TLexer", "s", "abc", false); result = execParser("T.g4", grammar, "TParser", "TLexer", "s", "abc", false);
expecting = "(a abc)\n" + expecting = "(a abc)\n" +
"[@0,0:2='abc',<6>,1:0]\n"; "[@0,0:2='abc',<6>,1:0]\n";
assertEquals(expecting, result); assertEquals(expecting, result);
@ -103,12 +103,12 @@ public class TestListeners extends BaseTest {
"INT : [0-9]+ ;\n" + "INT : [0-9]+ ;\n" +
"ID : [a-z]+ ;\n" + "ID : [a-z]+ ;\n" +
"WS : [ \\t\\n]+ -> skip ;\n"; "WS : [ \\t\\n]+ -> skip ;\n";
String result = execParser("T.g", grammar, "TParser", "TLexer", "s", "1 2", false); String result = execParser("T.g4", grammar, "TParser", "TLexer", "s", "1 2", false);
String expecting = "(a (b 1) (b 2))\n" + String expecting = "(a (b 1) (b 2))\n" +
"1 2 1\n"; "1 2 1\n";
assertEquals(expecting, result); assertEquals(expecting, result);
result = execParser("T.g", grammar, "TParser", "TLexer", "s", "abc", false); result = execParser("T.g4", grammar, "TParser", "TLexer", "s", "abc", false);
expecting = "(a (b abc))\n" + expecting = "(a (b abc))\n" +
"abc\n"; "abc\n";
assertEquals(expecting, result); assertEquals(expecting, result);
@ -145,7 +145,7 @@ public class TestListeners extends BaseTest {
"ADD : '+' ;\n" + "ADD : '+' ;\n" +
"INT : [0-9]+ ;\n" + "INT : [0-9]+ ;\n" +
"WS : [ \\t\\n]+ -> skip ;\n"; "WS : [ \\t\\n]+ -> skip ;\n";
String result = execParser("T.g", grammar, "TParser", "TLexer", "s", "1+2*3", false); String result = execParser("T.g4", grammar, "TParser", "TLexer", "s", "1+2*3", false);
String expecting = String expecting =
"(e (e 1) + (e (e 2) * (e 3)))\n" + "(e (e 1) + (e (e 2) * (e 3)))\n" +
"1\n" + "1\n" +
@ -186,7 +186,7 @@ public class TestListeners extends BaseTest {
"ADD : '+' ;\n" + "ADD : '+' ;\n" +
"INT : [0-9]+ ;\n" + "INT : [0-9]+ ;\n" +
"WS : [ \\t\\n]+ -> skip ;\n"; "WS : [ \\t\\n]+ -> skip ;\n";
String result = execParser("T.g", grammar, "TParser", "TLexer", "s", "1(2,3)", false); String result = execParser("T.g4", grammar, "TParser", "TLexer", "s", "1(2,3)", false);
String expecting = String expecting =
"(e (e 1) ( (eList (e 2) , (e 3)) ))\n" + "(e (e 1) ( (eList (e 2) , (e 3)) ))\n" +
"1\n" + "1\n" +

View File

@ -40,14 +40,14 @@ public class TestNonGreedyLoops extends BaseTest {
"INT : '0'..'9'+ ;\n" + "INT : '0'..'9'+ ;\n" +
"ID : 'a'..'z'+ ;\n" + "ID : 'a'..'z'+ ;\n" +
"WS : (' '|'\\n')+ {skip();} ;\n"; "WS : (' '|'\\n')+ {skip();} ;\n";
String found = execParser("T.g", grammar, "TParser", "TLexer", "s", String found = execParser("T.g4", grammar, "TParser", "TLexer", "s",
"x", true); "x", true);
assertEquals("x\n" + assertEquals("x\n" +
"Decision 0:\n" + "Decision 0:\n" +
"s0-ID->:s1=>2\n", found); "s0-ID->:s1=>2\n", found);
assertEquals(null, this.stderrDuringParse); assertEquals(null, this.stderrDuringParse);
found = execParser("T.g", grammar, "TParser", "TLexer", "s", found = execParser("T.g4", grammar, "TParser", "TLexer", "s",
"34 x", true); "34 x", true);
assertEquals("34x\n" + assertEquals("34x\n" +
"Decision 0:\n" + "Decision 0:\n" +
@ -63,7 +63,7 @@ public class TestNonGreedyLoops extends BaseTest {
"INT : '0'..'9'+ ;\n" + "INT : '0'..'9'+ ;\n" +
"ID : 'a'..'z'+ ;\n" + "ID : 'a'..'z'+ ;\n" +
"WS : (' '|'\\n')+ {skip();} ;\n"; "WS : (' '|'\\n')+ {skip();} ;\n";
String found = execParser("T.g", grammar, "TParser", "TLexer", "s", String found = execParser("T.g4", grammar, "TParser", "TLexer", "s",
"x", true); "x", true);
assertEquals("x\n" + assertEquals("x\n" +
"Decision 0:\n" + "Decision 0:\n" +
@ -80,7 +80,7 @@ public class TestNonGreedyLoops extends BaseTest {
"INT : '0'..'9'+ ;\n" + "INT : '0'..'9'+ ;\n" +
"ID : 'a'..'z'+ ;\n" + "ID : 'a'..'z'+ ;\n" +
"WS : (' '|'\\n')+ {skip();} ;\n"; "WS : (' '|'\\n')+ {skip();} ;\n";
String found = execParser("T.g", grammar, "TParser", "TLexer", "s", String found = execParser("T.g4", grammar, "TParser", "TLexer", "s",
"x", true); "x", true);
assertEquals("alt 1\n" + assertEquals("alt 1\n" +
"Decision 0:\n" + "Decision 0:\n" +
@ -91,7 +91,7 @@ public class TestNonGreedyLoops extends BaseTest {
"s0-ID->:s1=>2\n", found); "s0-ID->:s1=>2\n", found);
assertEquals(null, this.stderrDuringParse); assertEquals(null, this.stderrDuringParse);
found = execParser("T.g", grammar, "TParser", "TLexer", "s", found = execParser("T.g4", grammar, "TParser", "TLexer", "s",
"34", true); "34", true);
assertEquals("alt 2\n" + assertEquals("alt 2\n" +
"Decision 0:\n" + "Decision 0:\n" +
@ -102,7 +102,7 @@ public class TestNonGreedyLoops extends BaseTest {
"s0-INT->:s1=>2\n", found); "s0-INT->:s1=>2\n", found);
assertEquals(null, this.stderrDuringParse); assertEquals(null, this.stderrDuringParse);
found = execParser("T.g", grammar, "TParser", "TLexer", "s", found = execParser("T.g4", grammar, "TParser", "TLexer", "s",
"34 x", true); "34 x", true);
assertEquals("alt 1\n" + assertEquals("alt 1\n" +
"Decision 0:\n" + "Decision 0:\n" +
@ -125,7 +125,7 @@ public class TestNonGreedyLoops extends BaseTest {
"INT : '0'..'9'+ ;\n" + "INT : '0'..'9'+ ;\n" +
"ID : 'a'..'z'+ ;\n" + "ID : 'a'..'z'+ ;\n" +
"WS : (' '|'\\n')+ {skip();} ;\n"; "WS : (' '|'\\n')+ {skip();} ;\n";
String found = execParser("T.g", grammar, "TParser", "TLexer", "s", String found = execParser("T.g4", grammar, "TParser", "TLexer", "s",
"2 3 x", true); "2 3 x", true);
assertEquals("alt 1\n" + assertEquals("alt 1\n" +
"Decision 0:\n" + "Decision 0:\n" +
@ -139,7 +139,7 @@ public class TestNonGreedyLoops extends BaseTest {
"s0-ID->:s2=>2\n", found); "s0-ID->:s2=>2\n", found);
assertEquals(null, this.stderrDuringParse); assertEquals(null, this.stderrDuringParse);
found = execParser("T.g", grammar, "TParser", "TLexer", "s", found = execParser("T.g4", grammar, "TParser", "TLexer", "s",
"2 3", true); "2 3", true);
assertEquals("alt 2\n" + assertEquals("alt 2\n" +
"Decision 0:\n" + "Decision 0:\n" +
@ -151,7 +151,7 @@ public class TestNonGreedyLoops extends BaseTest {
"s0-INT->:s1=>2\n", found); "s0-INT->:s1=>2\n", found);
assertEquals("line 1:0 no viable alternative at input '2'\n", this.stderrDuringParse); assertEquals("line 1:0 no viable alternative at input '2'\n", this.stderrDuringParse);
found = execParser("T.g", grammar, "TParser", "TLexer", "s", found = execParser("T.g4", grammar, "TParser", "TLexer", "s",
"a b c 3", true); "a b c 3", true);
assertEquals("alt 2\n" + assertEquals("alt 2\n" +
"Decision 0:\n" + "Decision 0:\n" +
@ -176,14 +176,14 @@ public class TestNonGreedyLoops extends BaseTest {
"INT : '0'..'9'+ ;\n" + "INT : '0'..'9'+ ;\n" +
"ID : 'a'..'z'+ ;\n" + "ID : 'a'..'z'+ ;\n" +
"WS : (' '|'\\n')+ {skip();} ;\n"; "WS : (' '|'\\n')+ {skip();} ;\n";
String found = execParser("T.g", grammar, "TParser", "TLexer", "s", String found = execParser("T.g4", grammar, "TParser", "TLexer", "s",
"x", true); "x", true);
assertEquals("alt 1\n" + assertEquals("alt 1\n" +
"Decision 0:\n" + "Decision 0:\n" +
"s0-ID->:s1=>1\n", found); "s0-ID->:s1=>1\n", found);
assertNull(this.stderrDuringParse); assertNull(this.stderrDuringParse);
found = execParser("T.g", grammar, "TParser", "TLexer", "s", found = execParser("T.g4", grammar, "TParser", "TLexer", "s",
"34", true); "34", true);
assertEquals("alt 1\n" + assertEquals("alt 1\n" +
"Decision 0:\n" + "Decision 0:\n" +
@ -204,14 +204,14 @@ public class TestNonGreedyLoops extends BaseTest {
"WS : (' '|'\\n')+ {skip();} ;\n"; "WS : (' '|'\\n')+ {skip();} ;\n";
String input = String input =
"{ }"; "{ }";
String found = execParser("T.g", grammar, "TParser", "TLexer", "s", String found = execParser("T.g4", grammar, "TParser", "TLexer", "s",
input, true); input, true);
assertEquals("{}\n" + assertEquals("{}\n" +
"Decision 0:\n" + "Decision 0:\n" +
"s0-'}'->:s1=>2\n", found); "s0-'}'->:s1=>2\n", found);
input = input =
"{a b { }"; "{a b { }";
found = execParser("T.g", grammar, "TParser", "TLexer", "s", found = execParser("T.g4", grammar, "TParser", "TLexer", "s",
input, true); input, true);
assertEquals("{ab{}\n" + assertEquals("{ab{}\n" +
"Decision 0:\n" + "Decision 0:\n" +
@ -220,7 +220,7 @@ public class TestNonGreedyLoops extends BaseTest {
"s0-ID->:s1=>1\n", found); "s0-ID->:s1=>1\n", found);
input = input =
"{ } a 2 { }"; // FAILS to match since it terminates loop at first { } "{ } a 2 { }"; // FAILS to match since it terminates loop at first { }
found = execParser("T.g", grammar, "TParser", "TLexer", "s", found = execParser("T.g4", grammar, "TParser", "TLexer", "s",
input, true); input, true);
assertEquals("", found); // should not print output; resync kills rest of input til '}' then returns normally assertEquals("", found); // should not print output; resync kills rest of input til '}' then returns normally
} }
@ -237,7 +237,7 @@ public class TestNonGreedyLoops extends BaseTest {
"WS : (' '|'\\n')+ {skip();} ;\n"; "WS : (' '|'\\n')+ {skip();} ;\n";
String input = String input =
"if ( x=34 ) { } ;"; "if ( x=34 ) { } ;";
String found = execParser("T.g", grammar, "TParser", "TLexer", "s", String found = execParser("T.g4", grammar, "TParser", "TLexer", "s",
input, true); input, true);
assertEquals("if(x=34){};\n" + assertEquals("if(x=34){};\n" +
"Decision 0:\n" + "Decision 0:\n" +
@ -249,7 +249,7 @@ public class TestNonGreedyLoops extends BaseTest {
"s3-'}'->:s4=>2\n", found); "s3-'}'->:s4=>2\n", found);
input = input =
"if ( ))) ) { } ;"; "if ( ))) ) { } ;";
found = execParser("T.g", grammar, "TParser", "TLexer", "s", found = execParser("T.g4", grammar, "TParser", "TLexer", "s",
input, true); input, true);
assertEquals("if()))){};\n" + assertEquals("if()))){};\n" +
"Decision 0:\n" + "Decision 0:\n" +
@ -259,7 +259,7 @@ public class TestNonGreedyLoops extends BaseTest {
"s3-'}'->:s4=>2\n", found); "s3-'}'->:s4=>2\n", found);
input = input =
"if (() { } a 2) { } ;"; // The first { } should match block so should stop "if (() { } a 2) { } ;"; // The first { } should match block so should stop
found = execParser("T.g", grammar, "TParser", "TLexer", "s", found = execParser("T.g4", grammar, "TParser", "TLexer", "s",
input, true); input, true);
assertEquals("", found); // should not finish to print output assertEquals("", found); // should not finish to print output
} }
@ -276,7 +276,7 @@ public class TestNonGreedyLoops extends BaseTest {
"WS : (' '|'\\n')+ {skip();} ;\n"; "WS : (' '|'\\n')+ {skip();} ;\n";
String input = String input =
"if ( x=34 ) { {return a} b 34 } ;"; "if ( x=34 ) { {return a} b 34 } ;";
String found = execParser("T.g", grammar, "TParser", "TLexer", "s", String found = execParser("T.g4", grammar, "TParser", "TLexer", "s",
input, true); input, true);
assertEquals("if(x=34){{returna}b34};\n" + assertEquals("if(x=34){{returna}b34};\n" +
"Decision 0:\n" + "Decision 0:\n" +
@ -302,7 +302,7 @@ public class TestNonGreedyLoops extends BaseTest {
input = input =
"if ( ()) ) { {return a} b 34 } ;"; "if ( ()) ) { {return a} b 34 } ;";
found = execParser("T.g", grammar, "TParser", "TLexer", "s", found = execParser("T.g4", grammar, "TParser", "TLexer", "s",
input, true); input, true);
assertEquals("if(())){{returna}b34};\n" + assertEquals("if(())){{returna}b34};\n" +
"Decision 0:\n" + "Decision 0:\n" +
@ -344,7 +344,7 @@ public class TestNonGreedyLoops extends BaseTest {
String input = String input =
"x=1; a=b;"; "x=1; a=b;";
String found = null; String found = null;
found = execParser("T.g", grammar, "TParser", "TLexer", "s", found = execParser("T.g4", grammar, "TParser", "TLexer", "s",
input, true); input, true);
assertEquals("x=1;a=b;\n" + assertEquals("x=1;a=b;\n" +
"Decision 0:\n" + "Decision 0:\n" +
@ -356,7 +356,7 @@ public class TestNonGreedyLoops extends BaseTest {
"s5-EOF->:s6=>2\n", found); "s5-EOF->:s6=>2\n", found);
input = input =
"if ( 1 ) { x=3; { return 4; } } return 99; abc=def;"; "if ( 1 ) { x=3; { return 4; } } return 99; abc=def;";
found = execParser("T.g", grammar, "TParser", "TLexer", "s", found = execParser("T.g4", grammar, "TParser", "TLexer", "s",
input, true); input, true);
assertEquals("if(1){x=3;{return4;}}return99;abc=def;\n" + assertEquals("if(1){x=3;{return4;}}return99;abc=def;\n" +
"Decision 0:\n" + "Decision 0:\n" +
@ -369,7 +369,7 @@ public class TestNonGreedyLoops extends BaseTest {
"s6-EOF->:s7=>2\n", found); "s6-EOF->:s7=>2\n", found);
input = input =
"x=1; a=3;"; // FAILS to match since it can't match last element "x=1; a=3;"; // FAILS to match since it can't match last element
execParser("T.g", grammar, "TParser", "TLexer", "s", execParser("T.g4", grammar, "TParser", "TLexer", "s",
input, true); input, true);
// can't match EOF to ID '=' '3' ';' // can't match EOF to ID '=' '3' ';'
assertEquals("line 1:9 no viable alternative at input '<EOF>'\n", assertEquals("line 1:9 no viable alternative at input '<EOF>'\n",
@ -377,7 +377,7 @@ public class TestNonGreedyLoops extends BaseTest {
input = input =
"x=1; a=b; z=3;"; // FAILS to match since it can't match last element "x=1; a=b; z=3;"; // FAILS to match since it can't match last element
execParser("T.g", grammar, "TParser", "TLexer", "s", execParser("T.g4", grammar, "TParser", "TLexer", "s",
input, true); input, true);
assertEquals("line 1:14 no viable alternative at input '<EOF>'\n", assertEquals("line 1:14 no viable alternative at input '<EOF>'\n",
this.stderrDuringParse); this.stderrDuringParse);
@ -406,7 +406,7 @@ public class TestNonGreedyLoops extends BaseTest {
String input = String input =
"x=1; a=b; x=y;"; "x=1; a=b; x=y;";
String found = null; String found = null;
found = execParser("T.g", grammar, "TParser", "TLexer", "s", found = execParser("T.g4", grammar, "TParser", "TLexer", "s",
input, true); input, true);
assertEquals("x=1;a=b;\n" + assertEquals("x=1;a=b;\n" +
"Decision 0:\n" + "Decision 0:\n" +
@ -417,7 +417,7 @@ public class TestNonGreedyLoops extends BaseTest {
"s4-';'->:s5=>2\n", found); // ignores x=1 that follows first a=b assignment "s4-';'->:s5=>2\n", found); // ignores x=1 that follows first a=b assignment
input = input =
"if ( 1 ) { x=3; { return 4; } } return 99; abc=def;"; "if ( 1 ) { x=3; { return 4; } } return 99; abc=def;";
found = execParser("T.g", grammar, "TParser", "TLexer", "s", found = execParser("T.g4", grammar, "TParser", "TLexer", "s",
input, true); input, true);
assertEquals("if(1){x=3;{return4;}}return99;abc=def;\n" + assertEquals("if(1){x=3;{return4;}}return99;abc=def;\n" +
"Decision 0:\n" + "Decision 0:\n" +
@ -429,14 +429,14 @@ public class TestNonGreedyLoops extends BaseTest {
"s5-';'->:s6=>2\n", found); "s5-';'->:s6=>2\n", found);
input = input =
"x=1; a=3;"; // FAILS to match since it can't match either stat "x=1; a=3;"; // FAILS to match since it can't match either stat
execParser("T.g", grammar, "TParser", "TLexer", "s", execParser("T.g4", grammar, "TParser", "TLexer", "s",
input, true); input, true);
// can't match EOF to ID '=' '0' ';' // can't match EOF to ID '=' '0' ';'
assertEquals("line 1:9 no viable alternative at input '<EOF>'\n", assertEquals("line 1:9 no viable alternative at input '<EOF>'\n",
this.stderrDuringParse); this.stderrDuringParse);
input = input =
"x=1; a=b; z=3;"; // stops at a=b; ignores z=3; "x=1; a=b; z=3;"; // stops at a=b; ignores z=3;
found = execParser("T.g", grammar, "TParser", "TLexer", "s", found = execParser("T.g4", grammar, "TParser", "TLexer", "s",
input, true); input, true);
assertEquals("x=1;a=b;\n" + assertEquals("x=1;a=b;\n" +
"Decision 0:\n" + "Decision 0:\n" +
@ -461,7 +461,7 @@ public class TestNonGreedyLoops extends BaseTest {
"WS : (' '|'\\n') {skip();} ;\n"; "WS : (' '|'\\n') {skip();} ;\n";
String found = null; String found = null;
found = execParser("T.g", grammar, "TParser", "TLexer", "s", found = execParser("T.g4", grammar, "TParser", "TLexer", "s",
"<a>foo</a>", true); "<a>foo</a>", true);
assertEquals("<a>foo</a>\n" + assertEquals("<a>foo</a>\n" +
"Decision 1:\n" + "Decision 1:\n" +
@ -489,7 +489,7 @@ public class TestNonGreedyLoops extends BaseTest {
"line 1:7 reportAmbiguity d=2: ambigAlts={1..2}, input='/'\n", "line 1:7 reportAmbiguity d=2: ambigAlts={1..2}, input='/'\n",
this.stderrDuringParse); this.stderrDuringParse);
found = execParser("T.g", grammar, "TParser", "TLexer", "s", found = execParser("T.g4", grammar, "TParser", "TLexer", "s",
"<a></a>", true); "<a></a>", true);
assertEquals("<a></a>\n" + assertEquals("<a></a>\n" +
"Decision 1:\n" + "Decision 1:\n" +
@ -508,7 +508,7 @@ public class TestNonGreedyLoops extends BaseTest {
"Decision 3:\n" + "Decision 3:\n" +
"s0-'>'->:s2=>2\n" + "s0-'>'->:s2=>2\n" +
"s0-ID->:s1=>1\n", found); "s0-ID->:s1=>1\n", found);
found = execParser("T.g", grammar, "TParser", "TLexer", "s", found = execParser("T.g4", grammar, "TParser", "TLexer", "s",
"</b><a src=\"abc\", width=32>", true); "</b><a src=\"abc\", width=32>", true);
assertEquals("</b><asrc=\"abc\",width=32>\n" + assertEquals("</b><asrc=\"abc\",width=32>\n" +
"Decision 1:\n" + "Decision 1:\n" +
@ -556,7 +556,7 @@ public class TestNonGreedyLoops extends BaseTest {
String found = null; String found = null;
System.out.println(grammar); System.out.println(grammar);
found = execParser("T.g", grammar, "TParser", "TLexer", "s", found = execParser("T.g4", grammar, "TParser", "TLexer", "s",
",=foo <a x= 3>32skidoo<a><img>", true); ",=foo <a x= 3>32skidoo<a><img>", true);
assertEquals("<ax=3>\n" + assertEquals("<ax=3>\n" +
"<a>\n" + "<a>\n" +
@ -582,7 +582,7 @@ public class TestNonGreedyLoops extends BaseTest {
assertEquals(null, assertEquals(null,
this.stderrDuringParse); this.stderrDuringParse);
found = execParser("T.g", grammar, "TParser", "TLexer", "s", found = execParser("T.g4", grammar, "TParser", "TLexer", "s",
"x x<a>", true); "x x<a>", true);
assertEquals("<a>\n" + assertEquals("<a>\n" +
"Decision 0:\n" + "Decision 0:\n" +
@ -599,7 +599,7 @@ public class TestNonGreedyLoops extends BaseTest {
// gets line 1:3 no viable alternative at input '>'. Why?? // gets line 1:3 no viable alternative at input '>'. Why??
// oH! it sees .+ and figures it matches > so <> predicts tag CORRECT! // oH! it sees .+ and figures it matches > so <> predicts tag CORRECT!
// Seeing '.' in a lookahead prediction can be misleading!! // Seeing '.' in a lookahead prediction can be misleading!!
found = execParser("T.g", grammar, "TParser", "TLexer", "s", found = execParser("T.g4", grammar, "TParser", "TLexer", "s",
"x <><a>", true); "x <><a>", true);
assertEquals("<\n" + assertEquals("<\n" +
"<a>\n" + "<a>\n" +

View File

@ -37,7 +37,7 @@ public class TestParseErrors extends BaseTest {
String grammar = String grammar =
"grammar T;\n" + "grammar T;\n" +
"a : 'a' 'b' ;"; "a : 'a' 'b' ;";
String found = execParser("T.g", grammar, "TParser", "TLexer", "a", "aa", false); String found = execParser("T.g4", grammar, "TParser", "TLexer", "a", "aa", false);
String expecting = "line 1:1 mismatched input 'a' expecting 'b'\n"; String expecting = "line 1:1 mismatched input 'a' expecting 'b'\n";
String result = stderrDuringParse; String result = stderrDuringParse;
assertEquals(expecting, result); assertEquals(expecting, result);
@ -47,7 +47,7 @@ public class TestParseErrors extends BaseTest {
String grammar = String grammar =
"grammar T;\n" + "grammar T;\n" +
"a : 'a' 'b' ;"; "a : 'a' 'b' ;";
String found = execParser("T.g", grammar, "TParser", "TLexer", "a", "aab", false); String found = execParser("T.g4", grammar, "TParser", "TLexer", "a", "aab", false);
String expecting = "line 1:1 extraneous input 'a' expecting 'b'\n"; String expecting = "line 1:1 extraneous input 'a' expecting 'b'\n";
String result = stderrDuringParse; String result = stderrDuringParse;
assertEquals(expecting, result); assertEquals(expecting, result);
@ -57,7 +57,7 @@ public class TestParseErrors extends BaseTest {
String grammar = String grammar =
"grammar T;\n" + "grammar T;\n" +
"a : 'a' ('b'|'c') ;"; "a : 'a' ('b'|'c') ;";
String found = execParser("T.g", grammar, "TParser", "TLexer", "a", "aab", false); String found = execParser("T.g4", grammar, "TParser", "TLexer", "a", "aab", false);
String expecting = "line 1:1 extraneous input 'a' expecting {'b', 'c'}\n"; String expecting = "line 1:1 extraneous input 'a' expecting {'b', 'c'}\n";
String result = stderrDuringParse; String result = stderrDuringParse;
assertEquals(expecting, result); assertEquals(expecting, result);
@ -67,7 +67,7 @@ public class TestParseErrors extends BaseTest {
String grammar = String grammar =
"grammar T;\n" + "grammar T;\n" +
"a : 'a' 'b' 'c' ;"; "a : 'a' 'b' 'c' ;";
String found = execParser("T.g", grammar, "TParser", "TLexer", "a", "ac", false); String found = execParser("T.g4", grammar, "TParser", "TLexer", "a", "ac", false);
String expecting = "line 1:1 missing 'b' at 'c'\n"; String expecting = "line 1:1 missing 'b' at 'c'\n";
String result = stderrDuringParse; String result = stderrDuringParse;
assertEquals(expecting, result); assertEquals(expecting, result);
@ -77,7 +77,7 @@ public class TestParseErrors extends BaseTest {
String grammar = String grammar =
"grammar T;\n" + "grammar T;\n" +
"a : 'a' x='b' {System.out.println(\"conjured=\"+$x);} 'c' ;"; "a : 'a' x='b' {System.out.println(\"conjured=\"+$x);} 'c' ;";
String result = execParser("T.g", grammar, "TParser", "TLexer", "a", "ac", false); String result = execParser("T.g4", grammar, "TParser", "TLexer", "a", "ac", false);
String expecting = "conjured=[@-1,-1:-1='<missing 'b'>',<3>,1:1]\n"; String expecting = "conjured=[@-1,-1:-1='<missing 'b'>',<3>,1:1]\n";
assertEquals(expecting, result); assertEquals(expecting, result);
} }
@ -86,7 +86,7 @@ public class TestParseErrors extends BaseTest {
String grammar = String grammar =
"grammar T;\n" + "grammar T;\n" +
"a : 'a' ('b'|'c') 'd' ;"; "a : 'a' ('b'|'c') 'd' ;";
String found = execParser("T.g", grammar, "TParser", "TLexer", "a", "ad", false); String found = execParser("T.g4", grammar, "TParser", "TLexer", "a", "ad", false);
String expecting = "line 1:1 missing {'b', 'c'} at 'd'\n"; String expecting = "line 1:1 missing {'b', 'c'} at 'd'\n";
String result = stderrDuringParse; String result = stderrDuringParse;
assertEquals(expecting, result); assertEquals(expecting, result);
@ -96,7 +96,7 @@ public class TestParseErrors extends BaseTest {
String grammar = String grammar =
"grammar T;\n" + "grammar T;\n" +
"a : 'a' x=('b'|'c') {System.out.println(\"conjured=\"+$x);} 'd' ;"; "a : 'a' x=('b'|'c') {System.out.println(\"conjured=\"+$x);} 'd' ;";
String result = execParser("T.g", grammar, "TParser", "TLexer", "a", "ad", false); String result = execParser("T.g4", grammar, "TParser", "TLexer", "a", "ad", false);
String expecting = "conjured=[@-1,-1:-1='<missing 'b'>',<3>,1:1]\n"; String expecting = "conjured=[@-1,-1:-1='<missing 'b'>',<3>,1:1]\n";
assertEquals(expecting, result); assertEquals(expecting, result);
} }
@ -108,7 +108,7 @@ public class TestParseErrors extends BaseTest {
" | 'a' 'c'" + " | 'a' 'c'" +
";\n" + ";\n" +
"q : 'e' ;\n"; "q : 'e' ;\n";
String found = execParser("T.g", grammar, "TParser", "TLexer", "a", "ae", false); String found = execParser("T.g4", grammar, "TParser", "TLexer", "a", "ae", false);
String expecting = "line 1:1 no viable alternative at input 'ae'\n"; String expecting = "line 1:1 no viable alternative at input 'ae'\n";
String result = stderrDuringParse; String result = stderrDuringParse;
assertEquals(expecting, result); assertEquals(expecting, result);
@ -122,7 +122,7 @@ public class TestParseErrors extends BaseTest {
" ;\n" + " ;\n" +
"q : 'e' ;\n"; "q : 'e' ;\n";
System.out.println(grammar); System.out.println(grammar);
String found = execParser("T.g", grammar, "TParser", "TLexer", "a", "abe", false); String found = execParser("T.g4", grammar, "TParser", "TLexer", "a", "abe", false);
String expecting = "line 1:2 no viable alternative at input 'abe'\n"; String expecting = "line 1:2 no viable alternative at input 'abe'\n";
String result = stderrDuringParse; String result = stderrDuringParse;
assertEquals(expecting, result); assertEquals(expecting, result);
@ -135,7 +135,7 @@ public class TestParseErrors extends BaseTest {
" | 'a'+ 'c'" + " | 'a'+ 'c'" +
";\n" + ";\n" +
"q : 'e' ;\n"; "q : 'e' ;\n";
String found = execParser("T.g", grammar, "TParser", "TLexer", "a", "aaae", false); String found = execParser("T.g4", grammar, "TParser", "TLexer", "a", "aaae", false);
String expecting = "line 1:3 no viable alternative at input 'aaae'\n"; String expecting = "line 1:3 no viable alternative at input 'aaae'\n";
String result = stderrDuringParse; String result = stderrDuringParse;
assertEquals(expecting, result); assertEquals(expecting, result);
@ -145,7 +145,7 @@ public class TestParseErrors extends BaseTest {
String grammar = String grammar =
"grammar T;\n" + "grammar T;\n" +
"a : 'a' 'b'*;"; "a : 'a' 'b'*;";
String found = execParser("T.g", grammar, "TParser", "TLexer", "a", "aabc", false); String found = execParser("T.g4", grammar, "TParser", "TLexer", "a", "aabc", false);
String expecting = "line 1:1 extraneous input 'a' expecting {<EOF>, 'b'}\n" + String expecting = "line 1:1 extraneous input 'a' expecting {<EOF>, 'b'}\n" +
"line 1:3 token recognition error at: 'c'\n"; "line 1:3 token recognition error at: 'c'\n";
String result = stderrDuringParse; String result = stderrDuringParse;
@ -157,7 +157,7 @@ public class TestParseErrors extends BaseTest {
String grammar = String grammar =
"grammar T;\n" + "grammar T;\n" +
"a : 'a' 'b'* 'c';"; "a : 'a' 'b'* 'c';";
String found = execParser("T.g", grammar, "TParser", "TLexer", "a", "aacabc", false); String found = execParser("T.g4", grammar, "TParser", "TLexer", "a", "aacabc", false);
String expecting = String expecting =
"line 1:1 extraneous input 'a' expecting {'b', 'c'}\n"; "line 1:1 extraneous input 'a' expecting {'b', 'c'}\n";
String result = stderrDuringParse; String result = stderrDuringParse;
@ -168,7 +168,7 @@ public class TestParseErrors extends BaseTest {
String grammar = String grammar =
"grammar T;\n" + "grammar T;\n" +
"a : 'a' 'b'* 'c' ;"; "a : 'a' 'b'* 'c' ;";
String found = execParser("T.g", grammar, "TParser", "TLexer", "a", "ababbc", false); String found = execParser("T.g4", grammar, "TParser", "TLexer", "a", "ababbc", false);
String expecting = "line 1:2 extraneous input 'a' expecting {'b', 'c'}\n"; String expecting = "line 1:2 extraneous input 'a' expecting {'b', 'c'}\n";
String result = stderrDuringParse; String result = stderrDuringParse;
assertEquals(expecting, result); assertEquals(expecting, result);
@ -178,7 +178,7 @@ public class TestParseErrors extends BaseTest {
String grammar = String grammar =
"grammar T;\n" + "grammar T;\n" +
"a : 'a' 'b'* 'c' ;"; "a : 'a' 'b'* 'c' ;";
String found = execParser("T.g", grammar, "TParser", "TLexer", "a", "abaaababc", false); String found = execParser("T.g4", grammar, "TParser", "TLexer", "a", "abaaababc", false);
String expecting = String expecting =
"line 1:2 extraneous input 'a' expecting {'b', 'c'}\n" + "line 1:2 extraneous input 'a' expecting {'b', 'c'}\n" +
"line 1:6 extraneous input 'a' expecting {'b', 'c'}\n"; "line 1:6 extraneous input 'a' expecting {'b', 'c'}\n";
@ -192,7 +192,7 @@ public class TestParseErrors extends BaseTest {
String grammar = String grammar =
"grammar T;\n" + "grammar T;\n" +
"a : 'a' ('b'|'z'{;})*;"; "a : 'a' ('b'|'z'{;})*;";
String found = execParser("T.g", grammar, "TParser", "TLexer", "a", "aabc", false); String found = execParser("T.g4", grammar, "TParser", "TLexer", "a", "aabc", false);
String expecting = "line 1:1 extraneous input 'a' expecting {<EOF>, 'b', 'z'}\n" + String expecting = "line 1:1 extraneous input 'a' expecting {<EOF>, 'b', 'z'}\n" +
"line 1:3 token recognition error at: 'c'\n"; "line 1:3 token recognition error at: 'c'\n";
String result = stderrDuringParse; String result = stderrDuringParse;
@ -204,7 +204,7 @@ public class TestParseErrors extends BaseTest {
String grammar = String grammar =
"grammar T;\n" + "grammar T;\n" +
"a : 'a' ('b'|'z'{;})* 'c';"; "a : 'a' ('b'|'z'{;})* 'c';";
String found = execParser("T.g", grammar, "TParser", "TLexer", "a", "aacabc", false); String found = execParser("T.g4", grammar, "TParser", "TLexer", "a", "aacabc", false);
String expecting = String expecting =
"line 1:1 extraneous input 'a' expecting {'b', 'z', 'c'}\n"; "line 1:1 extraneous input 'a' expecting {'b', 'z', 'c'}\n";
String result = stderrDuringParse; String result = stderrDuringParse;
@ -215,7 +215,7 @@ public class TestParseErrors extends BaseTest {
String grammar = String grammar =
"grammar T;\n" + "grammar T;\n" +
"a : 'a' ('b'|'z'{;})* 'c' ;"; "a : 'a' ('b'|'z'{;})* 'c' ;";
String found = execParser("T.g", grammar, "TParser", "TLexer", "a", "ababbc", false); String found = execParser("T.g4", grammar, "TParser", "TLexer", "a", "ababbc", false);
String expecting = "line 1:2 extraneous input 'a' expecting {'b', 'z', 'c'}\n"; String expecting = "line 1:2 extraneous input 'a' expecting {'b', 'z', 'c'}\n";
String result = stderrDuringParse; String result = stderrDuringParse;
assertEquals(expecting, result); assertEquals(expecting, result);
@ -225,7 +225,7 @@ public class TestParseErrors extends BaseTest {
String grammar = String grammar =
"grammar T;\n" + "grammar T;\n" +
"a : 'a' ('b'|'z'{;})* 'c' ;"; "a : 'a' ('b'|'z'{;})* 'c' ;";
String found = execParser("T.g", grammar, "TParser", "TLexer", "a", "abaaababc", false); String found = execParser("T.g4", grammar, "TParser", "TLexer", "a", "abaaababc", false);
String expecting = String expecting =
"line 1:2 extraneous input 'a' expecting {'b', 'z', 'c'}\n" + "line 1:2 extraneous input 'a' expecting {'b', 'z', 'c'}\n" +
"line 1:6 extraneous input 'a' expecting {'b', 'z', 'c'}\n"; "line 1:6 extraneous input 'a' expecting {'b', 'z', 'c'}\n";
@ -249,7 +249,7 @@ public class TestParseErrors extends BaseTest {
"@init\n" + "@init\n" +
"{ System.out.println(getExpectedTokens().toString(tokenNames)); }\n" + "{ System.out.println(getExpectedTokens().toString(tokenNames)); }\n" +
" : ;\n"; " : ;\n";
String result = execParser("T.g", grammar, "TParser", "TLexer", "start", "dog and software", false); String result = execParser("T.g4", grammar, "TParser", "TLexer", "start", "dog and software", false);
String expecting = "{'hardware', 'software'}\n"; String expecting = "{'hardware', 'software'}\n";
assertEquals(expecting, result); assertEquals(expecting, result);
} }
@ -271,7 +271,7 @@ public class TestParseErrors extends BaseTest {
"primary : ID;\n" + "primary : ID;\n" +
"ID : [a-z]+;\n" + "ID : [a-z]+;\n" +
"\n"; "\n";
String result = execParser("T.g", grammar, "TParser", "TLexer", "start", "x:x", true); String result = execParser("T.g4", grammar, "TParser", "TLexer", "start", "x:x", true);
String expecting = ""; String expecting = "";
assertEquals(expecting, result); assertEquals(expecting, result);
assertNull(this.stderrDuringParse); assertNull(this.stderrDuringParse);

View File

@ -11,7 +11,7 @@ public class TestParseTrees extends BaseTest {
"@after {System.out.println($r.ctx.toStringTree(this));}\n" + "@after {System.out.println($r.ctx.toStringTree(this));}\n" +
" :r=a ;\n" + " :r=a ;\n" +
"a : 'x' {System.out.println(getRuleInvocationStack());} ;\n"; "a : 'x' {System.out.println(getRuleInvocationStack());} ;\n";
String result = execParser("T.g", grammar, "TParser", "TLexer", "s", "x", false); String result = execParser("T.g4", grammar, "TParser", "TLexer", "s", "x", false);
String expecting = "[a, s]\n(a x)\n"; String expecting = "[a, s]\n(a x)\n";
assertEquals(expecting, result); assertEquals(expecting, result);
} }
@ -25,7 +25,7 @@ public class TestParseTrees extends BaseTest {
" :r=a ;\n" + " :r=a ;\n" +
"a : 'x' 'y'\n" + "a : 'x' 'y'\n" +
" ;\n"; " ;\n";
String result = execParser("T.g", grammar, "TParser", "TLexer", "s", "xy", false); String result = execParser("T.g4", grammar, "TParser", "TLexer", "s", "xy", false);
String expecting = "(a x y)\n"; String expecting = "(a x y)\n";
assertEquals(expecting, result); assertEquals(expecting, result);
} }
@ -39,7 +39,7 @@ public class TestParseTrees extends BaseTest {
" :r=a ;\n" + " :r=a ;\n" +
"a : 'x' | 'y'\n" + "a : 'x' | 'y'\n" +
" ;\n"; " ;\n";
String result = execParser("T.g", grammar, "TParser", "TLexer", "s", "y", false); String result = execParser("T.g4", grammar, "TParser", "TLexer", "s", "y", false);
String expecting = "(a y)\n"; String expecting = "(a y)\n";
assertEquals(expecting, result); assertEquals(expecting, result);
} }
@ -53,7 +53,7 @@ public class TestParseTrees extends BaseTest {
" :r=a ;\n" + " :r=a ;\n" +
"a : ('x' | 'y')* 'z'\n" + "a : ('x' | 'y')* 'z'\n" +
" ;\n"; " ;\n";
String result = execParser("T.g", grammar, "TParser", "TLexer", "s", "xyyxyxz", false); String result = execParser("T.g4", grammar, "TParser", "TLexer", "s", "xyyxyxz", false);
String expecting = "(a x y y x y x z)\n"; String expecting = "(a x y y x y x z)\n";
assertEquals(expecting, result); assertEquals(expecting, result);
} }
@ -68,7 +68,7 @@ public class TestParseTrees extends BaseTest {
"a : b 'x'\n" + "a : b 'x'\n" +
" ;\n" + " ;\n" +
"b : 'y' ;\n"; "b : 'y' ;\n";
String result = execParser("T.g", grammar, "TParser", "TLexer", "s", "yx", false); String result = execParser("T.g4", grammar, "TParser", "TLexer", "s", "yx", false);
String expecting = "(a (b y) x)\n"; String expecting = "(a (b y) x)\n";
assertEquals(expecting, result); assertEquals(expecting, result);
} }
@ -85,7 +85,7 @@ public class TestParseTrees extends BaseTest {
"a : 'x' 'y'\n" + "a : 'x' 'y'\n" +
" ;\n" + " ;\n" +
"Z : 'z'; \n"; "Z : 'z'; \n";
String result = execParser("T.g", grammar, "TParser", "TLexer", "s", "xzy", false); String result = execParser("T.g4", grammar, "TParser", "TLexer", "s", "xzy", false);
String expecting = "(a x z y)\n"; // ERRORs not shown. z is colored red in tree view String expecting = "(a x z y)\n"; // ERRORs not shown. z is colored red in tree view
assertEquals(expecting, result); assertEquals(expecting, result);
} }
@ -100,7 +100,7 @@ public class TestParseTrees extends BaseTest {
"a : 'x' | 'y'\n" + "a : 'x' | 'y'\n" +
" ;\n" + " ;\n" +
"Z : 'z'; \n"; "Z : 'z'; \n";
String result = execParser("T.g", grammar, "TParser", "TLexer", "s", "z", false); String result = execParser("T.g4", grammar, "TParser", "TLexer", "s", "z", false);
String expecting = "(a z)\n"; String expecting = "(a z)\n";
assertEquals(expecting, result); assertEquals(expecting, result);
} }
@ -115,7 +115,7 @@ public class TestParseTrees extends BaseTest {
"a : 'x' 'y'* '!'\n" + "a : 'x' 'y'* '!'\n" +
" ;\n" + " ;\n" +
"Z : 'z'; \n"; "Z : 'z'; \n";
String result = execParser("T.g", grammar, "TParser", "TLexer", "s", "xzyy!", false); String result = execParser("T.g4", grammar, "TParser", "TLexer", "s", "xzyy!", false);
String expecting = "(a x z y y !)\n"; String expecting = "(a x z y y !)\n";
assertEquals(expecting, result); assertEquals(expecting, result);
} }

View File

@ -43,7 +43,7 @@ public class TestParserExec extends BaseTest {
"INT : '0'..'9'+;\n" + "INT : '0'..'9'+;\n" +
"WS : (' '|'\\n') {skip();} ;\n"; "WS : (' '|'\\n') {skip();} ;\n";
String found = execParser("T.g", grammar, "TParser", "TLexer", "a", String found = execParser("T.g4", grammar, "TParser", "TLexer", "a",
"abc 34", false); "abc 34", false);
assertEquals("", found); assertEquals("", found);
assertEquals(null, stderrDuringParse); assertEquals(null, stderrDuringParse);
@ -57,7 +57,7 @@ public class TestParserExec extends BaseTest {
"INT : '0'..'9'+;\n" + "INT : '0'..'9'+;\n" +
"WS : (' '|'\\n') {skip();} ;\n"; "WS : (' '|'\\n') {skip();} ;\n";
String found = execParser("T.g", grammar, "TParser", "TLexer", "a", String found = execParser("T.g4", grammar, "TParser", "TLexer", "a",
"abc 34", false); "abc 34", false);
assertEquals("abc34\n", found); assertEquals("abc34\n", found);
} }
@ -72,7 +72,7 @@ public class TestParserExec extends BaseTest {
"INT : '0'..'9'+;\n" + "INT : '0'..'9'+;\n" +
"WS : (' '|'\\n') {skip();} ;\n"; "WS : (' '|'\\n') {skip();} ;\n";
String found = execParser("T.g", grammar, "TParser", "TLexer", "a", String found = execParser("T.g4", grammar, "TParser", "TLexer", "a",
"34", false); "34", false);
assertEquals("alt 2\n", found); assertEquals("alt 2\n", found);
} }
@ -84,7 +84,7 @@ public class TestParserExec extends BaseTest {
"ID : 'a'..'z'+ ;\n" + "ID : 'a'..'z'+ ;\n" +
"WS : (' '|'\\n') {skip();} ;\n"; "WS : (' '|'\\n') {skip();} ;\n";
String found = execParser("T.g", grammar, "TParser", "TLexer", "a", String found = execParser("T.g4", grammar, "TParser", "TLexer", "a",
"a b c", false); "a b c", false);
assertEquals("abc\n", found); assertEquals("abc\n", found);
} }
@ -97,7 +97,7 @@ public class TestParserExec extends BaseTest {
"ID : 'a'..'z'+ ;\n" + "ID : 'a'..'z'+ ;\n" +
"WS : (' '|'\\n') {skip();} ;\n"; "WS : (' '|'\\n') {skip();} ;\n";
String found = execParser("T.g", grammar, "TParser", "TLexer", "a", String found = execParser("T.g4", grammar, "TParser", "TLexer", "a",
"a b c", false); "a b c", false);
assertEquals("abc\n", found); assertEquals("abc\n", found);
} }
@ -109,10 +109,10 @@ public class TestParserExec extends BaseTest {
"ID : 'a'..'z'+ ;\n" + "ID : 'a'..'z'+ ;\n" +
"WS : (' '|'\\n') {skip();} ;\n"; "WS : (' '|'\\n') {skip();} ;\n";
String found = execParser("T.g", grammar, "TParser", "TLexer", "a", String found = execParser("T.g4", grammar, "TParser", "TLexer", "a",
"", false); "", false);
assertEquals("\n", found); assertEquals("\n", found);
found = execParser("T.g", grammar, "TParser", "TLexer", "a", found = execParser("T.g4", grammar, "TParser", "TLexer", "a",
"a b c", false); "a b c", false);
assertEquals("abc\n", found); assertEquals("abc\n", found);
} }
@ -125,10 +125,10 @@ public class TestParserExec extends BaseTest {
"ID : 'a'..'z'+ ;\n" + "ID : 'a'..'z'+ ;\n" +
"WS : (' '|'\\n') {skip();} ;\n"; "WS : (' '|'\\n') {skip();} ;\n";
String found = execParser("T.g", grammar, "TParser", "TLexer", "a", String found = execParser("T.g4", grammar, "TParser", "TLexer", "a",
"", false); "", false);
assertEquals("\n", found); assertEquals("\n", found);
found = execParser("T.g", grammar, "TParser", "TLexer", "a", found = execParser("T.g4", grammar, "TParser", "TLexer", "a",
"a b c", false); "a b c", false);
assertEquals("abc\n", found); assertEquals("abc\n", found);
} }
@ -141,7 +141,7 @@ public class TestParserExec extends BaseTest {
"INT : '0'..'9'+;\n" + "INT : '0'..'9'+;\n" +
"WS : (' '|'\\n') {skip();} ;\n"; "WS : (' '|'\\n') {skip();} ;\n";
String found = execParser("T.g", grammar, "TParser", "TLexer", "a", String found = execParser("T.g4", grammar, "TParser", "TLexer", "a",
"a 34 c", false); "a 34 c", false);
assertEquals("a34c\n", found); assertEquals("a34c\n", found);
} }
@ -154,10 +154,10 @@ public class TestParserExec extends BaseTest {
"INT : '0'..'9'+;\n" + "INT : '0'..'9'+;\n" +
"WS : (' '|'\\n') {skip();} ;\n"; "WS : (' '|'\\n') {skip();} ;\n";
String found = execParser("T.g", grammar, "TParser", "TLexer", "a", String found = execParser("T.g4", grammar, "TParser", "TLexer", "a",
"", false); "", false);
assertEquals("\n", found); assertEquals("\n", found);
found = execParser("T.g", grammar, "TParser", "TLexer", "a", found = execParser("T.g4", grammar, "TParser", "TLexer", "a",
"a 34 c", false); "a 34 c", false);
assertEquals("a34c\n", found); assertEquals("a34c\n", found);
} }
@ -175,19 +175,19 @@ public class TestParserExec extends BaseTest {
"a : 'a' s ('b' s)?;\n" "a : 'a' s ('b' s)?;\n"
; ;
String found = execParser("T.g", grammar, "TParser", "TLexer", "s", "x", false); String found = execParser("T.g4", grammar, "TParser", "TLexer", "s", "x", false);
assertEquals("", found); assertEquals("", found);
assertNull(this.stderrDuringParse); assertNull(this.stderrDuringParse);
found = execParser("T.g", grammar, "TParser", "TLexer", "s", "axbx", false); found = execParser("T.g4", grammar, "TParser", "TLexer", "s", "axbx", false);
assertEquals("", found); assertEquals("", found);
assertNull(this.stderrDuringParse); assertNull(this.stderrDuringParse);
found = execParser("T.g", grammar, "TParser", "TLexer", "s", "ax", false); found = execParser("T.g4", grammar, "TParser", "TLexer", "s", "ax", false);
assertEquals("", found); assertEquals("", found);
assertNull(this.stderrDuringParse); assertNull(this.stderrDuringParse);
found = execParser("T.g", grammar, "TParser", "TLexer", "s", "aaxbx", false); found = execParser("T.g4", grammar, "TParser", "TLexer", "s", "aaxbx", false);
assertEquals("", found); assertEquals("", found);
assertNull(this.stderrDuringParse); assertNull(this.stderrDuringParse);
} }
@ -207,7 +207,7 @@ public class TestParserExec extends BaseTest {
"WS : (' ' | '\\t')+ -> skip;\n" "WS : (' ' | '\\t')+ -> skip;\n"
; ;
String found = execParser("T.g", grammar, "TParser", "TLexer", "stmt", String found = execParser("T.g4", grammar, "TParser", "TLexer", "stmt",
"if x if x a else b", true); "if x if x a else b", true);
String expecting = ""; String expecting = "";
assertEquals(expecting, found); assertEquals(expecting, found);

View File

@ -78,8 +78,8 @@ public class TestPerformance extends BaseTest {
private static final boolean RECURSIVE = true; private static final boolean RECURSIVE = true;
/** /**
* True to use the Java grammar with expressions in the v4 left-recursive syntax (Java-LR.g). False to use * True to use the Java grammar with expressions in the v4 left-recursive syntax (Java-LR.g4). False to use
* the standard grammar (Java.g). In either case, the grammar is renamed in the temporary directory to Java.g * the standard grammar (Java.g4). In either case, the grammar is renamed in the temporary directory to Java.g4
* before compiling. * before compiling.
*/ */
private static final boolean USE_LR_GRAMMAR = true; private static final boolean USE_LR_GRAMMAR = true;
@ -421,8 +421,8 @@ public class TestPerformance extends BaseTest {
} }
protected void compileJavaParser(boolean leftRecursive) throws IOException { protected void compileJavaParser(boolean leftRecursive) throws IOException {
String grammarFileName = "Java.g"; String grammarFileName = "Java.g4";
String sourceName = leftRecursive ? "Java-LR.g" : "Java.g"; String sourceName = leftRecursive ? "Java-LR.g4" : "Java.g4";
String body = load(sourceName, null); String body = load(sourceName, null);
@SuppressWarnings({"ConstantConditions"}) @SuppressWarnings({"ConstantConditions"})
List<String> extraOptions = new ArrayList<String>(); List<String> extraOptions = new ArrayList<String>();

View File

@ -11,7 +11,7 @@ public class TestSemPredEvalLexer extends BaseTest {
"E2 : {true}? 'enum' ;\n" + // winner not E1 or ID "E2 : {true}? 'enum' ;\n" + // winner not E1 or ID
"ID : 'a'..'z'+ ;\n"+ "ID : 'a'..'z'+ ;\n"+
"WS : (' '|'\\n') {skip();} ;"; "WS : (' '|'\\n') {skip();} ;";
String found = execLexer("L.g", grammar, "L", "enum abc", true); String found = execLexer("L.g4", grammar, "L", "enum abc", true);
String expecting = String expecting =
"[@0,0:3='enum',<4>,1:0]\n" + "[@0,0:3='enum',<4>,1:0]\n" +
"[@1,5:7='abc',<5>,1:5]\n" + "[@1,5:7='abc',<5>,1:5]\n" +
@ -26,7 +26,7 @@ public class TestSemPredEvalLexer extends BaseTest {
"E2 : 'enum' {true}? ;\n" + // winner not E1 or ID "E2 : 'enum' {true}? ;\n" + // winner not E1 or ID
"ID : 'a'..'z'+ ;\n"+ "ID : 'a'..'z'+ ;\n"+
"WS : (' '|'\\n') {skip();} ;"; "WS : (' '|'\\n') {skip();} ;";
String found = execLexer("L.g", grammar, "L", "enum abc enum", true); String found = execLexer("L.g4", grammar, "L", "enum abc enum", true);
String expecting = String expecting =
"[@0,0:3='enum',<4>,1:0]\n" + "[@0,0:3='enum',<4>,1:0]\n" +
"[@1,5:7='abc',<5>,1:5]\n" + "[@1,5:7='abc',<5>,1:5]\n" +
@ -50,7 +50,7 @@ public class TestSemPredEvalLexer extends BaseTest {
"B : {int n=0;} ({n<=2}? DIGIT {n++})+ ;\n" + "B : {int n=0;} ({n<=2}? DIGIT {n++})+ ;\n" +
"fragment DIGIT : '0'..'9' ;\n"+ "fragment DIGIT : '0'..'9' ;\n"+
"WS : (' '|'\\n') {skip();} ;"; "WS : (' '|'\\n') {skip();} ;";
String found = execLexer("L.g", grammar, "L", "1234 56", true); String found = execLexer("L.g4", grammar, "L", "1234 56", true);
String expecting = String expecting =
"[@0,0:3='enum',<4>,1:0]\n" + "[@0,0:3='enum',<4>,1:0]\n" +
"[@1,5:7='abc',<5>,1:5]\n" + "[@1,5:7='abc',<5>,1:5]\n" +

View File

@ -45,7 +45,7 @@ public class TestSemPredEvalParser extends BaseTest {
"INT : '0'..'9'+;\n" + "INT : '0'..'9'+;\n" +
"WS : (' '|'\\n') {skip();} ;\n"; "WS : (' '|'\\n') {skip();} ;\n";
String found = execParser("T.g", grammar, "TParser", "TLexer", "s", String found = execParser("T.g4", grammar, "TParser", "TLexer", "s",
"3 4 x", false); "3 4 x", false);
String expecting = String expecting =
"alt 2\n" + "alt 2\n" +
@ -70,7 +70,7 @@ public class TestSemPredEvalParser extends BaseTest {
"INT : '0'..'9'+;\n" + "INT : '0'..'9'+;\n" +
"WS : (' '|'\\n') {skip();} ;\n"; "WS : (' '|'\\n') {skip();} ;\n";
String found = execParser("T.g", grammar, "TParser", "TLexer", "s", String found = execParser("T.g4", grammar, "TParser", "TLexer", "s",
"x ; y", false); "x ; y", false);
String expecting = ""; String expecting = "";
assertEquals(expecting, found); assertEquals(expecting, found);
@ -95,7 +95,7 @@ public class TestSemPredEvalParser extends BaseTest {
"INT : '0'..'9'+;\n" + "INT : '0'..'9'+;\n" +
"WS : (' '|'\\n') {skip();} ;\n"; "WS : (' '|'\\n') {skip();} ;\n";
String found = execParser("T.g", grammar, "TParser", "TLexer", "s", String found = execParser("T.g4", grammar, "TParser", "TLexer", "s",
"x y 3", false); "x y 3", false);
String expecting = String expecting =
"alt 2\n" + "alt 2\n" +
@ -120,7 +120,7 @@ public class TestSemPredEvalParser extends BaseTest {
"INT : '0'..'9'+;\n" + "INT : '0'..'9'+;\n" +
"WS : (' '|'\\n') {skip();} ;\n"; "WS : (' '|'\\n') {skip();} ;\n";
String found = execParser("T.g", grammar, "TParser", "TLexer", "s", String found = execParser("T.g4", grammar, "TParser", "TLexer", "s",
"x y", false); "x y", false);
String expecting = String expecting =
"alt 1\n" + "alt 1\n" +
@ -147,7 +147,7 @@ public class TestSemPredEvalParser extends BaseTest {
"INT : '0'..'9'+;\n" + "INT : '0'..'9'+;\n" +
"WS : (' '|'\\n') {skip();} ;\n"; "WS : (' '|'\\n') {skip();} ;\n";
String found = execParser("T.g", grammar, "TParser", "TLexer", "s", String found = execParser("T.g4", grammar, "TParser", "TLexer", "s",
"x; y", true); "x; y", true);
String expecting = String expecting =
"alt 1\n" + "alt 1\n" +
@ -180,7 +180,7 @@ public class TestSemPredEvalParser extends BaseTest {
"INT : '0'..'9'+;\n" + "INT : '0'..'9'+;\n" +
"WS : (' '|'\\n') {skip();} ;\n"; "WS : (' '|'\\n') {skip();} ;\n";
String found = execParser("T.g", grammar, "TParser", "TLexer", "s", String found = execParser("T.g4", grammar, "TParser", "TLexer", "s",
"34; x; y", true); "34; x; y", true);
String expecting = String expecting =
"alt 1\n" + "alt 1\n" +
@ -208,7 +208,7 @@ public class TestSemPredEvalParser extends BaseTest {
"INT : '0'..'9'+;\n" + "INT : '0'..'9'+;\n" +
"WS : (' '|'\\n') {skip();} ;\n"; "WS : (' '|'\\n') {skip();} ;\n";
String found = execParser("T.g", grammar, "TParser", "TLexer", "s", String found = execParser("T.g4", grammar, "TParser", "TLexer", "s",
"y 3 x 4", false); "y 3 x 4", false);
String expecting = String expecting =
"alt 2\n" + "alt 2\n" +
@ -229,7 +229,7 @@ public class TestSemPredEvalParser extends BaseTest {
"INT : '0'..'9'+;\n" + "INT : '0'..'9'+;\n" +
"WS : (' '|'\\n') {skip();} ;\n"; "WS : (' '|'\\n') {skip();} ;\n";
execParser("T.g", grammar, "TParser", "TLexer", "s", execParser("T.g4", grammar, "TParser", "TLexer", "s",
"y 3 x 4", false); "y 3 x 4", false);
String expecting = "line 1:0 no viable alternative at input 'y'\n"; String expecting = "line 1:0 no viable alternative at input 'y'\n";
String result = stderrDuringParse; String result = stderrDuringParse;
@ -247,7 +247,7 @@ public class TestSemPredEvalParser extends BaseTest {
"INT : '0'..'9'+;\n" + "INT : '0'..'9'+;\n" +
"WS : (' '|'\\n') {skip();} ;\n"; "WS : (' '|'\\n') {skip();} ;\n";
String found = execParser("T.g", grammar, "TParser", "TLexer", "s", String found = execParser("T.g4", grammar, "TParser", "TLexer", "s",
"x x y", false); "x x y", false);
String expecting = String expecting =
"alt 2\n" + "alt 2\n" +
@ -272,7 +272,7 @@ public class TestSemPredEvalParser extends BaseTest {
"INT : '0'..'9'+;\n" + "INT : '0'..'9'+;\n" +
"WS : (' '|'\\n') {skip();} ;\n"; "WS : (' '|'\\n') {skip();} ;\n";
String found = execParser("T.g", grammar, "TParser", "TLexer", "s", String found = execParser("T.g4", grammar, "TParser", "TLexer", "s",
"x 4", false); "x 4", false);
String expecting = String expecting =
"alt 1\n"; "alt 1\n";
@ -295,7 +295,7 @@ public class TestSemPredEvalParser extends BaseTest {
"INT : '0'..'9'+;\n" + "INT : '0'..'9'+;\n" +
"WS : (' '|'\\n') {skip();} ;\n"; "WS : (' '|'\\n') {skip();} ;\n";
String found = execParser("T.g", grammar, "TParser", "TLexer", "s", String found = execParser("T.g4", grammar, "TParser", "TLexer", "s",
"x x y", false); "x x y", false);
String expecting = String expecting =
"alt 1\n" + "alt 1\n" +
@ -321,7 +321,7 @@ public class TestSemPredEvalParser extends BaseTest {
"INT : '0'..'9'+;\n" + "INT : '0'..'9'+;\n" +
"WS : (' '|'\\n') {skip();} ;\n"; "WS : (' '|'\\n') {skip();} ;\n";
String found = execParser("T.g", grammar, "TParser", "TLexer", "s", String found = execParser("T.g4", grammar, "TParser", "TLexer", "s",
"x x y", false); "x x y", false);
String expecting = String expecting =
"i=1\n" + "i=1\n" +
@ -352,7 +352,7 @@ public class TestSemPredEvalParser extends BaseTest {
"INT : '0'..'9'+;\n" + "INT : '0'..'9'+;\n" +
"WS : (' '|'\\n') {skip();} ;\n"; "WS : (' '|'\\n') {skip();} ;\n";
String found = execParser("T.g", grammar, "TParser", "TLexer", "s", String found = execParser("T.g4", grammar, "TParser", "TLexer", "s",
"a b", false); "a b", false);
String expecting = String expecting =
"alt 2\n" + "alt 2\n" +
@ -382,7 +382,7 @@ public class TestSemPredEvalParser extends BaseTest {
"INT : '0'..'9'+;\n" + "INT : '0'..'9'+;\n" +
"WS : (' '|'\\n') {skip();} ;\n"; "WS : (' '|'\\n') {skip();} ;\n";
String found = execParser("T.g", grammar, "TParser", "TLexer", "s", String found = execParser("T.g4", grammar, "TParser", "TLexer", "s",
"a b", false); "a b", false);
String expecting = String expecting =
""; "";
@ -403,7 +403,7 @@ public class TestSemPredEvalParser extends BaseTest {
"INT : '0'..'9'+;\n" + "INT : '0'..'9'+;\n" +
"WS : (' '|'\\n') {skip();} ;\n"; "WS : (' '|'\\n') {skip();} ;\n";
String found = execParser("T.g", grammar, "TParser", "TLexer", "s", String found = execParser("T.g4", grammar, "TParser", "TLexer", "s",
"a;", false); "a;", false);
String expecting = String expecting =
"alt 2\n"; "alt 2\n";
@ -423,7 +423,7 @@ public class TestSemPredEvalParser extends BaseTest {
"INT : '0'..'9'+;\n" + "INT : '0'..'9'+;\n" +
"WS : (' '|'\\n') {skip();} ;\n"; "WS : (' '|'\\n') {skip();} ;\n";
String found = execParser("T.g", grammar, "TParser", "TLexer", "s", String found = execParser("T.g4", grammar, "TParser", "TLexer", "s",
"a;", false); "a;", false);
String expecting = String expecting =
"alt 2\n"; "alt 2\n";
@ -447,7 +447,7 @@ public class TestSemPredEvalParser extends BaseTest {
"INT : '0'..'9'+;\n" + "INT : '0'..'9'+;\n" +
"WS : (' '|'\\n') {skip();} ;\n"; "WS : (' '|'\\n') {skip();} ;\n";
String found = execParser("T.g", grammar, "TParser", "TLexer", "s", String found = execParser("T.g4", grammar, "TParser", "TLexer", "s",
"a!", false); "a!", false);
String expecting = String expecting =
"eval=true\n" + // now we are parsing "eval=true\n" + // now we are parsing
@ -473,7 +473,7 @@ public class TestSemPredEvalParser extends BaseTest {
"INT : '0'..'9'+;\n" + "INT : '0'..'9'+;\n" +
"WS : (' '|'\\n') {skip();} ;\n"; "WS : (' '|'\\n') {skip();} ;\n";
String found = execParser("T.g", grammar, "TParser", "TLexer", "s", String found = execParser("T.g4", grammar, "TParser", "TLexer", "s",
"a!", false); "a!", false);
String expecting = String expecting =
"eval=true\n" + "eval=true\n" +
@ -500,7 +500,7 @@ public class TestSemPredEvalParser extends BaseTest {
"INT : '0'..'9'+;\n" + "INT : '0'..'9'+;\n" +
"WS : (' '|'\\n') {skip();} ;\n"; "WS : (' '|'\\n') {skip();} ;\n";
String found = execParser("T.g", grammar, "TParser", "TLexer", "s", String found = execParser("T.g4", grammar, "TParser", "TLexer", "s",
"a!", false); "a!", false);
String expecting = String expecting =
"eval=true\n" + "eval=true\n" +

View File

@ -46,7 +46,7 @@ public class TestSets extends BaseTest {
"fragment A : '1' | '2';\n" + "fragment A : '1' | '2';\n" +
"fragment B : '3' '4';\n" + "fragment B : '3' '4';\n" +
"C : A | B;\n"; "C : A | B;\n";
String found = execParser("P.g", grammar, "PParser", "PLexer", String found = execParser("P.g4", grammar, "PParser", "PLexer",
"a", "34", debug); "a", "34", debug);
assertEquals("34\n", found); assertEquals("34\n", found);
} }
@ -55,7 +55,7 @@ public class TestSets extends BaseTest {
String grammar = String grammar =
"grammar T;\n" + "grammar T;\n" +
"a : t=('x'|'y') {System.out.println($t.text);} ;\n"; "a : t=('x'|'y') {System.out.println($t.text);} ;\n";
String found = execParser("T.g", grammar, "TParser", "TLexer", String found = execParser("T.g4", grammar, "TParser", "TLexer",
"a", "x", debug); "a", "x", debug);
assertEquals("x\n", found); assertEquals("x\n", found);
} }
@ -64,7 +64,7 @@ public class TestSets extends BaseTest {
String grammar = String grammar =
"grammar T;\n" + "grammar T;\n" +
"a : t=~('x'|'y') 'z' {System.out.println($t.text);} ;\n"; "a : t=~('x'|'y') 'z' {System.out.println($t.text);} ;\n";
String found = execParser("T.g", grammar, "TParser", "TLexer", String found = execParser("T.g4", grammar, "TParser", "TLexer",
"a", "zz", debug); "a", "zz", debug);
assertEquals("z\n", found); assertEquals("z\n", found);
} }
@ -73,7 +73,7 @@ public class TestSets extends BaseTest {
String grammar = String grammar =
"grammar T;\n" + "grammar T;\n" +
"a : ~'x' 'z' {System.out.println(_input);} ;\n"; "a : ~'x' 'z' {System.out.println(_input);} ;\n";
String found = execParser("T.g", grammar, "TParser", "TLexer", String found = execParser("T.g4", grammar, "TParser", "TLexer",
"a", "zz", debug); "a", "zz", debug);
assertEquals("zz\n", found); assertEquals("zz\n", found);
} }
@ -82,7 +82,7 @@ public class TestSets extends BaseTest {
String grammar = String grammar =
"grammar T;\n" + "grammar T;\n" +
"a : t=~'x' 'z' {System.out.println($t.text);} ;\n"; "a : t=~'x' 'z' {System.out.println($t.text);} ;\n";
String found = execParser("T.g", grammar, "TParser", "TLexer", String found = execParser("T.g4", grammar, "TParser", "TLexer",
"a", "zz", debug); "a", "zz", debug);
assertEquals("z\n", found); assertEquals("z\n", found);
} }
@ -91,7 +91,7 @@ public class TestSets extends BaseTest {
String grammar = String grammar =
"grammar T;\n" + "grammar T;\n" +
"a @after {System.out.println(_input);} : 'a' | 'b' |'c' ;\n"; "a @after {System.out.println(_input);} : 'a' | 'b' |'c' ;\n";
String found = execParser("T.g", grammar, "TParser", "TLexer", String found = execParser("T.g4", grammar, "TParser", "TLexer",
"a", "b", debug); "a", "b", debug);
assertEquals("b\n", found); assertEquals("b\n", found);
} }
@ -101,7 +101,7 @@ public class TestSets extends BaseTest {
"grammar T;\n" + "grammar T;\n" +
"a : A {System.out.println($A.text);} ;\n" + "a : A {System.out.println($A.text);} ;\n" +
"A : ~'b' ;\n"; "A : ~'b' ;\n";
String found = execParser("T.g", grammar, "TParser", "TLexer", String found = execParser("T.g4", grammar, "TParser", "TLexer",
"a", "x", debug); "a", "x", debug);
assertEquals("x\n", found); assertEquals("x\n", found);
} }
@ -111,7 +111,7 @@ public class TestSets extends BaseTest {
"grammar T;\n" + "grammar T;\n" +
"a : A? 'c' {System.out.println(_input);} ;\n" + "a : A? 'c' {System.out.println(_input);} ;\n" +
"A : 'b' ;\n"; "A : 'b' ;\n";
String found = execParser("T.g", grammar, "TParser", "TLexer", String found = execParser("T.g4", grammar, "TParser", "TLexer",
"a", "bc", debug); "a", "bc", debug);
assertEquals("bc\n", found); assertEquals("bc\n", found);
} }
@ -121,7 +121,7 @@ public class TestSets extends BaseTest {
"grammar T;\n" + "grammar T;\n" +
"a : A {System.out.println(_input);} ;\n" + "a : A {System.out.println(_input);} ;\n" +
"A : 'b'? 'c' ;\n"; "A : 'b'? 'c' ;\n";
String found = execParser("T.g", grammar, "TParser", "TLexer", String found = execParser("T.g4", grammar, "TParser", "TLexer",
"a", "bc", debug); "a", "bc", debug);
assertEquals("bc\n", found); assertEquals("bc\n", found);
} }
@ -131,10 +131,10 @@ public class TestSets extends BaseTest {
"grammar T;\n" + "grammar T;\n" +
"a : A {System.out.println(_input);} ;\n" + "a : A {System.out.println(_input);} ;\n" +
"A : 'b'* 'c' ;\n"; "A : 'b'* 'c' ;\n";
String found = execParser("T.g", grammar, "TParser", "TLexer", String found = execParser("T.g4", grammar, "TParser", "TLexer",
"a", "bbbbc", debug); "a", "bbbbc", debug);
assertEquals("bbbbc\n", found); assertEquals("bbbbc\n", found);
found = execParser("T.g", grammar, "TParser", "TLexer", found = execParser("T.g4", grammar, "TParser", "TLexer",
"a", "c", debug); "a", "c", debug);
assertEquals("c\n", found); assertEquals("c\n", found);
} }
@ -144,7 +144,7 @@ public class TestSets extends BaseTest {
"grammar T;\n" + "grammar T;\n" +
"a : A {System.out.println(_input);} ;\n" + "a : A {System.out.println(_input);} ;\n" +
"A : 'b'+ 'c' ;\n"; "A : 'b'+ 'c' ;\n";
String found = execParser("T.g", grammar, "TParser", "TLexer", String found = execParser("T.g4", grammar, "TParser", "TLexer",
"a", "bbbbc", debug); "a", "bbbbc", debug);
assertEquals("bbbbc\n", found); assertEquals("bbbbc\n", found);
} }
@ -153,7 +153,7 @@ public class TestSets extends BaseTest {
String grammar = String grammar =
"grammar T;\n" + "grammar T;\n" +
"a : ('a'|'b')? 'c' {System.out.println(_input);} ;\n"; "a : ('a'|'b')? 'c' {System.out.println(_input);} ;\n";
String found = execParser("T.g", grammar, "TParser", "TLexer", String found = execParser("T.g4", grammar, "TParser", "TLexer",
"a", "ac", debug); "a", "ac", debug);
assertEquals("ac\n", found); assertEquals("ac\n", found);
} }
@ -162,7 +162,7 @@ public class TestSets extends BaseTest {
String grammar = String grammar =
"grammar T;\n" + "grammar T;\n" +
"a : ('a'|'b')* 'c' {System.out.println(_input);} ;\n"; "a : ('a'|'b')* 'c' {System.out.println(_input);} ;\n";
String found = execParser("T.g", grammar, "TParser", "TLexer", String found = execParser("T.g4", grammar, "TParser", "TLexer",
"a", "abaac", debug); "a", "abaac", debug);
assertEquals("abaac\n", found); assertEquals("abaac\n", found);
} }
@ -171,7 +171,7 @@ public class TestSets extends BaseTest {
String grammar = String grammar =
"grammar T;\n" + "grammar T;\n" +
"a : ('a'|'b')+ 'c' {System.out.println(_input);} ;\n"; "a : ('a'|'b')+ 'c' {System.out.println(_input);} ;\n";
String found = execParser("T.g", grammar, "TParser", "TLexer", String found = execParser("T.g4", grammar, "TParser", "TLexer",
"a", "abaac", debug); "a", "abaac", debug);
assertEquals("abaac\n", found); assertEquals("abaac\n", found);
} }
@ -181,7 +181,7 @@ public class TestSets extends BaseTest {
"grammar T;\n" + "grammar T;\n" +
"a : A {System.out.println(_input);} ;\n" + "a : A {System.out.println(_input);} ;\n" +
"A : ('a'|'b')? 'c' ;\n"; "A : ('a'|'b')? 'c' ;\n";
String found = execParser("T.g", grammar, "TParser", "TLexer", String found = execParser("T.g4", grammar, "TParser", "TLexer",
"a", "ac", debug); "a", "ac", debug);
assertEquals("ac\n", found); assertEquals("ac\n", found);
} }
@ -191,7 +191,7 @@ public class TestSets extends BaseTest {
"grammar T;\n" + "grammar T;\n" +
"a : A {System.out.println(_input);} ;\n" + "a : A {System.out.println(_input);} ;\n" +
"A : ('a'|'b')* 'c' ;\n"; "A : ('a'|'b')* 'c' ;\n";
String found = execParser("T.g", grammar, "TParser", "TLexer", String found = execParser("T.g4", grammar, "TParser", "TLexer",
"a", "abaac", debug); "a", "abaac", debug);
assertEquals("abaac\n", found); assertEquals("abaac\n", found);
} }
@ -201,7 +201,7 @@ public class TestSets extends BaseTest {
"grammar T;\n" + "grammar T;\n" +
"a : A {System.out.println(_input);} ;\n" + "a : A {System.out.println(_input);} ;\n" +
"A : ('a'|'b')+ 'c' ;\n"; "A : ('a'|'b')+ 'c' ;\n";
String found = execParser("T.g", grammar, "TParser", "TLexer", String found = execParser("T.g4", grammar, "TParser", "TLexer",
"a", "abaac", debug); "a", "abaac", debug);
assertEquals("abaac\n", found); assertEquals("abaac\n", found);
} }
@ -211,7 +211,7 @@ public class TestSets extends BaseTest {
"grammar T;\n" + "grammar T;\n" +
"a : A {System.out.println($A.text);} ;\n" + "a : A {System.out.println($A.text);} ;\n" +
"A : ~('b'|'c') ;\n"; "A : ~('b'|'c') ;\n";
String found = execParser("T.g", grammar, "TParser", "TLexer", String found = execParser("T.g4", grammar, "TParser", "TLexer",
"a", "x", debug); "a", "x", debug);
assertEquals("x\n", found); assertEquals("x\n", found);
} }
@ -221,7 +221,7 @@ public class TestSets extends BaseTest {
"grammar T;\n" + "grammar T;\n" +
"a : A {System.out.println($A.text);} ;\n" + "a : A {System.out.println($A.text);} ;\n" +
"A : h=~('b'|'c') ;\n"; "A : h=~('b'|'c') ;\n";
String found = execParser("T.g", grammar, "TParser", "TLexer", String found = execParser("T.g4", grammar, "TParser", "TLexer",
"a", "x", debug); "a", "x", debug);
assertEquals("x\n", found); assertEquals("x\n", found);
} }
@ -232,7 +232,7 @@ public class TestSets extends BaseTest {
"a : A {System.out.println($A.text);} ;\n" + "a : A {System.out.println($A.text);} ;\n" +
"A : ~('a'|B) ;\n" + "A : ~('a'|B) ;\n" +
"B : 'b' ;\n"; "B : 'b' ;\n";
String found = execParser("T.g", grammar, "TParser", "TLexer", String found = execParser("T.g4", grammar, "TParser", "TLexer",
"a", "x", debug); "a", "x", debug);
assertEquals("x\n", found); assertEquals("x\n", found);
} }
@ -243,7 +243,7 @@ public class TestSets extends BaseTest {
"a : A {System.out.println($A.text);} ;\n" + "a : A {System.out.println($A.text);} ;\n" +
"A : ~('a'|B) ;\n" + "A : ~('a'|B) ;\n" +
"B : 'b'|'c' ;\n"; "B : 'b'|'c' ;\n";
String found = execParser("T.g", grammar, "TParser", "TLexer", String found = execParser("T.g4", grammar, "TParser", "TLexer",
"a", "x", debug); "a", "x", debug);
assertEquals("x\n", found); assertEquals("x\n", found);
} }
@ -255,7 +255,7 @@ public class TestSets extends BaseTest {
"A : ('a'|B) ;\n" + "A : ('a'|B) ;\n" +
"fragment\n" + "fragment\n" +
"B : ~('a'|'c') ;\n"; "B : ~('a'|'c') ;\n";
String found = execParser("T.g", grammar, "TParser", "TLexer", String found = execParser("T.g4", grammar, "TParser", "TLexer",
"a", "x", debug); "a", "x", debug);
assertEquals("x\n", found); assertEquals("x\n", found);
} }
@ -269,7 +269,7 @@ public class TestSets extends BaseTest {
"B : ~('a'|C) ;\n" + "B : ~('a'|C) ;\n" +
"fragment\n" + "fragment\n" +
"C : 'c'|'d' ;\n "; "C : 'c'|'d' ;\n ";
String found = execParser("T.g", grammar, "TParser", "TLexer", String found = execParser("T.g4", grammar, "TParser", "TLexer",
"a", "x", debug); "a", "x", debug);
assertEquals("x\n", found); assertEquals("x\n", found);
} }
@ -280,7 +280,7 @@ public class TestSets extends BaseTest {
"a : (A {System.out.println($A.text);})+ ;\n" + "a : (A {System.out.println($A.text);})+ ;\n" +
"A : [AaBb] ;\n" + "A : [AaBb] ;\n" +
"WS : (' '|'\\n')+ {skip();} ;\n"; "WS : (' '|'\\n')+ {skip();} ;\n";
String found = execParser("T.g", grammar, "TParser", "TLexer", String found = execParser("T.g4", grammar, "TParser", "TLexer",
"a", "A a B b", debug); "a", "A a B b", debug);
assertEquals("A\n" + assertEquals("A\n" +
"a\n" + "a\n" +

View File

@ -20,15 +20,15 @@ public class TestSymbolIssues extends BaseTest {
"\n" + "\n" +
"ID : 'a'..'z'+ ID ;", "ID : 'a'..'z'+ ID ;",
// YIELDS // YIELDS
"warning(48): A.g:2:10: illegal option opt\n" + "warning(48): A.g4:2:10: illegal option opt\n" +
"warning(48): A.g:2:21: illegal option k\n" + "warning(48): A.g4:2:21: illegal option k\n" +
"error(59): A.g:7:1: redefinition of header action\n" + "error(59): A.g4:7:1: redefinition of header action\n" +
"warning(51): A.g:2:10: illegal option opt\n" + "warning(51): A.g4:2:10: illegal option opt\n" +
"error(19): A.g:11:0: rule a redefinition\n" + "error(19): A.g4:11:0: rule a redefinition\n" +
"error(60): A.g:5:1: redefinition of members action\n" + "error(60): A.g4:5:1: redefinition of members action\n" +
"error(47): A.g:9:37: rule b has no defined parameters\n" + "error(47): A.g4:9:37: rule b has no defined parameters\n" +
"error(24): A.g:9:43: reference to undefined rule: q\n" + "error(24): A.g4:9:43: reference to undefined rule: q\n" +
"error(46): A.g:10:31: missing parameter(s) on rule reference: a\n" "error(46): A.g4:10:31: missing parameter(s) on rule reference: a\n"
}; };
static String[] B = { static String[] B = {
@ -42,11 +42,11 @@ public class TestSymbolIssues extends BaseTest {
"\n" + "\n" +
"s : FOO ;", "s : FOO ;",
// YIELDS // YIELDS
"error(25): B.g:2:9: can't assign string value to token name X in non-combined grammar\n" + "error(25): B.g4:2:9: can't assign string value to token name X in non-combined grammar\n" +
"error(35): B.g:4:4: label s conflicts with rule with same name\n" + "error(35): B.g4:4:4: label s conflicts with rule with same name\n" +
"error(35): B.g:4:9: label b conflicts with rule with same name\n" + "error(35): B.g4:4:9: label b conflicts with rule with same name\n" +
"error(36): B.g:4:15: label X conflicts with token with same name\n" + "error(36): B.g4:4:15: label X conflicts with token with same name\n" +
"error(40): B.g:6:9: label x type mismatch with previous definition: TOKEN_LIST_LABEL!=TOKEN_LABEL\n" "error(40): B.g4:6:9: label x type mismatch with previous definition: TOKEN_LIST_LABEL!=TOKEN_LABEL\n"
}; };
static String[] D = { static String[] D = {
@ -61,8 +61,8 @@ public class TestSymbolIssues extends BaseTest {
" : ID ;", " : ID ;",
// YIELDS // YIELDS
"error(37): D.g:3:21: label j conflicts with rule a's return value or parameter with same name\n" + "error(37): D.g4:3:21: label j conflicts with rule a's return value or parameter with same name\n" +
"error(41): D.g:5:0: rule b's argument i conflicts a return value with same name\n" "error(41): D.g4:5:0: rule b's argument i conflicts a return value with same name\n"
}; };
static String[] E = { static String[] E = {
@ -78,10 +78,10 @@ public class TestSymbolIssues extends BaseTest {
"a : A ;\n", "a : A ;\n",
// YIELDS // YIELDS
"error(73): E.g:4:8: cannot redefine B; token name already defined\n" + "error(73): E.g4:4:8: cannot redefine B; token name already defined\n" +
"error(73): E.g:5:4: cannot redefine C; token name already defined\n" + "error(73): E.g4:5:4: cannot redefine C; token name already defined\n" +
"error(73): E.g:6:8: cannot redefine D; token name already defined\n" + "error(73): E.g4:6:8: cannot redefine D; token name already defined\n" +
"error(72): E.g:7:8: cannot alias X='e'; string already assigned to E\n" "error(72): E.g4:7:8: cannot alias X='e'; string already assigned to E\n"
}; };
@Test public void testA() { super.testErrors(A, false); } @Test public void testA() { super.testErrors(A, false); }

View File

@ -136,7 +136,7 @@ public class TestTokenTypeAssignment extends BaseTest {
"A : 'a' ;\n" + "A : 'a' ;\n" +
"B : '}' ;\n"+ "B : '}' ;\n"+
"WS : (' '|'\\n') {skip();} ;"; "WS : (' '|'\\n') {skip();} ;";
String found = execParser("P.g", grammar, "PParser", "PLexer", String found = execParser("P.g4", grammar, "PParser", "PLexer",
"a", "a}", false); "a", "a}", false);
assertEquals("a}\n", found); assertEquals("a}\n", found);
} }
@ -151,7 +151,7 @@ public class TestTokenTypeAssignment extends BaseTest {
"A : 'a' ;\n" + "A : 'a' ;\n" +
"B : '}' ;\n"+ "B : '}' ;\n"+
"WS : (' '|'\\n') {skip();} ;"; "WS : (' '|'\\n') {skip();} ;";
String found = execParser("P.g", grammar, "PParser", "PLexer", String found = execParser("P.g4", grammar, "PParser", "PLexer",
"a", "a}", false); "a", "a}", false);
assertEquals("a}\n", found); assertEquals("a}\n", found);
} }

View File

@ -8,7 +8,7 @@ public class TestToolSyntaxErrors extends BaseTest {
"grammar A;\n" + "grammar A;\n" +
"", "",
// YIELDS // YIELDS
"error(64): A.g::: grammar A has no rules\n", "error(64): A.g4::: grammar A has no rules\n",
"A;", "A;",
"error(16): <string>:1:0: 'A' came as a complete surprise to me\n", "error(16): <string>:1:0: 'A' came as a complete surprise to me\n",
@ -23,22 +23,22 @@ public class TestToolSyntaxErrors extends BaseTest {
"grammar A;\n" + "grammar A;\n" +
"a : ID ;;\n"+ "a : ID ;;\n"+
"b : B ;", "b : B ;",
"error(16): A.g:2:8: ';' came as a complete surprise to me\n", "error(16): A.g4:2:8: ';' came as a complete surprise to me\n",
"grammar A;;\n" + "grammar A;;\n" +
"a : ID ;\n", "a : ID ;\n",
"error(16): A;.g:1:10: ';' came as a complete surprise to me\n", "error(16): A;.g4:1:10: ';' came as a complete surprise to me\n",
"grammar A;\n" + "grammar A;\n" +
"a @init : ID ;\n", "a @init : ID ;\n",
"error(16): A.g:2:8: mismatched input ':' expecting ACTION while matching rule preamble\n", "error(16): A.g4:2:8: mismatched input ':' expecting ACTION while matching rule preamble\n",
"grammar A;\n" + "grammar A;\n" +
"a ( A | B ) D ;\n" + "a ( A | B ) D ;\n" +
"b : B ;", "b : B ;",
"error(16): A.g:2:3: '(' came as a complete surprise to me while matching rule preamble\n" + "error(16): A.g4:2:3: '(' came as a complete surprise to me while matching rule preamble\n" +
"error(16): A.g:2:11: mismatched input ')' expecting SEMI while matching a rule\n" + "error(16): A.g4:2:11: mismatched input ')' expecting SEMI while matching a rule\n" +
"error(16): A.g:2:15: mismatched input ';' expecting COLON while matching a lexer rule\n", "error(16): A.g4:2:15: mismatched input ';' expecting COLON while matching a lexer rule\n",
}; };
@Test public void testA() { super.testErrors(A, true); } @Test public void testA() { super.testErrors(A, true); }
@ -48,7 +48,7 @@ public class TestToolSyntaxErrors extends BaseTest {
"grammar A;\n" + "grammar A;\n" +
"a : : A ;\n" + "a : : A ;\n" +
"b : B ;", "b : B ;",
"error(16): A.g:2:4: ':' came as a complete surprise to me while matching alternative\n", "error(16): A.g4:2:4: ':' came as a complete surprise to me while matching alternative\n",
}; };
super.testErrors(pair, true); super.testErrors(pair, true);
} }
@ -58,7 +58,7 @@ public class TestToolSyntaxErrors extends BaseTest {
"grammar A;\n" + "grammar A;\n" +
"a : A \n" + "a : A \n" +
"b : B ;", "b : B ;",
"error(16): A.g:3:0: unterminated rule (missing ';') detected at 'b :' while looking for rule element\n", "error(16): A.g4:3:0: unterminated rule (missing ';') detected at 'b :' while looking for rule element\n",
}; };
super.testErrors(pair, true); super.testErrors(pair, true);
} }
@ -68,7 +68,7 @@ public class TestToolSyntaxErrors extends BaseTest {
"lexer grammar A;\n" + "lexer grammar A;\n" +
"A : 'a' \n" + "A : 'a' \n" +
"B : 'b' ;", "B : 'b' ;",
"error(16): A.g:3:0: unterminated rule (missing ';') detected at 'B :' while looking for lexer rule element\n", "error(16): A.g4:3:0: unterminated rule (missing ';') detected at 'B :' while looking for lexer rule element\n",
}; };
super.testErrors(pair, true); super.testErrors(pair, true);
} }
@ -78,7 +78,7 @@ public class TestToolSyntaxErrors extends BaseTest {
"grammar A;\n" + "grammar A;\n" +
"a : A \n" + "a : A \n" +
"b[int i] returns [int y] : B ;", "b[int i] returns [int y] : B ;",
"error(16): A.g:3:9: unterminated rule (missing ';') detected at 'returns int y' while looking for rule element\n" "error(16): A.g4:3:9: unterminated rule (missing ';') detected at 'returns int y' while looking for rule element\n"
}; };
super.testErrors(pair, true); super.testErrors(pair, true);
} }
@ -90,7 +90,7 @@ public class TestToolSyntaxErrors extends BaseTest {
" catch [Exception e] {...}\n" + " catch [Exception e] {...}\n" +
"b : B ;\n", "b : B ;\n",
"error(16): A.g:2:4: unterminated rule (missing ';') detected at 'b catch' while looking for rule element\n" "error(16): A.g4:2:4: unterminated rule (missing ';') detected at 'b catch' while looking for rule element\n"
}; };
super.testErrors(pair, true); super.testErrors(pair, true);
} }
@ -101,7 +101,7 @@ public class TestToolSyntaxErrors extends BaseTest {
"a : A \n" + "a : A \n" +
" catch [Exception e] {...}\n", " catch [Exception e] {...}\n",
"error(16): A.g:2:4: unterminated rule (missing ';') detected at 'A catch' while looking for rule element\n" "error(16): A.g4:2:4: unterminated rule (missing ';') detected at 'A catch' while looking for rule element\n"
}; };
super.testErrors(pair, true); super.testErrors(pair, true);
} }
@ -112,7 +112,7 @@ public class TestToolSyntaxErrors extends BaseTest {
"a @ options {k=1;} : A ;\n" + "a @ options {k=1;} : A ;\n" +
"b : B ;", "b : B ;",
"error(16): A.g:2:4: 'options {' came as a complete surprise to me while looking for an identifier\n" "error(16): A.g4:2:4: 'options {' came as a complete surprise to me while looking for an identifier\n"
}; };
super.testErrors(pair, true); super.testErrors(pair, true);
} }
@ -123,7 +123,7 @@ public class TestToolSyntaxErrors extends BaseTest {
"a } : A ;\n" + "a } : A ;\n" +
"b : B ;", "b : B ;",
"error(16): A.g:2:2: '}' came as a complete surprise to me while matching rule preamble\n" "error(16): A.g4:2:2: '}' came as a complete surprise to me while matching rule preamble\n"
}; };
super.testErrors(pair, true); super.testErrors(pair, true);
} }
@ -135,8 +135,8 @@ public class TestToolSyntaxErrors extends BaseTest {
"mode foo;\n" + "mode foo;\n" +
"b : B ;", "b : B ;",
"error(16): A.g:4:0: 'b' came as a complete surprise to me\n" + "error(16): A.g4:4:0: 'b' came as a complete surprise to me\n" +
"error(16): A.g:4:6: mismatched input ';' expecting COLON while matching a lexer rule\n" "error(16): A.g4:4:6: mismatched input ';' expecting COLON while matching a lexer rule\n"
}; };
super.testErrors(pair, true); super.testErrors(pair, true);
} }