From 1c4943828f568d173dfcb6c556aa99c588f9688b Mon Sep 17 00:00:00 2001 From: Daniel M Date: Thu, 27 Jan 2022 21:38:58 +0100 Subject: [PATCH] Number separator _ --- src/lexer.rs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/lexer.rs b/src/lexer.rs index 03f918b..ee328fc 100644 --- a/src/lexer.rs +++ b/src/lexer.rs @@ -40,9 +40,19 @@ impl<'a> Lexer<'a> { let mut sval = String::from(ch); // Do as long as a next char exists and it is a numeric char - while let Some('0'..='9') = self.peek() { + while let Some(ch) = self.peek() { // The next char is verified to be Some, so unwrap is safe - sval.push(self.next().unwrap()); + match ch { + // Underscore is a separator, so remove it but don't add to number + '_' => { + self.next().unwrap(); + } + '0'..='9' => { + sval.push(self.next().unwrap()); + } + // Next char is not a number, so stop and finish the number token + _ => break + } } // TODO: We only added numeric chars to the string, but the conversion could still fail