forked from jasder/antlr
Fixes to LexerATNSimulator.closure, fixes to non-greedy positive closure
This commit is contained in:
parent
a40073a8cc
commit
6fa853c14f
|
@ -568,10 +568,15 @@ public class LexerATNSimulator extends ATNSimulator {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( config.context == null || config.context.isEmpty() ) {
|
if ( config.context == null || config.context.hasEmpty() ) {
|
||||||
configs.add(config);
|
if (config.context == null || config.context.isEmpty()) {
|
||||||
return;
|
configs.add(config);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
configs.add(new LexerATNConfig(config, config.state, PredictionContext.EMPTY));
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( config.context!=null && !config.context.isEmpty() ) {
|
if ( config.context!=null && !config.context.isEmpty() ) {
|
||||||
for (SingletonPredictionContext ctx : config.context) {
|
for (SingletonPredictionContext ctx : config.context) {
|
||||||
if ( !ctx.isEmpty() ) {
|
if ( !ctx.isEmpty() ) {
|
||||||
|
@ -603,8 +608,8 @@ public class LexerATNSimulator extends ATNSimulator {
|
||||||
}
|
}
|
||||||
|
|
||||||
ATNState p = config.state;
|
ATNState p = config.state;
|
||||||
boolean nonGreedy = p instanceof DecisionState && ((DecisionState)p).nonGreedy
|
boolean nonGreedy = (p instanceof DecisionState && ((DecisionState)p).nonGreedy && !(p instanceof PlusLoopbackState))
|
||||||
|| p instanceof PlusBlockStartState && ((PlusBlockStartState)p).loopBackState.nonGreedy;
|
|| (p instanceof PlusBlockStartState && ((PlusBlockStartState)p).loopBackState.nonGreedy);
|
||||||
for (int i=0; i<p.getNumberOfTransitions(); i++) {
|
for (int i=0; i<p.getNumberOfTransitions(); i++) {
|
||||||
Transition t = p.transition(i);
|
Transition t = p.transition(i);
|
||||||
LexerATNConfig c = getEpsilonTarget(config, t, configs);
|
LexerATNConfig c = getEpsilonTarget(config, t, configs);
|
||||||
|
@ -627,7 +632,7 @@ public class LexerATNSimulator extends ATNSimulator {
|
||||||
ATNState p = config.state;
|
ATNState p = config.state;
|
||||||
switch (p.getStateType()) {
|
switch (p.getStateType()) {
|
||||||
case ATNState.PLUS_LOOP_BACK:
|
case ATNState.PLUS_LOOP_BACK:
|
||||||
if (t.target instanceof PlusBlockStartState && ((PlusBlockStartState)t.target).nonGreedy) {
|
if (((PlusLoopbackState)p).nonGreedy) {
|
||||||
config = config.exitNonGreedyBlock();
|
config = config.exitNonGreedyBlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -638,9 +643,18 @@ public class LexerATNSimulator extends ATNSimulator {
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ATNState.LOOP_END:
|
case ATNState.LOOP_END:
|
||||||
ATNState loopEntry = ((LoopEndState)p).loopBackState.transition(0).target;
|
ATNState loopBackState = ((LoopEndState)p).loopBackState;
|
||||||
if (loopEntry instanceof StarLoopEntryState && ((StarLoopEntryState)loopEntry).nonGreedy) {
|
if (loopBackState instanceof PlusLoopbackState) {
|
||||||
config = config.exitNonGreedyBlock();
|
if (((PlusLoopbackState)loopBackState).nonGreedy) {
|
||||||
|
config = config.exitNonGreedyBlock();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
assert loopBackState instanceof StarLoopbackState;
|
||||||
|
ATNState loopEntry = loopBackState.transition(0).target;
|
||||||
|
if (loopEntry instanceof StarLoopEntryState && ((StarLoopEntryState)loopEntry).nonGreedy) {
|
||||||
|
config = config.exitNonGreedyBlock();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -70,6 +70,10 @@ public abstract class PredictionContext implements Iterable<SingletonPredictionC
|
||||||
return this == EMPTY;
|
return this == EMPTY;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean hasEmpty() {
|
||||||
|
return getInvokingState(size() - 1) == EMPTY_INVOKING_STATE;
|
||||||
|
}
|
||||||
|
|
||||||
public abstract PredictionContext popAll(
|
public abstract PredictionContext popAll(
|
||||||
int invokingState,
|
int invokingState,
|
||||||
boolean fullCtx,
|
boolean fullCtx,
|
||||||
|
|
Loading…
Reference in New Issue