expect method

bool expect(
  1. List<String> lexemes, {
  2. bool consume = false,
})

Check current token and some tokens after it to see if the types match, return a boolean result. If consume is true, will advance.

Implementation

bool expect(List<String> lexemes, {bool consume = false}) {
  for (var i = 0; i < lexemes.length; ++i) {
    if (peek(i).lexeme != lexemes[i]) {
      return false;
    }
  }
  if (consume) {
    advance(lexemes.length);
  }
  return true;
}