diff --git a/tool/test/org/antlr/v4/testgen/Generator.java b/tool/test/org/antlr/v4/testgen/Generator.java index 47c4274b3..571df6854 100644 --- a/tool/test/org/antlr/v4/testgen/Generator.java +++ b/tool/test/org/antlr/v4/testgen/Generator.java @@ -114,9 +114,48 @@ public class Generator { list.add(buildListeners()); list.add(buildParserErrors()); list.add(buildParserExec()); + list.add(buildParseTrees()); return list; } + private TestFile buildParseTrees() throws Exception { + TestFile file = new TestFile("ParseTrees"); + file.addParserTest(input, "TokenAndRuleContextString", "T", "s", + "x", + "[a, s]\n(a x)\n", + null); + file.addParserTest(input, "Token2", "T", "s", + "xy", + "(a x y)\n", + null); + file.addParserTest(input, "test2Alts", "T", "s", + "y", + "(a y)\n", + null); + file.addParserTest(input, "2AltLoop", "T", "s", + "xyyxyxz", + "(a x y y x y x z)\n", + null); + file.addParserTest(input, "RuleRef", "T", "s", + "yx", + "(a (b y) x)\n", + null); + // ERRORs not shown. z is colored red in tree view + file.addParserTest(input, "ExtraToken", "T", "s", + "xzy", + "(a x z y)\n", + null); + file.addParserTest(input, "NoViableAlt", "T", "s", + "z", + "(a z)\n", + null); + file.addParserTest(input, "Sync", "T", "s", + "xzyy!", + "(a x z y y !)\n", + null); + return file; + } + private TestFile buildParserErrors() throws Exception { TestFile file = new TestFile("ParserErrors"); file.addParserTest(input, "TokenMismatch", "T", "a", diff --git a/tool/test/org/antlr/v4/testgen/grammars/ParseTrees/2AltLoop.st b/tool/test/org/antlr/v4/testgen/grammars/ParseTrees/2AltLoop.st new file mode 100644 index 000000000..0b5bbd977 --- /dev/null +++ b/tool/test/org/antlr/v4/testgen/grammars/ParseTrees/2AltLoop.st @@ -0,0 +1,11 @@ +grammar ; +s +@init { + +} +@after { + +} + : r=a ; +a : ('x' | 'y')* 'z' + ; \ No newline at end of file diff --git a/tool/test/org/antlr/v4/testgen/grammars/ParseTrees/ExtraToken.st b/tool/test/org/antlr/v4/testgen/grammars/ParseTrees/ExtraToken.st new file mode 100644 index 000000000..c5520f0b4 --- /dev/null +++ b/tool/test/org/antlr/v4/testgen/grammars/ParseTrees/ExtraToken.st @@ -0,0 +1,14 @@ +grammar ; +s +@init { + +} +@after { + +} + : r=a ; +a : 'x' 'y' + ; +Z : 'z' + ; + diff --git a/tool/test/org/antlr/v4/testgen/grammars/ParseTrees/NoViableAlt.st b/tool/test/org/antlr/v4/testgen/grammars/ParseTrees/NoViableAlt.st new file mode 100644 index 000000000..3461fe3a4 --- /dev/null +++ b/tool/test/org/antlr/v4/testgen/grammars/ParseTrees/NoViableAlt.st @@ -0,0 +1,14 @@ +grammar ; +s +@init { + +} +@after { + +} + : r=a ; +a : 'x' | 'y' + ; +Z : 'z' + ; + \ No newline at end of file diff --git a/tool/test/org/antlr/v4/testgen/grammars/ParseTrees/RuleRef.st b/tool/test/org/antlr/v4/testgen/grammars/ParseTrees/RuleRef.st new file mode 100644 index 000000000..2a048fd34 --- /dev/null +++ b/tool/test/org/antlr/v4/testgen/grammars/ParseTrees/RuleRef.st @@ -0,0 +1,13 @@ +grammar ; +s +@init { + +} +@after { + +} + : r=a ; +a : b 'x' + ; +b : 'y' + ; diff --git a/tool/test/org/antlr/v4/testgen/grammars/ParseTrees/Sync.st b/tool/test/org/antlr/v4/testgen/grammars/ParseTrees/Sync.st new file mode 100644 index 000000000..183d1629c --- /dev/null +++ b/tool/test/org/antlr/v4/testgen/grammars/ParseTrees/Sync.st @@ -0,0 +1,13 @@ +grammar ; +s +@init { + +} +@after { + +} + : r=a ; +a : 'x' 'y'* '!' + ; +Z : 'z' + ; diff --git a/tool/test/org/antlr/v4/testgen/grammars/ParseTrees/Token2.st b/tool/test/org/antlr/v4/testgen/grammars/ParseTrees/Token2.st new file mode 100644 index 000000000..8261e8503 --- /dev/null +++ b/tool/test/org/antlr/v4/testgen/grammars/ParseTrees/Token2.st @@ -0,0 +1,11 @@ +grammar ; +s +@init { + +} +@after { + +} + : r=a ; +a : 'x' 'y' + ; diff --git a/tool/test/org/antlr/v4/testgen/grammars/ParseTrees/TokenAndRuleContextString.st b/tool/test/org/antlr/v4/testgen/grammars/ParseTrees/TokenAndRuleContextString.st new file mode 100644 index 000000000..b418522e3 --- /dev/null +++ b/tool/test/org/antlr/v4/testgen/grammars/ParseTrees/TokenAndRuleContextString.st @@ -0,0 +1,12 @@ +grammar ; +s +@init { + +} +@after { + +} + : r=a ; +a : 'x' { + +} ; diff --git a/tool/test/org/antlr/v4/testgen/grammars/ParseTrees/test2Alts.st b/tool/test/org/antlr/v4/testgen/grammars/ParseTrees/test2Alts.st new file mode 100644 index 000000000..67eb15bea --- /dev/null +++ b/tool/test/org/antlr/v4/testgen/grammars/ParseTrees/test2Alts.st @@ -0,0 +1,11 @@ +grammar ; +s +@init { + +} +@after { + +} + : r=a ; +a : 'x' | 'y' + ;