fix: implicit operator for adjacent parenthesis

This commit is contained in:
electria 2026-07-20 20:25:10 -07:00
commit 48a1da47fb
Signed by: electria
SSH key fingerprint: SHA256:8LlB3ucPbBHqozqkhsNbaV5oG3SlzzqUj8FZDL6IPQs
2 changed files with 8 additions and 4 deletions

View file

@ -111,10 +111,6 @@ impl FromStr for Nodes {
} }
ParsingState::ReadingNumber(start_index) => { ParsingState::ReadingNumber(start_index) => {
if !is_number_char(c) { if !is_number_char(c) {
if matches!(nodes.last(), Some(Node::ParenthesisEnd)) {
nodes.push(Node::Operator(Default::default()));
}
nodes.push(Node::Number( nodes.push(Node::Number(
Float::parse(&filtered_string[start_index..i]) Float::parse(&filtered_string[start_index..i])
.map_err(|e| { .map_err(|e| {
@ -138,6 +134,9 @@ impl FromStr for Nodes {
} else if c.is_alphabetic() { } else if c.is_alphabetic() {
state = ParsingState::ReadingFunctionName(i); state = ParsingState::ReadingFunctionName(i);
} else if c == '(' { } else if c == '(' {
if matches!(nodes.last(), Some(Node::Number(_) | Node::ParenthesisEnd)) {
nodes.push(Node::Operator(Default::default()));
}
nodes.push(Node::ParenthesisStart); nodes.push(Node::ParenthesisStart);
} else if c == ')' { } else if c == ')' {
nodes.push(Node::ParenthesisEnd); nodes.push(Node::ParenthesisEnd);

View file

@ -11,6 +11,11 @@ fn implicit_mult() {
Nodes::from_str("10 sin(10)").unwrap().evaluate().to_f64(), Nodes::from_str("10 sin(10)").unwrap().evaluate().to_f64(),
-5.440211108893698 -5.440211108893698
); );
assert_eq!(
Nodes::from_str("(10)(10)").unwrap().evaluate().to_f64(),
100.,
)
} }
#[test] #[test]