diff --git a/runtime/Java/src/org/antlr/v4/runtime/Parser.java b/runtime/Java/src/org/antlr/v4/runtime/Parser.java index 5a8fe9827..d831b234c 100644 --- a/runtime/Java/src/org/antlr/v4/runtime/Parser.java +++ b/runtime/Java/src/org/antlr/v4/runtime/Parser.java @@ -577,10 +577,11 @@ public abstract class Parser extends Recognizer { */ @Deprecated public void enterRecursionRule(ParserRuleContext localctx, int ruleIndex) { - enterRecursionRule(localctx, ruleIndex, 0); + enterRecursionRule(localctx, getATN().ruleToStartState[ruleIndex].stateNumber, ruleIndex, 0); } - public void enterRecursionRule(ParserRuleContext localctx, int ruleIndex, int precedence) { + public void enterRecursionRule(ParserRuleContext localctx, int state, int ruleIndex, int precedence) { + setState(state); _precedenceStack.push(precedence); _ctx = localctx; _ctx.start = _input.LT(1); diff --git a/runtime/Java/src/org/antlr/v4/runtime/ParserInterpreter.java b/runtime/Java/src/org/antlr/v4/runtime/ParserInterpreter.java index 616c75e39..f01ded747 100644 --- a/runtime/Java/src/org/antlr/v4/runtime/ParserInterpreter.java +++ b/runtime/Java/src/org/antlr/v4/runtime/ParserInterpreter.java @@ -30,12 +30,6 @@ package org.antlr.v4.runtime; -import org.antlr.v4.runtime.FailedPredicateException; -import org.antlr.v4.runtime.InterpreterRuleContext; -import org.antlr.v4.runtime.Parser; -import org.antlr.v4.runtime.ParserRuleContext; -import org.antlr.v4.runtime.Token; -import org.antlr.v4.runtime.TokenStream; import org.antlr.v4.runtime.atn.ATN; import org.antlr.v4.runtime.atn.ATNState; import org.antlr.v4.runtime.atn.ActionTransition; @@ -153,7 +147,7 @@ public class ParserInterpreter extends Parser { InterpreterRuleContext rootContext = new InterpreterRuleContext(null, ATNState.INVALID_STATE_NUMBER, startRuleIndex); if (startRuleStartState.isPrecedenceRule) { - enterRecursionRule(rootContext, startRuleIndex, 0); + enterRecursionRule(rootContext, startRuleStartState.stateNumber, startRuleIndex, 0); } else { enterRule(rootContext, startRuleStartState.stateNumber, startRuleIndex); @@ -180,9 +174,9 @@ public class ParserInterpreter extends Parser { } @Override - public void enterRecursionRule(ParserRuleContext localctx, int ruleIndex, int precedence) { + public void enterRecursionRule(ParserRuleContext localctx, int state, int ruleIndex, int precedence) { _parentContextStack.push(new Pair(_ctx, localctx.invokingState)); - super.enterRecursionRule(localctx, ruleIndex, precedence); + super.enterRecursionRule(localctx, state, ruleIndex, precedence); } protected ATNState getATNState() { @@ -229,7 +223,7 @@ public class ParserInterpreter extends Parser { int ruleIndex = ruleStartState.ruleIndex; InterpreterRuleContext ctx = new InterpreterRuleContext(_ctx, p.stateNumber, ruleIndex); if (ruleStartState.isPrecedenceRule) { - enterRecursionRule(ctx, ruleIndex, ((RuleTransition)transition).precedence); + enterRecursionRule(ctx, ruleStartState.stateNumber, ruleIndex, ((RuleTransition)transition).precedence); } else { enterRule(ctx, transition.target.stateNumber, ruleIndex); 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 3491aed8a..95a03650e 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 @@ -372,7 +372,7 @@ private (int _p _localctx = new (_ctx, _parentState}>); _prevctx = _localctx; int _startState = ; - enterRecursionRule(_localctx, RULE_, _p); + enterRecursionRule(_localctx, , RULE_, _p); try {