markPrecedenceDecisions method

void markPrecedenceDecisions(
  1. ATN atn
)

Analyze the StarLoopEntryState states in the specified ATN to set the {@link StarLoopEntryState#isPrecedenceDecision} field to the correct value.

@param atn The ATN.

Implementation

void markPrecedenceDecisions(ATN atn) {
  for (var state in atn.states) {
    if (state is StarLoopEntryState) {
      /* We analyze the ATN to determine if this ATN decision state is the
			 * decision for the closure block that determines whether a
			 * precedence rule should continue or complete.
			 */
      if (atn.ruleToStartState[state.ruleIndex].isLeftRecursiveRule) {
        final maybeLoopEndState =
            state.transition(state.numberOfTransitions - 1).target;
        if (maybeLoopEndState is LoopEndState) {
          if (maybeLoopEndState.epsilonOnlyTransitions &&
              maybeLoopEndState.transition(0).target is RuleStopState) {
            state.isPrecedenceDecision = true;
          }
        }
      }
    }
  }
}