precedenceTransition method

ATNConfig? precedenceTransition(
  1. ATNConfig config,
  2. PrecedencePredicateTransition pt,
  3. bool collectPredicates,
  4. bool inContext,
  5. bool fullCtx,
)

Implementation

ATNConfig? precedenceTransition(
    ATNConfig config,
    PrecedencePredicateTransition pt,
    bool collectPredicates,
    bool inContext,
    bool fullCtx) {
  if (debug) {
    log('PRED (collectPredicates=$collectPredicates) ${pt.precedence}>=_p, ctx dependent=true');

    log('context surrounding pred is ${parser.getRuleInvocationStack()}');
  }

  ATNConfig? c;
  if (collectPredicates && 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;
}