Fix support for element options on semantic predicates in left recursive rules (fixes #590)

This commit is contained in:
Sam Harwell 2014-06-01 12:19:10 -05:00
parent be16c71e56
commit e7a1d84197
2 changed files with 19 additions and 2 deletions

View File

@ -179,8 +179,8 @@ element
| ^(SET setElement+)
| RULE_REF
| ebnf
| ACTION
| SEMPRED
| ^(ACTION elementOptions?)
| ^(SEMPRED elementOptions?)
| EPSILON
;

View File

@ -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" +