From d5397d1591ba9e857cf5870d8c40a0c8b1ad3521 Mon Sep 17 00:00:00 2001 From: ozzy <2+ozzy@noreply.localhost> Date: Sun, 27 Sep 2026 13:26:47 -0500 Subject: [PATCH] fix(parser): allow negative numbers made adding a minus sign before a group/primary expression implicitly multiply by -1 --- src/math/parser.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/math/parser.rs b/src/math/parser.rs index 808cf34..e7126d9 100644 --- a/src/math/parser.rs +++ b/src/math/parser.rs @@ -1,3 +1,5 @@ +use rust_decimal::dec; + use crate::math::{ lexer::Token, types::{Expression, Operator}, @@ -126,6 +128,15 @@ impl Parser { self.position += 1; Expression::Number(num) } + Token::Operator(Operator::Subtract) => { + self.position += 1; + let right = self.parse_group(); + Expression::Operation( + Operator::Multiply, + Box::new(Expression::Number(dec!(-1))), + Box::new(right), + ) + } Token::Identifier(identifier) => { let is_function = matches!(self.tokens.get(self.position + 1), Some(Token::OpenParen));