diff --git a/runtime/Java/src/org/antlr/v4/runtime/ParserRuleContext.java b/runtime/Java/src/org/antlr/v4/runtime/ParserRuleContext.java index 3837d857d..8573f1cd9 100644 --- a/runtime/Java/src/org/antlr/v4/runtime/ParserRuleContext.java +++ b/runtime/Java/src/org/antlr/v4/runtime/ParserRuleContext.java @@ -57,7 +57,7 @@ public class ParserRuleContext extends RuleContext { public int ruleIndex; /** Set during parsing to identify which alt of rule parser is in. */ - public int alt; + public int altNum; public ParserRuleContext() { super(); } diff --git a/tool/playground/T.g b/tool/playground/T.g index 8d7c4cd68..2d79111f3 100644 --- a/tool/playground/T.g +++ b/tool/playground/T.g @@ -1,10 +1,12 @@ grammar T; s : i=ifstat {System.out.println(_input.toString(0,_input.index()-1));} ; -ifstat : 'if' '(' INT ')' ID '=' ID ';' ; + +ifstat : 'if' '(' INT ')' ID '=' ID ';' # DoIf; r[int x] returns [int y] locals [int z] - : name=ID + : name=ID # foo + | ID (ID|';'{;}) # bar ; EQ : '=' ; diff --git a/tool/resources/org/antlr/v4/tool/templates/codegen/Java/Java.stg b/tool/resources/org/antlr/v4/tool/templates/codegen/Java/Java.stg index 9227398ad..051bb8ab8 100644 --- a/tool/resources/org/antlr/v4/tool/templates/codegen/Java/Java.stg +++ b/tool/resources/org/antlr/v4/tool/templates/codegen/Java/Java.stg @@ -41,9 +41,9 @@ import org.antlr.v4.runtime.tree.ParseTreeListener; @SuppressWarnings({"all", "warnings", "unchecked", "unused"}) public interface Listener extends ParseTreeListener { - .Context ctx); -void exitRule(.Context ctx);}; separator="\n"> + (.Context ctx); +void exit(.Context ctx);}; separator="\n"> } >> @@ -55,9 +55,9 @@ import org.antlr.v4.runtime.Token; @SuppressWarnings({"all", "warnings", "unchecked", "unused"}) public class BlankListener implements Listener { - .Context ctx) { \} -public void exitRule(.Context ctx) { \}}; separator="\n"> + (.Context ctx) { \} +public void exit(.Context ctx) { \}}; separator="\n"> public void enterEveryRule(ParserRuleContext ctx) { } public void exitEveryRule(ParserRuleContext ctx) { } @@ -188,6 +188,11 @@ public QStack\<\> _stk = new QStack\<> +CodeBlockForOuterMostAlt(c, locals, preamble, ops) ::= << +_ctx.altNum = ; + +>> + CodeBlockForAlt(c, locals, preamble, ops) ::= << { @@ -442,7 +447,7 @@ ListLabelName(label) ::= "