mirror of
https://github.com/urinalcaketopper/fddl.git
synced 2025-06-07 05:34:47 +00:00
duplicate token
This commit is contained in:
parent
4d7f5ce8ad
commit
9cc45d4a2f
4
Cargo.lock
generated
4
Cargo.lock
generated
@ -1,7 +1,7 @@
|
|||||||
# This file is automatically @generated by Cargo.
|
# This file is automatically @generated by Cargo.
|
||||||
# It is not intended for manual editing.
|
# It is not intended for manual editing.
|
||||||
version = 3
|
version = 4
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "fddl"
|
name = "fddl"
|
||||||
version = "0.0.3"
|
version = "0.0.2"
|
||||||
|
@ -51,11 +51,12 @@ impl Parser {
|
|||||||
|
|
||||||
fn parse_variable_declaration(&mut self) -> Option<Statement> {
|
fn parse_variable_declaration(&mut self) -> Option<Statement> {
|
||||||
// Assuming 'let' token is already consumed by match_token
|
// 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) {
|
let initializer = if self.match_token(Token::Equal) {
|
||||||
self.parse_expression() // Needs implemented parse_expression
|
self.parse_expression()
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
};
|
};
|
||||||
@ -63,13 +64,12 @@ impl Parser {
|
|||||||
if self.match_token(Token::Semicolon) {
|
if self.match_token(Token::Semicolon) {
|
||||||
Some(Statement::VariableDeclaration(name, initializer))
|
Some(Statement::VariableDeclaration(name, initializer))
|
||||||
} else {
|
} else {
|
||||||
// Error: Missing semicolon
|
|
||||||
eprintln!("Error: Expected ';' after variable declaration.");
|
eprintln!("Error: Expected ';' after variable declaration.");
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
eprintln!("Error: Expected variable name after 'let'.");
|
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
|
None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user