duplicate token

This commit is contained in:
Noro 2025-05-06 15:03:34 -04:00
parent 4d7f5ce8ad
commit 9cc45d4a2f
2 changed files with 7 additions and 7 deletions

4
Cargo.lock generated
View File

@ -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"

View File

@ -51,11 +51,12 @@ impl Parser {
fn parse_variable_declaration(&mut self) -> Option<Statement> {
// 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<Token>, 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
}
}