Merge pull request #593 from sharwell/fix-590

Fix support for element options on semantic predicates in LR rules
This commit is contained in:
Sam Harwell 2014-06-01 22:36:34 -05:00
commit 0968498f3e
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" +