varDeclaration method

AstNode varDeclaration()

Implementation

AstNode varDeclaration() {
  Token name = consume(TokenType.identifier, "Expect variable name.");
  AstNode? initializer;
  if (match([TokenType.assign])) {
    initializer = expression();
  }
  consume(TokenType.semicolon, "Expect ';' after variable declaration.");
  return VariableDeclaration(name, initializer);
}