From e0937a6322c18a27a3638b1937e6f395ae14ec9a Mon Sep 17 00:00:00 2001 From: Sam Harwell Date: Sat, 24 May 2014 13:14:08 -0500 Subject: [PATCH] Add regression test for #561 (token named ATN breaks reference to ATN.INVALID_ALT_NUMBER) --- .../org/antlr/v4/test/TestParserExec.java | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/tool/test/org/antlr/v4/test/TestParserExec.java b/tool/test/org/antlr/v4/test/TestParserExec.java index 53b5db1c6..c61f7c09e 100644 --- a/tool/test/org/antlr/v4/test/TestParserExec.java +++ b/tool/test/org/antlr/v4/test/TestParserExec.java @@ -441,4 +441,25 @@ public class TestParserExec extends BaseTest { assertEquals("", found); assertNull(stderrDuringParse); } + + /** + * This is a regression test for antlr/antlr4#561 "Issue with parser + * generation in 4.2.2" + * https://github.com/antlr/antlr4/issues/561 + */ + @Test public void testReferenceToATN() throws Exception { + String grammar = + "grammar T;\n" + + "a : (ID|ATN)* ATN? {System.out.println($text);} ;\n" + + "ID : 'a'..'z'+ ;\n" + + "ATN : '0'..'9'+;\n" + + "WS : (' '|'\\n') -> skip ;\n"; + + String found = execParser("T.g4", grammar, "TParser", "TLexer", "a", + "", false); + assertEquals("\n", found); + found = execParser("T.g4", grammar, "TParser", "TLexer", "a", + "a 34 c", false); + assertEquals("a34c\n", found); + } }