From 9cc45d4a2f3a90b91103475c896b59d07eb87bf9 Mon Sep 17 00:00:00 2001 From: Noro Date: Tue, 6 May 2025 15:03:34 -0400 Subject: [PATCH] duplicate token --- Cargo.lock | 4 ++-- src/parser/parser.rs | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 042104d..9fa5e0b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,7 +1,7 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. -version = 3 +version = 4 [[package]] name = "fddl" -version = "0.0.3" +version = "0.0.2" diff --git a/src/parser/parser.rs b/src/parser/parser.rs index 8364f16..adc9135 100644 --- a/src/parser/parser.rs +++ b/src/parser/parser.rs @@ -51,11 +51,12 @@ impl Parser { fn parse_variable_declaration(&mut self) -> Option { // Assuming 'let' token is already consumed by match_token - let token = self.peek_and_advance().cloned(); // Need a way to get the identifier token + // peek_and_advance() returns Option, which is what we want. + let token_option = self.peek_and_advance(); - if let Some(Token::Identifier(name)) = token { + if let Some(Token::Identifier(name)) = token_option { let initializer = if self.match_token(Token::Equal) { - self.parse_expression() // Needs implemented parse_expression + self.parse_expression() } else { None }; @@ -63,13 +64,12 @@ impl Parser { if self.match_token(Token::Semicolon) { Some(Statement::VariableDeclaration(name, initializer)) } else { - // Error: Missing semicolon eprintln!("Error: Expected ';' after variable declaration."); None } } else { eprintln!("Error: Expected variable name after 'let'."); - // Potentially consume tokens until next semicolon or brace to recover? + // If token_option was None or not an Identifier, this branch is taken. None } }