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::Start => {}
|
||||||
ParsingState::ReadingFunctionName(start_index) => {
|
ParsingState::ReadingFunctionName(start_index) => {
|
||||||
if !c.is_alphabetic() {
|
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])?);
|
nodes.push(Node::from_name(&filtered_string[start_index..i])?);
|
||||||
|
|
||||||
state = ParsingState::Start;
|
state = ParsingState::Start;
|
||||||
|
|
@ -101,6 +105,10 @@ 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| {
|
||||||
|
|
@ -144,9 +152,15 @@ impl FromStr for Nodes {
|
||||||
match state {
|
match state {
|
||||||
ParsingState::Start => {}
|
ParsingState::Start => {}
|
||||||
ParsingState::ReadingFunctionName(start_index) => {
|
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])?);
|
nodes.push(Node::from_name(&filtered_string[start_index..i])?);
|
||||||
}
|
}
|
||||||
ParsingState::ReadingNumber(start_index) => {
|
ParsingState::ReadingNumber(start_index) => {
|
||||||
|
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| {
|
||||||
|
|
|
||||||
|
|
@ -28,10 +28,11 @@ enum Node {
|
||||||
Operator(Operator),
|
Operator(Operator),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, PartialEq)]
|
#[derive(Default, Clone, Debug, PartialEq)]
|
||||||
enum Operator {
|
enum Operator {
|
||||||
Plus,
|
Plus,
|
||||||
Minus,
|
Minus,
|
||||||
|
#[default]
|
||||||
Mult,
|
Mult,
|
||||||
Div,
|
Div,
|
||||||
Exp,
|
Exp,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue