fix: match 'e' and '.' as numeric

This commit is contained in:
electria 2026-07-14 17:32:27 -07:00
commit 0b0d4a960f
Signed by: electria
SSH key fingerprint: SHA256:8LlB3ucPbBHqozqkhsNbaV5oG3SlzzqUj8FZDL6IPQs

View file

@ -29,6 +29,10 @@ impl FromStr for Nodes {
let mut state = ParsingState::default(); let mut state = ParsingState::default();
let is_ignored_char = |c: &char| !matches!(c, ' ' | '&' | '\n'); 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(); let filtered_string: String = s.chars().filter(is_ignored_char).collect();
@ -49,7 +53,7 @@ impl FromStr for Nodes {
} }
} }
ParsingState::ReadingNumber(start_index) => { ParsingState::ReadingNumber(start_index) => {
if !c.is_numeric() { if !is_numeric_char(c) {
nodes.push(Node::Number( nodes.push(Node::Number(
Float::parse_radix(&filtered_string[start_index..i], 10) Float::parse_radix(&filtered_string[start_index..i], 10)
.map_err(|e| { .map_err(|e| {
@ -68,10 +72,10 @@ impl FromStr for Nodes {
} }
if start { if start {
if c.is_alphabetic() { if is_numeric_char(c) {
state = ParsingState::ReadingFunctionName(i);
} else if c.is_numeric() {
state = ParsingState::ReadingNumber(i); state = ParsingState::ReadingNumber(i);
} else if c.is_alphabetic() {
state = ParsingState::ReadingFunctionName(i);
} else if c == '(' { } else if c == '(' {
nodes.push(Node::ParenthesisStart); nodes.push(Node::ParenthesisStart);
} else if c == ')' { } else if c == ')' {