forked from jasder/antlr
prefix left-recursive alts weren't recognized with actions on end.
This commit is contained in:
parent
642177f716
commit
7287f5a2d3
|
@ -148,7 +148,7 @@ ternary
|
|||
prefix
|
||||
: ^( ALT {setTokenPrec((GrammarAST)input.LT(1), currentOuterAltNumber);}
|
||||
({!((CommonTree)input.LT(1)).getText().equals(ruleName)}? element)+
|
||||
recurse
|
||||
recurse ACTION?
|
||||
)
|
||||
;
|
||||
|
||||
|
|
|
@ -255,6 +255,27 @@ public class TestLeftRecursion extends BaseTest {
|
|||
runTests(grammar, tests, "s");
|
||||
}
|
||||
|
||||
@Test public void testPrefixOpWithActionAndLabel() throws Exception {
|
||||
String grammar =
|
||||
"grammar T;\n" +
|
||||
"s : e {System.out.println($e.result);} ;\n" +
|
||||
"\n" +
|
||||
"e returns [String result]\n" +
|
||||
" : ID '=' e1=e { $result = \"(\" + $ID.getText() + \"=\" + $e1.result + \")\"; }\n" +
|
||||
" | ID { $result = $ID.getText(); }\n" +
|
||||
" | e1=e '+' e2=e { $result = \"(\" + $e1.result + \"+\" + $e2.result + \")\"; }\n" +
|
||||
" ;\n" +
|
||||
"ID : 'a'..'z'+ ;\n" +
|
||||
"INT : '0'..'9'+ ;\n" +
|
||||
"WS : (' '|'\\n') {skip();} ;\n";
|
||||
String[] tests = {
|
||||
"a", "a",
|
||||
"a+b", "(a+b)",
|
||||
"a=b+c", "((a=b)+c)",
|
||||
};
|
||||
runTests(grammar, tests, "s");
|
||||
}
|
||||
|
||||
public void runTests(String grammar, String[] tests, String startRule) {
|
||||
rawGenerateAndBuildRecognizer("T.g", grammar, "TParser", "TLexer");
|
||||
writeRecognizerAndCompile("TParser",
|
||||
|
|
Loading…
Reference in New Issue