diff --git a/tool/test/org/antlr/v4/test/rt/gen/Generator.java b/tool/test/org/antlr/v4/test/rt/gen/Generator.java index e5e04fcb7..1553ce3de 100644 --- a/tool/test/org/antlr/v4/test/rt/gen/Generator.java +++ b/tool/test/org/antlr/v4/test/rt/gen/Generator.java @@ -567,6 +567,10 @@ public class Generator { "aa", "", "line 1:1 mismatched input 'a' expecting 'b'\n"); + file.addParserTest(input, "TokenMismatch2", "T", "stat", + "( ~FORCE_ERROR~ ", + "", + "line 1:2 mismatched input '~FORCE_ERROR~' expecting ')'\n"); file.addParserTest(input, "SingleTokenDeletion", "T", "a", "aab", "", diff --git a/tool/test/org/antlr/v4/test/rt/gen/grammars/ParserErrors/TokenMismatch2.st b/tool/test/org/antlr/v4/test/rt/gen/grammars/ParserErrors/TokenMismatch2.st new file mode 100644 index 000000000..6f9d19930 --- /dev/null +++ b/tool/test/org/antlr/v4/test/rt/gen/grammars/ParserErrors/TokenMismatch2.st @@ -0,0 +1,9 @@ +grammar ; + +stat: ( '(' expr? ')' )? EOF ; +expr: ID '=' STR ; + +ERR : '~FORCE_ERROR~' ; +ID : [a-zA-Z]+ ; +STR : '"' ~["]* '"' ; +WS : [ \t\r\n]+ -> skip ; \ No newline at end of file diff --git a/tool/test/org/antlr/v4/test/rt/java/TestParserErrors.java b/tool/test/org/antlr/v4/test/rt/java/TestParserErrors.java index 0c9c1edb5..db0c5d986 100644 --- a/tool/test/org/antlr/v4/test/rt/java/TestParserErrors.java +++ b/tool/test/org/antlr/v4/test/rt/java/TestParserErrors.java @@ -17,6 +17,23 @@ public class TestParserErrors extends BaseTest { assertEquals("line 1:1 mismatched input 'a' expecting 'b'\n", this.stderrDuringParse); } + /* this file and method are generated, any edit will be overwritten by the next generation */ + @Test + public void testTokenMismatch2() throws Exception { + String grammar = "grammar T;\n" + + "\n" + + "stat: ( '(' expr? ')' )? EOF ;\n" + + "expr: ID '=' STR ;\n" + + "\n" + + "ERR : '~FORCE_ERROR~' ;\n" + + "ID : [a-zA-Z]+ ;\n" + + "STR : '\"' ~[\"]* '\"' ;\n" + + "WS : [ \\t\\r\\n]+ -> skip ;"; + String found = execParser("T.g4", grammar, "TParser", "TLexer", "stat", "( ~FORCE_ERROR~ ", false); + assertEquals("", found); + assertEquals("line 1:2 mismatched input '~FORCE_ERROR~' expecting ')'\n", this.stderrDuringParse); + } + /* this file and method are generated, any edit will be overwritten by the next generation */ @Test public void testSingleTokenDeletion() throws Exception {