Properly encapsulate LexerATNConfig.lexerActionExecutor, and mark as final

This commit is contained in:
Sam Harwell 2014-03-20 09:25:37 -05:00
parent 41e04a27c0
commit 27270fdd05
2 changed files with 16 additions and 5 deletions

View File

@ -36,8 +36,10 @@ import org.antlr.v4.runtime.misc.Nullable;
import org.antlr.v4.runtime.misc.ObjectEqualityComparator;
public class LexerATNConfig extends ATNConfig {
/** Capture lexer actions we traverse. */
public LexerActionExecutor lexerActionExecutor;
/**
* This is the backing field for {@link #getLexerActionExecutor}.
*/
private final LexerActionExecutor lexerActionExecutor;
private final boolean passedThroughNonGreedyDecision;
@ -47,6 +49,7 @@ public class LexerATNConfig extends ATNConfig {
{
super(state, alt, context, SemanticContext.NONE);
this.passedThroughNonGreedyDecision = false;
this.lexerActionExecutor = null;
}
public LexerATNConfig(@NotNull ATNState state,
@ -80,6 +83,14 @@ public class LexerATNConfig extends ATNConfig {
this.passedThroughNonGreedyDecision = checkNonGreedyDecision(c, state);
}
/**
* Gets the {@link LexerActionExecutor} capable of executing the embedded
* action(s) for the current configuration.
*/
public final LexerActionExecutor getLexerActionExecutor() {
return lexerActionExecutor;
}
public final boolean hasPassedThroughNonGreedyDecision() {
return passedThroughNonGreedyDecision;
}

View File

@ -346,7 +346,7 @@ public class LexerATNSimulator extends ATNSimulator {
Transition trans = c.state.transition(ti);
ATNState target = getReachableTarget(trans, t);
if ( target!=null ) {
LexerActionExecutor lexerActionExecutor = ((LexerATNConfig)c).lexerActionExecutor;
LexerActionExecutor lexerActionExecutor = ((LexerATNConfig)c).getLexerActionExecutor();
if (lexerActionExecutor != null) {
lexerActionExecutor = lexerActionExecutor.fixOffsetBeforeMatch(input.index() - startIndex);
}
@ -537,7 +537,7 @@ public class LexerATNSimulator extends ATNSimulator {
// getEpsilonTarget to return two configurations, so
// additional modifications are needed before we can support
// the split operation.
LexerActionExecutor lexerActionExecutor = LexerActionExecutor.append(config.lexerActionExecutor, atn.lexerActions[((ActionTransition)t).actionIndex]);
LexerActionExecutor lexerActionExecutor = LexerActionExecutor.append(config.getLexerActionExecutor(), atn.lexerActions[((ActionTransition)t).actionIndex]);
c = new LexerATNConfig(config, t.target, lexerActionExecutor);
break;
}
@ -684,7 +684,7 @@ public class LexerATNSimulator extends ATNSimulator {
if ( firstConfigWithRuleStopState!=null ) {
proposed.isAcceptState = true;
proposed.lexerActionExecutor = ((LexerATNConfig)firstConfigWithRuleStopState).lexerActionExecutor;
proposed.lexerActionExecutor = ((LexerATNConfig)firstConfigWithRuleStopState).getLexerActionExecutor();
proposed.prediction = atn.ruleToTokenType[firstConfigWithRuleStopState.state.ruleIndex];
}