getReachableConfigSet method
Given a starting configuration set, figure out all ATN configurations
we can reach upon input t
. Parameter reach
is a return
parameter.
Implementation
void getReachableConfigSet(
CharStream input,
ATNConfigSet configs,
ATNConfigSet reach,
int t,
) {
// this is used to skip processing for configs which have a lower priority
// than a config that already reached an accept state for the same rule
var skipAlt = ATN.INVALID_ALT_NUMBER;
for (var c in configs) {
final currentAltReachedAcceptState = c.alt == skipAlt;
if (currentAltReachedAcceptState &&
(c as LexerATNConfig).hasPassedThroughNonGreedyDecision()) {
continue;
}
if (debug) {
log('testing ${getTokenName(t)} at ${c.toString(recog, true)}\n',
level: Level.FINE.value);
}
final n = c.state.numberOfTransitions;
for (var ti = 0; ti < n; ti++) {
// for each transition
final trans = c.state.transition(ti);
final target = getReachableTarget(trans, t);
if (target != null) {
var lexerActionExecutor = (c as LexerATNConfig).lexerActionExecutor;
if (lexerActionExecutor != null) {
lexerActionExecutor = lexerActionExecutor
.fixOffsetBeforeMatch(input.index - startIndex);
}
final treatEofAsEpsilon = t == IntStream.EOF;
if (closure(
input,
LexerATNConfig.dup(c, target,
lexerActionExecutor: lexerActionExecutor),
reach,
currentAltReachedAcceptState,
true,
treatEofAsEpsilon)) {
// any remaining configs for this alt have a lower priority than
// the one that just reached an accept state.
skipAlt = c.alt;
break;
}
}
}
}
}