From 9d1e3c8d4ffd7cbaed1045bb0773c551e543994d Mon Sep 17 00:00:00 2001 From: Lucas Date: Sat, 8 Jun 2024 06:12:22 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=A8=20Fix=20lint=20warnings?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit semver: chore --- src/parser/lookup.rs | 103 ++++++++++++++++------------------------ src/parser/statement.rs | 7 ++- 2 files changed, 44 insertions(+), 66 deletions(-) diff --git a/src/parser/lookup.rs b/src/parser/lookup.rs index 8985f9b..16313a8 100644 --- a/src/parser/lookup.rs +++ b/src/parser/lookup.rs @@ -67,12 +67,7 @@ impl Lookup { self.statement_lookup.insert(token, handler); } - pub(crate) fn add_expression_handler( - &mut self, - token: Token, - binding_power: BindingPower, - handler: ExpressionHandler, - ) { + pub(crate) fn add_expression_handler(&mut self, token: Token, handler: ExpressionHandler) { self.expression_lookup.insert(token, handler); } @@ -100,7 +95,7 @@ impl Default for Lookup { lookup.add_left_expression_handler( Token::Plus, BindingPower::Additive, - |parser, cursor, lhs, binding| { + |parser, cursor, lhs, _binding| { let (rhs, cursor) = super::expression::parse(parser, cursor + 1, &BindingPower::Additive)?; Some(( @@ -113,7 +108,7 @@ impl Default for Lookup { lookup.add_left_expression_handler( Token::Minus, BindingPower::Additive, - |parser, cursor, lhs, binding| { + |parser, cursor, lhs, _binding| { let (rhs, cursor) = super::expression::parse(parser, cursor + 1, &BindingPower::Additive)?; Some(( @@ -127,7 +122,7 @@ impl Default for Lookup { lookup.add_left_expression_handler( Token::Star, BindingPower::Multiplicative, - |parser, cursor, lhs, binding| { + |parser, cursor, lhs, _binding| { let (rhs, cursor) = super::expression::parse(parser, cursor + 1, &BindingPower::Multiplicative)?; Some(( @@ -140,7 +135,7 @@ impl Default for Lookup { lookup.add_left_expression_handler( Token::Slash, BindingPower::Multiplicative, - |parser, cursor, lhs, binding| { + |parser, cursor, lhs, _binding| { let (rhs, cursor) = super::expression::parse(parser, cursor + 1, &BindingPower::Multiplicative)?; Some(( @@ -151,61 +146,45 @@ impl Default for Lookup { ); // Literals and symbols - lookup.add_expression_handler( - Token::Decimal(0.0), - BindingPower::Primary, - |parser, cursor| { - let (tokens, cursor) = expect_tokens!(parser, cursor, (Token::Decimal(_)))?; - let integer = tokens.first().unwrap(); - if let Lexeme::Valid(Token::Decimal(value), _) = integer { - Some((Expression::Number(*value), cursor)) - } else { - None - } - }, - ); + lookup.add_expression_handler(Token::Decimal(0.0), |parser, cursor| { + let (tokens, cursor) = expect_tokens!(parser, cursor, (Token::Decimal(_)))?; + let integer = tokens.first().unwrap(); + if let Lexeme::Valid(Token::Decimal(value), _) = integer { + Some((Expression::Number(*value), cursor)) + } else { + None + } + }); - lookup.add_expression_handler( - Token::Integer(0), - BindingPower::Primary, - |parser, cursor| { - let (tokens, cursor) = expect_tokens!(parser, cursor, (Token::Integer(_)))?; - let integer = tokens.first().unwrap(); - if let Lexeme::Valid(Token::Integer(value), _) = integer { - Some((Expression::Number(*value as f64), cursor)) - } else { - None - } - }, - ); + lookup.add_expression_handler(Token::Integer(0), |parser, cursor| { + let (tokens, cursor) = expect_tokens!(parser, cursor, (Token::Integer(_)))?; + let integer = tokens.first().unwrap(); + if let Lexeme::Valid(Token::Integer(value), _) = integer { + Some((Expression::Number(*value as f64), cursor)) + } else { + None + } + }); - lookup.add_expression_handler( - Token::String("".to_string()), - BindingPower::Primary, - |parser, cursor| { - let (tokens, cursor) = expect_tokens!(parser, cursor, (Token::String(_)))?; - let string = tokens.first().unwrap(); - if let Lexeme::Valid(Token::String(value), _) = string { - Some((Expression::String(value.clone()), cursor)) - } else { - None - } - }, - ); + lookup.add_expression_handler(Token::String("".to_string()), |parser, cursor| { + let (tokens, cursor) = expect_tokens!(parser, cursor, (Token::String(_)))?; + let string = tokens.first().unwrap(); + if let Lexeme::Valid(Token::String(value), _) = string { + Some((Expression::String(value.clone()), cursor)) + } else { + None + } + }); - lookup.add_expression_handler( - Token::Identifier("".to_string()), - BindingPower::Primary, - |parser, cursor| { - let (tokens, cursor) = expect_tokens!(parser, cursor, (Token::Identifier(_)))?; - let identifier = tokens.first().unwrap(); - if let Lexeme::Valid(Token::Identifier(value), _) = identifier { - Some((Expression::Symbol(value.clone()), cursor)) - } else { - None - } - }, - ); + lookup.add_expression_handler(Token::Identifier("".to_string()), |parser, cursor| { + let (tokens, cursor) = expect_tokens!(parser, cursor, (Token::Identifier(_)))?; + let identifier = tokens.first().unwrap(); + if let Lexeme::Valid(Token::Identifier(value), _) = identifier { + Some((Expression::Symbol(value.clone()), cursor)) + } else { + None + } + }); lookup.add_statement_handler(Token::Semicolon, |parser, cursor| { let (expression, cursor) = expression::parse(parser, cursor, &BindingPower::Primary)?; diff --git a/src/parser/statement.rs b/src/parser/statement.rs index 34a63ef..31d7483 100644 --- a/src/parser/statement.rs +++ b/src/parser/statement.rs @@ -4,10 +4,9 @@ use super::{expression, lookup::BindingPower, Parser, Statement}; pub fn parse(parser: &Parser, cursor: usize) -> Option<(Statement, usize)> { let lexeme = parser.lexemes.get(cursor)?; - let token = match lexeme { - Lexeme::Valid(token, _) => token, - Lexeme::Invalid(_) => return None, - }; + if let Lexeme::Invalid(_) = lexeme { + return None; + } let (expression, cursor) = expression::parse(parser, cursor, &BindingPower::None)?;