fix: match 'e' and '.' as numeric
This commit is contained in:
parent
ff152cccea
commit
0b0d4a960f
1 changed files with 8 additions and 4 deletions
|
|
@ -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 == ')' {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue