fix: implicit operator for adjacent parenthesis
This commit is contained in:
parent
016e21ac5a
commit
48a1da47fb
2 changed files with 8 additions and 4 deletions
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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]
|
||||
|
|
|
|||
Loading…
Reference in a new issue