From 9b099bb408e355f5042f12c8e0b411519858d3a3 Mon Sep 17 00:00:00 2001 From: Mark Date: Fri, 7 Apr 2023 09:33:55 -0700 Subject: [PATCH] Fixed decimal parsing --- src/parser/mod.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/parser/mod.rs b/src/parser/mod.rs index eb8b404..f4adfda 100644 --- a/src/parser/mod.rs +++ b/src/parser/mod.rs @@ -72,7 +72,14 @@ impl PreToken { #[inline(always)] pub fn to_token(self) -> Result{ match self { - PreToken::PreNumber(l, s) => { + PreToken::PreNumber(l, mut s) => { + + // The length check here ensures that + // `.` is not parsed as `0.` + // That should be a syntax error. + if s.len() != 1 && &s[0..1] == "." { + s.insert(0, '0'); + } let r = Quantity::new_rational_from_float_string(&s); if r.is_none() {