diff --git a/src/nodes/from_str.rs b/src/nodes/from_str.rs index a28b15a..94a4af4 100644 --- a/src/nodes/from_str.rs +++ b/src/nodes/from_str.rs @@ -111,10 +111,6 @@ 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| { @@ -138,6 +134,9 @@ impl FromStr for Nodes { } else if c.is_alphabetic() { state = ParsingState::ReadingFunctionName(i); } else if c == '(' { + if matches!(nodes.last(), Some(Node::Number(_) | Node::ParenthesisEnd)) { + nodes.push(Node::Operator(Default::default())); + } nodes.push(Node::ParenthesisStart); } else if c == ')' { nodes.push(Node::ParenthesisEnd); diff --git a/src/nodes/tests.rs b/src/nodes/tests.rs index ae50576..405efe5 100644 --- a/src/nodes/tests.rs +++ b/src/nodes/tests.rs @@ -11,6 +11,11 @@ fn implicit_mult() { Nodes::from_str("10 sin(10)").unwrap().evaluate().to_f64(), -5.440211108893698 ); + + assert_eq!( + Nodes::from_str("(10)(10)").unwrap().evaluate().to_f64(), + 100., + ) } #[test]