diff --git a/runtime/Java/src/org/antlr/v4/runtime/DefaultErrorStrategy.java b/runtime/Java/src/org/antlr/v4/runtime/DefaultErrorStrategy.java index 838fed58f..82592ad4d 100644 --- a/runtime/Java/src/org/antlr/v4/runtime/DefaultErrorStrategy.java +++ b/runtime/Java/src/org/antlr/v4/runtime/DefaultErrorStrategy.java @@ -34,7 +34,6 @@ import org.antlr.v4.runtime.atn.ATNState; import org.antlr.v4.runtime.atn.BlockStartState; import org.antlr.v4.runtime.atn.PlusBlockStartState; import org.antlr.v4.runtime.atn.PlusLoopbackState; -import org.antlr.v4.runtime.atn.RuleTransition; import org.antlr.v4.runtime.atn.StarLoopEntryState; import org.antlr.v4.runtime.atn.StarLoopbackState; import org.antlr.v4.runtime.misc.IntervalSet; @@ -522,19 +521,8 @@ public class DefaultErrorStrategy implements ANTLRErrorStrategy { */ protected IntervalSet getErrorRecoverySet(Parser recognizer) { ATN atn = recognizer.getInterpreter().atn; - RuleContext ctx = recognizer._ctx; - IntervalSet recoverSet = new IntervalSet(); - while ( ctx!=null && ctx.invokingState>=0 ) { - // compute what follows who invoked us - ATNState invokingState = atn.states.get(ctx.invokingState); - RuleTransition rt = (RuleTransition)invokingState.transition(0); - IntervalSet follow = atn.nextTokens(rt.followState); - recoverSet.addAll(follow); - ctx = ctx.parent; - } - recoverSet.remove(Token.EPSILON); -// System.out.println("recover set "+recoverSet.toString(recognizer.getTokenNames())); - return recoverSet; + ParserRuleContext ctx = recognizer._ctx; + return atn.nextTokens(atn.states.get(ctx.s), ctx); } /** Consume tokens until one matches the given token set */ diff --git a/runtime/Java/src/org/antlr/v4/runtime/Parser.java b/runtime/Java/src/org/antlr/v4/runtime/Parser.java index 3d5622e1c..0e5059cee 100644 --- a/runtime/Java/src/org/antlr/v4/runtime/Parser.java +++ b/runtime/Java/src/org/antlr/v4/runtime/Parser.java @@ -547,24 +547,7 @@ public abstract class Parser extends Recognizer { ATN atn = getInterpreter().atn; ParserRuleContext ctx = _ctx; ATNState s = atn.states.get(ctx.s); - IntervalSet following = atn.nextTokens(s); -// System.out.println("following "+s+"="+following); - if ( !following.contains(Token.EPSILON) ) return following; - IntervalSet expected = new IntervalSet(); - expected.addAll(following); - expected.remove(Token.EPSILON); - while ( ctx!=null && ctx.invokingState>=0 && following.contains(Token.EPSILON) ) { - ATNState invokingState = atn.states.get(ctx.invokingState); - RuleTransition rt = (RuleTransition)invokingState.transition(0); - following = atn.nextTokens(rt.followState); - expected.addAll(following); - expected.remove(Token.EPSILON); - ctx = (ParserRuleContext)ctx.parent; - } - if ( following.contains(Token.EPSILON) ) { - expected.add(Token.EOF); - } - return expected; + return atn.nextTokens(s, ctx); } public IntervalSet getExpectedTokensWithinCurrentRule() {