diff --git a/src/nodes/from_str.rs b/src/nodes/from_str.rs index 95f25a7..f6dfbd6 100644 --- a/src/nodes/from_str.rs +++ b/src/nodes/from_str.rs @@ -29,6 +29,10 @@ impl FromStr for Nodes { let mut state = ParsingState::default(); let is_ignored_char = |c: &char| !matches!(c, ' ' | '&' | '\n'); + let is_numeric_char = |c: char| match c { + '.' | 'e' => true, + c => c.is_numeric(), + }; let filtered_string: String = s.chars().filter(is_ignored_char).collect(); @@ -49,7 +53,7 @@ impl FromStr for Nodes { } } ParsingState::ReadingNumber(start_index) => { - if !c.is_numeric() { + if !is_numeric_char(c) { nodes.push(Node::Number( Float::parse_radix(&filtered_string[start_index..i], 10) .map_err(|e| { @@ -68,10 +72,10 @@ impl FromStr for Nodes { } if start { - if c.is_alphabetic() { - state = ParsingState::ReadingFunctionName(i); - } else if c.is_numeric() { + if is_numeric_char(c) { state = ParsingState::ReadingNumber(i); + } else if c.is_alphabetic() { + state = ParsingState::ReadingFunctionName(i); } else if c == '(' { nodes.push(Node::ParenthesisStart); } else if c == ')' {