expect method

bool expect(
  1. List<String> types, {
  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> types, {bool consume = false}) {
  for (var i = 0; i < types.length; ++i) {
    if (peek(i).type != types[i]) {
      return false;
    }
  }
  if (consume) {
    advance(types.length);
  }
  return true;
}