Merge pull request #593 from sharwell/fix-590
Fix support for element options on semantic predicates in LR rules
This commit is contained in:
commit
0968498f3e
|
@ -179,8 +179,8 @@ element
|
|||
| ^(SET setElement+)
|
||||
| RULE_REF
|
||||
| ebnf
|
||||
| ACTION
|
||||
| SEMPRED
|
||||
| ^(ACTION elementOptions?)
|
||||
| ^(SEMPRED elementOptions?)
|
||||
| EPSILON
|
||||
;
|
||||
|
||||
|
|
|
@ -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}?<fail='custom message'>\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" +
|
||||
|
|
Loading…
Reference in New Issue