From 2ca3abf42fa2a21916b221bba3030befc49a944e Mon Sep 17 00:00:00 2001 From: electria Date: Thu, 16 Jul 2026 00:13:37 -0700 Subject: [PATCH] feat: implicit mult --- src/nodes/from_str.rs | 14 ++++++++++++++ src/nodes/mod.rs | 3 ++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/nodes/from_str.rs b/src/nodes/from_str.rs index 5d77c7f..ea7b4c3 100644 --- a/src/nodes/from_str.rs +++ b/src/nodes/from_str.rs @@ -94,6 +94,10 @@ impl FromStr for Nodes { ParsingState::Start => {} ParsingState::ReadingFunctionName(start_index) => { if !c.is_alphabetic() { + if matches!(nodes.last(), Some(Node::ParenthesisEnd | Node::Number(_))) { + nodes.push(Node::Operator(Default::default())); + } + nodes.push(Node::from_name(&filtered_string[start_index..i])?); state = ParsingState::Start; @@ -101,6 +105,10 @@ impl FromStr for Nodes { } ParsingState::ReadingNumber(start_index) => { if !is_number_char(c) { + if matches!(nodes.last(), Some(Node::ParenthesisEnd)) { + nodes.push(Node::Operator(Default::default())); + } + nodes.push(Node::Number( Float::parse(&filtered_string[start_index..i]) .map_err(|e| { @@ -144,9 +152,15 @@ impl FromStr for Nodes { match state { ParsingState::Start => {} ParsingState::ReadingFunctionName(start_index) => { + if matches!(nodes.last(), Some(Node::ParenthesisEnd | Node::Number(_))) { + nodes.push(Node::Operator(Default::default())); + } nodes.push(Node::from_name(&filtered_string[start_index..i])?); } ParsingState::ReadingNumber(start_index) => { + if matches!(nodes.last(), Some(Node::ParenthesisEnd)) { + nodes.push(Node::Operator(Default::default())); + } nodes.push(Node::Number( Float::parse(&filtered_string[start_index..i]) .map_err(|e| { diff --git a/src/nodes/mod.rs b/src/nodes/mod.rs index 42f73c8..84c7583 100644 --- a/src/nodes/mod.rs +++ b/src/nodes/mod.rs @@ -28,10 +28,11 @@ enum Node { Operator(Operator), } -#[derive(Clone, Debug, PartialEq)] +#[derive(Default, Clone, Debug, PartialEq)] enum Operator { Plus, Minus, + #[default] Mult, Div, Exp,