closureCheckingStopState method
void
closureCheckingStopState()
Implementation
void closureCheckingStopState(
ATNConfig config,
ATNConfigSet configs,
Set<ATNConfig> closureBusy,
bool collectPredicates,
bool fullCtx,
int depth,
bool treatEofAsEpsilon) {
if (debug) log('closure(' + config.toString(parser, true) + ')');
assert(config.context != null);
final configContext = config.context!;
if (config.state is RuleStopState) {
// We hit rule end. If we have context info, use it
// run thru all possible stack tops in ctx
if (!configContext.isEmpty) {
for (var i = 0; i < configContext.length; i++) {
if (configContext.getReturnState(i) ==
PredictionContext.EMPTY_RETURN_STATE) {
if (fullCtx) {
configs.add(
ATNConfig.dup(
config,
state: config.state,
context: EmptyPredictionContext.Instance,
),
mergeCache);
continue;
} else {
// we have no context info, just chase follow links (if greedy)
if (debug) {
log('FALLING off rule ' + getRuleName(config.state.ruleIndex));
}
closure_(
config,
configs,
closureBusy,
collectPredicates,
fullCtx,
depth,
treatEofAsEpsilon,
);
}
continue;
}
final returnState = atn.states[configContext.getReturnState(i)]!;
final newContext = configContext.getParent(i); // "pop" return state
final c = ATNConfig(
returnState,
config.alt,
newContext,
config.semanticContext,
);
// While we have context to pop back from, we may have
// gotten that context AFTER having falling off a rule.
// Make sure we track that we are now out of context.
//
// This assignment also propagates the
// isPrecedenceFilterSuppressed() value to the new
// configuration.
c.reachesIntoOuterContext = config.reachesIntoOuterContext;
// assert(depth > int.MIN_VALUE);
closureCheckingStopState(c, configs, closureBusy, collectPredicates,
fullCtx, depth - 1, treatEofAsEpsilon);
}
return;
} else if (fullCtx) {
// reached end of start rule
configs.add(config, mergeCache);
return;
} else {
// else if we have no context info, just chase follow links (if greedy)
if (debug) {
log('FALLING off rule ' + getRuleName(config.state.ruleIndex));
}
}
}
closure_(
config,
configs,
closureBusy,
collectPredicates,
fullCtx,
depth,
treatEofAsEpsilon,
);
}