Fix panic when input contains only whitespace and/or commas
This commit is contained in:
parent
d9a08b0b85
commit
6585366b0d
10
src/lexer.rs
10
src/lexer.rs
@ -21,10 +21,6 @@ pub const fn is_alphabetic_extended(input: &char) -> bool {
|
|||||||
/// Lex an input string and return a [`TokenVector`]
|
/// Lex an input string and return a [`TokenVector`]
|
||||||
pub fn lex(input: &str, allow_trailing_operators: bool, default_degree: Unit) -> Result<TokenVector, String> {
|
pub fn lex(input: &str, allow_trailing_operators: bool, default_degree: Unit) -> Result<TokenVector, String> {
|
||||||
|
|
||||||
if input == "" {
|
|
||||||
return Err(format!("Input was empty"))
|
|
||||||
}
|
|
||||||
|
|
||||||
let mut input = input.replace(",", ""); // ignore commas
|
let mut input = input.replace(",", ""); // ignore commas
|
||||||
input = input.to_lowercase();
|
input = input.to_lowercase();
|
||||||
|
|
||||||
@ -399,8 +395,6 @@ pub fn lex(input: &str, allow_trailing_operators: bool, default_degree: Unit) ->
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
},
|
},
|
||||||
'.' | '0'..='9' => {
|
'.' | '0'..='9' => {
|
||||||
let start_index = byte_index;
|
let start_index = byte_index;
|
||||||
@ -455,6 +449,10 @@ pub fn lex(input: &str, allow_trailing_operators: bool, default_degree: Unit) ->
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if tokens.len() == 0 {
|
||||||
|
return Err(format!("Input was empty"))
|
||||||
|
}
|
||||||
|
|
||||||
let mut token_index = 0;
|
let mut token_index = 0;
|
||||||
loop {
|
loop {
|
||||||
match tokens[token_index] {
|
match tokens[token_index] {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user