diff --git a/tool/src/org/antlr/v4/parse/LeftRecursiveRuleWalker.g b/tool/src/org/antlr/v4/parse/LeftRecursiveRuleWalker.g index e8c26faf6..bdfea1b65 100644 --- a/tool/src/org/antlr/v4/parse/LeftRecursiveRuleWalker.g +++ b/tool/src/org/antlr/v4/parse/LeftRecursiveRuleWalker.g @@ -179,8 +179,8 @@ element | ^(SET setElement+) | RULE_REF | ebnf - | ACTION - | SEMPRED + | ^(ACTION elementOptions?) + | ^(SEMPRED elementOptions?) | EPSILON ; diff --git a/tool/test/org/antlr/v4/test/TestLeftRecursion.java b/tool/test/org/antlr/v4/test/TestLeftRecursion.java index 538e9ac24..b7866cab4 100644 --- a/tool/test/org/antlr/v4/test/TestLeftRecursion.java +++ b/tool/test/org/antlr/v4/test/TestLeftRecursion.java @@ -109,6 +109,23 @@ public class TestLeftRecursion extends BaseTest { assertEquals(expecting, found); } + @Test + public void testSemPredFailOption() throws Exception { + String grammar = + "grammar T;\n" + + "s @after {System.out.println($ctx.toStringTree(this));} : a ;\n" + + "a : a ID {false}?\n" + + " | ID" + + " ;\n" + + "ID : 'a'..'z'+ ;\n" + + "WS : (' '|'\\n') -> skip ;\n"; + String found = execParser("T.g4", grammar, "TParser", "TLexer", + "s", "x y z", debug); + String expecting = "(s (a (a x) y z))\n"; + assertEquals(expecting, found); + assertEquals("line 1:4 rule a custom message\n", stderrDuringParse); + } + @Test public void testTernaryExpr() throws Exception { String grammar = "grammar T;\n" +