From 6be28381d6081dfb3a1dc9d1ec15062b67ba1ef9 Mon Sep 17 00:00:00 2001 From: Tolmachev Igor Date: Sat, 9 May 2026 19:04:27 +0300 Subject: Implement fmt::Display for Error Replaces the todo!() stub. InvalidFloatLiteral and InvalidIntegerLiteral now also take the original string. --- compiler/src/ast/parser.rs | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'compiler/src/ast/parser.rs') diff --git a/compiler/src/ast/parser.rs b/compiler/src/ast/parser.rs index 83e48b8..263e5b7 100644 --- a/compiler/src/ast/parser.rs +++ b/compiler/src/ast/parser.rs @@ -12,13 +12,17 @@ fn parse_number(number: &str) -> Result { let is_float = number.bytes().any(|b| matches!(b, b'.' | b'e' | b'E')) || matches!(number, "inf" | "+inf" | "-inf" | "nan"); - let atom = if is_float { - Atom::Float(number.parse()?) + if is_float { + match number.parse() { + Ok(ok) => Ok(Atom::Float(ok)), + Err(err) => Err(Error::InvalidFloatLiteral(number.into(), err)), + } } else { - Atom::Integer(number.parse()?) - }; - - Ok(atom) + match number.parse() { + Ok(ok) => Ok(Atom::Integer(ok)), + Err(err) => Err(Error::InvalidIntegerLiteral(number.into(), err)), + } + } } fn parse_string(string: &str) -> Result { -- cgit v1.3