diff --git a/tool/test/org/antlr/v4/test/tool/TestParserExec.java b/tool/test/org/antlr/v4/test/tool/TestParserExec.java index 150f553f5..aecd7b123 100644 --- a/tool/test/org/antlr/v4/test/tool/TestParserExec.java +++ b/tool/test/org/antlr/v4/test/tool/TestParserExec.java @@ -107,6 +107,45 @@ public class TestParserExec extends BaseTest { assertEquals("line 1:6 rule floating_constant DEC:A floating-point constant cannot have internal white space\n", stderrDuringParse); } + /** + * This is a regression test for antlr/antlr4#563 "Inconsistent token + * handling in ANTLR4". + * https://github.com/antlr/antlr4/issues/563 + */ + // TODO: port to test framework (missing templates) + @Test public void testAlternateQuotes() throws Exception { + String lexerGrammar = + "lexer grammar ModeTagsLexer;\n" + + "\n" + + "// Default mode rules (the SEA)\n" + + "OPEN : '«' -> mode(ISLAND) ; // switch to ISLAND mode\n" + + "TEXT : ~'«'+ ; // clump all text together\n" + + "\n" + + "mode ISLAND;\n" + + "CLOSE : '»' -> mode(DEFAULT_MODE) ; // back to SEA mode \n" + + "SLASH : '/' ;\n" + + "ID : [a-zA-Z]+ ; // match/send ID in tag to parser\n"; + String parserGrammar = + "parser grammar ModeTagsParser;\n" + + "\n" + + "options { tokenVocab=ModeTagsLexer; } // use tokens from ModeTagsLexer.g4\n" + + "\n" + + "file: (tag | TEXT)* ;\n" + + "\n" + + "tag : '«' ID '»'\n" + + " | '«' '/' ID '»'\n" + + " ;"; + + boolean success = rawGenerateAndBuildRecognizer("ModeTagsLexer.g4", + lexerGrammar, + null, + "ModeTagsLexer"); + assertTrue(success); + + String found = execParser("ModeTagsParser.g4", parserGrammar, "ModeTagsParser", "ModeTagsLexer", "file", "", false); + assertEquals("", found); + assertNull(stderrDuringParse); + } /** * This is a regression test for antlr/antlr4#672 "Initialization failed in