predTransition method
ATNConfig?
predTransition(
- ATNConfig config,
- PredicateTransition pt,
- bool collectPredicates,
- bool inContext,
- bool fullCtx,
Implementation
ATNConfig? predTransition(
ATNConfig config,
PredicateTransition pt,
bool collectPredicates,
bool inContext,
bool fullCtx,
) {
if (debug) {
log('PRED (collectPredicates=$collectPredicates) '
'${pt.ruleIndex}:${pt.predIndex}'
', ctx dependent=${pt.isCtxDependent}');
log('context surrounding pred is ${parser.getRuleInvocationStack()}');
}
ATNConfig? c;
if (collectPredicates &&
(!pt.isCtxDependent || (pt.isCtxDependent && inContext))) {
if (fullCtx) {
// In full context mode, we can evaluate predicates on-the-fly
// during closure, which dramatically reduces the size of
// the config sets. It also obviates the need to test predicates
// later during conflict resolution.
final currentPosition = input.index;
input.seek(startIndex);
final predSucceeds = evalSemanticContextOne(
pt.predicate,
_outerContext,
config.alt,
fullCtx,
);
input.seek(currentPosition);
if (predSucceeds) {
c = ATNConfig.dup(config, state: pt.target); // no pred context
}
} else {
final newSemCtx =
SemanticContext.and(config.semanticContext, pt.predicate);
c = ATNConfig.dup(config, state: pt.target, semanticContext: newSemCtx);
}
} else {
c = ATNConfig.dup(config, state: pt.target);
}
if (debug) log('config from pred transition=$c');
return c;
}