From 56e71d678270a6c331fb5a0f0c3933ec0ac70de3 Mon Sep 17 00:00:00 2001 From: John Date: Thu, 19 Sep 2024 13:16:27 -0500 Subject: [PATCH] cl-lexer: Add a hacky workaround for float support. It's disgusting, but better than nothing! --- compiler/cl-lexer/src/lib.rs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/compiler/cl-lexer/src/lib.rs b/compiler/cl-lexer/src/lib.rs index e0e1328..2ed2d91 100644 --- a/compiler/cl-lexer/src/lib.rs +++ b/compiler/cl-lexer/src/lib.rs @@ -387,7 +387,19 @@ impl<'t> Lexer<'t> { while let Ok(true) = self.peek().as_ref().map(char::is_ascii_alphanumeric) { value = value * B as u128 + self.digit::()? as u128; } - self.produce(Kind::Literal, value) + // TODO: find a better way to handle floats in the tokenizer + match self.peek() { + Ok('.') => { + let mut float = format!("{value}."); + self.consume()?; + while let Ok(true) = self.peek().as_ref().map(char::is_ascii_digit) { + float.push(self.iter.next().unwrap_or_default()); + } + let float = f64::from_str(&float).expect("must be parsable as float"); + self.produce(Kind::Literal, float) + } + _ => self.produce(Kind::Literal, value), + } } fn digit(&mut self) -> LResult { let digit = self.peek()?;