isExpectedToken method

bool isExpectedToken(
  1. int symbol
)

Checks whether or not symbol can follow the current state in the ATN. The behavior of this method is equivalent to the following, but is implemented such that the complete context-sensitive follow set does not need to be explicitly constructed.

return expectedTokens.contains(symbol);

@param symbol the symbol type to check @return true if symbol can follow the current state in the ATN, otherwise false.

Implementation

bool isExpectedToken(int symbol) {
//   		return interpreter!.atn.nextTokens(_ctx);
  final atn = interpreter!.atn;
  var ctx = context;
  final s = atn.states[state];
  var following = atn.nextTokens(s!);
  if (following.contains(symbol)) {
    return true;
  }
//        log("following "+s+"="+following);
  if (!following.contains(Token.EPSILON)) return false;

  while (ctx != null &&
      ctx.invokingState >= 0 &&
      following.contains(Token.EPSILON)) {
    final invokingState = atn.states[ctx.invokingState]!;
    final rt = invokingState.transition(0) as RuleTransition;
    following = atn.nextTokens(rt.followState);
    if (following.contains(symbol)) {
      return true;
    }

    ctx = ctx.parent;
  }

  if (following.contains(Token.EPSILON) && symbol == Token.EOF) {
    return true;
  }

  return false;
}