matchId method

TokenIdentifier matchId()

If the current token is an identifier, advance 1 and return the original token. If not, generate an error.

Implementation

TokenIdentifier matchId() {
  if (curTok is TokenIdentifier) {
    return advance() as TokenIdentifier;
  } else {
    final err = HTError.unexpectedToken(
      HTLocale.current.identifier,
      curTok.lexeme,
      filename: currrentFileName,
      line: curTok.line,
      column: curTok.column,
      offset: curTok.offset,
      length: curTok.length,
    );
    errors.add(err);
    final idTok = advance();
    return TokenIdentifier(
      lexeme: idTok.lexeme,
      line: idTok.line,
      column: idTok.column,
      offset: idTok.offset,
      previous: idTok.previous,
      next: idTok.next,
    );
  }
}