Skip to content

Commit

Permalink
♻️ (parser): Cleanup statement lookup
Browse files Browse the repository at this point in the history
semver: chore
  • Loading branch information
Somfic committed Jun 13, 2024
1 parent dad925a commit 9344a7d
Showing 1 changed file with 2 additions and 14 deletions.
16 changes: 2 additions & 14 deletions src/parser/statement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,13 @@ use super::{
lookup::BindingPower,
macros::{
expect_any_token, expect_expression, expect_token, expect_token_value, expect_tokens,
expect_type,
expect_type, expect_valid_token,
},
Diagnostic, Parser, Statement,
};

pub fn parse(parser: &Parser, cursor: usize) -> Result<(Statement, usize), Diagnostic> {
let lexeme = parser.lexemes.get(cursor);

if lexeme.is_none() {
return Err(Diagnostic::error(cursor, 1, "Expected expression"));
}

let lexeme = lexeme.unwrap();

let token = match lexeme {
Lexeme::Valid(token) => token,
Lexeme::Invalid(_) => return Err(Diagnostic::error(cursor, 0, "Invalid token")),
};

let (token, _) = expect_valid_token!(parser, cursor);
let statement_handler = parser.lookup.statement_lookup.get(&token.token_type);

match statement_handler {
Expand Down

0 comments on commit 9344a7d

Please sign in to comment.