diff --git a/tool/test/org/antlr/v4/test/TestLeftRecursion.java b/tool/test/org/antlr/v4/test/TestLeftRecursion.java index 202fd5e61..b5640da4b 100644 --- a/tool/test/org/antlr/v4/test/TestLeftRecursion.java +++ b/tool/test/org/antlr/v4/test/TestLeftRecursion.java @@ -342,6 +342,70 @@ public class TestLeftRecursion extends BaseTest { runTests(grammar, tests, "s"); } + /** + * This is a regression test for antlr/antlr4#677 "labels not working in + * grammar file". + * https://github.com/antlr/antlr4/issues/677 + * + *
This test treats {@code ,} and {@code >>} as part of a single compound + * operator (similar to a ternary operator).
+ */ + @Test public void testReturnValueAndActionsList1() throws Exception { + String grammar = + "grammar T;\n" + + "s @after {System.out.println($ctx.toStringTree(this));} : expr EOF;\n" + + "expr:\n" + + " a=expr '*' a=expr #Factor\n" + + " | b+=expr (',' b+=expr)* '>>' c=expr #Send\n" + + " | ID #JustId //semantic check on modifiers\n" + + ";\n" + + "\n" + + "ID : ('a'..'z'|'A'..'Z'|'_')\n" + + " ('a'..'z'|'A'..'Z'|'0'..'9'|'_')*\n" + + ";\n" + + "\n" + + "WS : [ \\t\\n]+ -> skip ;\n"; + String[] tests = { + "a*b", "(s (expr (expr a) * (expr b))This test treats the {@code ,} and {@code >>} operators separately.
+ */ + @Test public void testReturnValueAndActionsList2() throws Exception { + String grammar = + "grammar T;\n" + + "s @after {System.out.println($ctx.toStringTree(this));} : expr EOF;\n" + + "expr:\n" + + " a=expr '*' a=expr #Factor\n" + + " | b+=expr ',' b+=expr #Comma\n" + + " | b+=expr '>>' c=expr #Send\n" + + " | ID #JustId //semantic check on modifiers\n" + + ";\n" + + "\n" + + "ID : ('a'..'z'|'A'..'Z'|'_')\n" + + " ('a'..'z'|'A'..'Z'|'0'..'9'|'_')*\n" + + ";\n" + + "\n" + + "WS : [ \\t\\n]+ -> skip ;\n"; + String[] tests = { + "a*b", "(s (expr (expr a) * (expr b))