diff --git a/runtime/Java/src/org/antlr/v4/runtime/atn/LexerATNConfig.java b/runtime/Java/src/org/antlr/v4/runtime/atn/LexerATNConfig.java index 5cf5a1dbc..d3f857d85 100644 --- a/runtime/Java/src/org/antlr/v4/runtime/atn/LexerATNConfig.java +++ b/runtime/Java/src/org/antlr/v4/runtime/atn/LexerATNConfig.java @@ -76,7 +76,7 @@ public class LexerATNConfig extends ATNConfig { } public LexerATNConfig exitNonGreedyBlock() { - if (!isGreedy()) { + if (isGreedy()) { return this; } 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 3d1439cf7..95d39f7f8 100644 --- a/runtime/Java/src/org/antlr/v4/runtime/atn/LexerATNSimulator.java +++ b/runtime/Java/src/org/antlr/v4/runtime/atn/LexerATNSimulator.java @@ -417,6 +417,7 @@ public class LexerATNSimulator extends ATNSimulator { } if (!((LexerATNConfig)config).isGreedy()) { + assert !(config.state instanceof RuleStopState); nonGreedyAlts.set(config.alt); } } @@ -602,13 +603,13 @@ public class LexerATNSimulator extends ATNSimulator { } ATNState p = config.state; + boolean nonGreedy = p instanceof DecisionState && ((DecisionState)p).nonGreedy + || p instanceof PlusBlockStartState && ((PlusBlockStartState)p).loopBackState.nonGreedy; for (int i=0; i