From d54c9636ca0ad0f3676a9286143ed5f404124e17 Mon Sep 17 00:00:00 2001 From: electria Date: Wed, 15 Jul 2026 21:26:06 -0700 Subject: [PATCH] refactor: simplify from_str logic slightly --- src/nodes/from_str.rs | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/nodes/from_str.rs b/src/nodes/from_str.rs index f6dfbd6..8b6d819 100644 --- a/src/nodes/from_str.rs +++ b/src/nodes/from_str.rs @@ -14,7 +14,7 @@ pub enum Error { NumberParsing(String, ParseFloatError), } -#[derive(Clone, Debug, Default)] +#[derive(Clone, Debug, Default, PartialEq)] enum ParsingState { #[default] Start, @@ -37,9 +37,8 @@ impl FromStr for Nodes { let filtered_string: String = s.chars().filter(is_ignored_char).collect(); for (i, c) in filtered_string.char_indices() { - let mut start = false; match state { - ParsingState::Start => start = true, + ParsingState::Start => {} ParsingState::ReadingFunctionName(start_index) => { if !c.is_alphabetic() { nodes.push(Node::Function( @@ -49,13 +48,12 @@ impl FromStr for Nodes { )); state = ParsingState::Start; - start = true; } } ParsingState::ReadingNumber(start_index) => { if !is_numeric_char(c) { nodes.push(Node::Number( - Float::parse_radix(&filtered_string[start_index..i], 10) + Float::parse(&filtered_string[start_index..i]) .map_err(|e| { Error::NumberParsing( filtered_string[start_index..i].to_owned(), @@ -66,12 +64,11 @@ impl FromStr for Nodes { )); state = ParsingState::Start; - start = true; } } } - if start { + if state == ParsingState::Start { if is_numeric_char(c) { state = ParsingState::ReadingNumber(i); } else if c.is_alphabetic() {