feat: implicit mult
This commit is contained in:
parent
b9fc3c1eec
commit
2ca3abf42f
2 changed files with 16 additions and 1 deletions
|
|
@ -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| {
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue