From fb87e4c78582e641ec1993ea9bef06771c23c7c3 Mon Sep 17 00:00:00 2001 From: Sam Harwell Date: Tue, 16 Oct 2012 07:46:46 -0500 Subject: [PATCH] Another fix for non-greedy with closures --- .../src/org/antlr/v4/runtime/atn/LexerATNSimulator.java | 9 +++++---- .../src/org/antlr/v4/runtime/atn/StarLoopbackState.java | 3 +++ 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/runtime/Java/src/org/antlr/v4/runtime/atn/LexerATNSimulator.java b/runtime/Java/src/org/antlr/v4/runtime/atn/LexerATNSimulator.java index 966a91d7d..ece984866 100644 --- a/runtime/Java/src/org/antlr/v4/runtime/atn/LexerATNSimulator.java +++ b/runtime/Java/src/org/antlr/v4/runtime/atn/LexerATNSimulator.java @@ -639,7 +639,9 @@ public class LexerATNSimulator extends ATNSimulator { break; case ATNState.STAR_LOOP_BACK: - config = config.exitNonGreedyBlock(); + if (((StarLoopbackState)p).getLoopEntryState().nonGreedy) { + config = config.exitNonGreedyBlock(); + } break; case ATNState.LOOP_END: @@ -650,9 +652,8 @@ public class LexerATNSimulator extends ATNSimulator { } } else { - assert loopBackState instanceof StarLoopbackState; - ATNState loopEntry = loopBackState.transition(0).target; - if (loopEntry instanceof StarLoopEntryState && ((StarLoopEntryState)loopEntry).nonGreedy) { + StarLoopbackState starLoopbackState = (StarLoopbackState)loopBackState; + if (starLoopbackState.getLoopEntryState().nonGreedy) { config = config.exitNonGreedyBlock(); } } diff --git a/runtime/Java/src/org/antlr/v4/runtime/atn/StarLoopbackState.java b/runtime/Java/src/org/antlr/v4/runtime/atn/StarLoopbackState.java index 685adf1fc..b05f92cf2 100644 --- a/runtime/Java/src/org/antlr/v4/runtime/atn/StarLoopbackState.java +++ b/runtime/Java/src/org/antlr/v4/runtime/atn/StarLoopbackState.java @@ -30,4 +30,7 @@ package org.antlr.v4.runtime.atn; public class StarLoopbackState extends ATNState { + public final StarLoopEntryState getLoopEntryState() { + return (StarLoopEntryState)transition(0).target; + } }