From 6585366b0d832de170ca831b3693d5dab9f962e9 Mon Sep 17 00:00:00 2001 From: Kasper Date: Wed, 21 Apr 2021 21:06:02 +0200 Subject: [PATCH] Fix panic when input contains only whitespace and/or commas --- src/lexer.rs | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/lexer.rs b/src/lexer.rs index 142bc89..8d25895 100644 --- a/src/lexer.rs +++ b/src/lexer.rs @@ -21,10 +21,6 @@ pub const fn is_alphabetic_extended(input: &char) -> bool { /// Lex an input string and return a [`TokenVector`] pub fn lex(input: &str, allow_trailing_operators: bool, default_degree: Unit) -> Result { - if input == "" { - return Err(format!("Input was empty")) - } - let mut input = input.replace(",", ""); // ignore commas input = input.to_lowercase(); @@ -399,8 +395,6 @@ pub fn lex(input: &str, allow_trailing_operators: bool, default_degree: Unit) -> } } } - - }, '.' | '0'..='9' => { 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; loop { match tokens[token_index] {