diff --git a/tool/test/org/antlr/v4/test/tool/TestCompositeGrammars.java b/tool/test/org/antlr/v4/test/tool/TestCompositeGrammars.java index 85b284008..72638929d 100644 --- a/tool/test/org/antlr/v4/test/tool/TestCompositeGrammars.java +++ b/tool/test/org/antlr/v4/test/tool/TestCompositeGrammars.java @@ -385,7 +385,8 @@ public class TestCompositeGrammars extends BaseTest { /** * This is a regression test for antlr/antlr4#670 "exception when importing - * grammar". + * grammar". I think this one always worked but I found that a different + * Java grammar caused an error and so I made the testImportLeftRecursiveGrammar() test below. * https://github.com/antlr/antlr4/issues/670 */ // TODO: migrate to test framework @@ -403,4 +404,32 @@ public class TestCompositeGrammars extends BaseTest { assertEquals("", found); assertNull(stderrDuringParse); } + + /** + * This is a regression test for antlr/antlr4#670 "exception when importing + * grammar". + * https://github.com/antlr/antlr4/issues/670 + */ + // TODO: migrate to test framework + @Test + public void testImportLeftRecursiveGrammar() throws Exception { + String slave = + "grammar Java;\n" + + "e : '(' e ')'\n" + + " | e '=' e\n" + + " | ID\n" + + " ;\n" + + "ID : [a-z]+ ;\n"; + String master = + "grammar T;\n" + + "import Java;\n" + + "s : e ;\n"; + + System.out.println("dir "+tmpdir); + mkdir(tmpdir); + writeFile(tmpdir, "Java.g4", slave); + String found = execParser("T.g4", master, "TParser", "TLexer", "s", "a=b", debug); + assertEquals("", found); + assertNull(stderrDuringParse); + } }