diff options
| author | Tolmachev Igor <me@igorek.dev> | 2026-05-10 12:54:41 +0300 |
|---|---|---|
| committer | Tolmachev Igor <me@igorek.dev> | 2026-05-10 12:54:41 +0300 |
| commit | 843242e692280d604b74324ba26ead6158223439 (patch) | |
| tree | e5f2d362b1c728f900d8214bc415752336fa4a94 /compiler/src/ast/parser.rs | |
| parent | 1801afdbd0058cc9cc040b977de0d5652d65aab9 (diff) | |
| download | crisp-843242e692280d604b74324ba26ead6158223439.tar.gz crisp-843242e692280d604b74324ba26ead6158223439.zip | |
Remove Float from parser
Dropped to make the language simpler.
Diffstat (limited to 'compiler/src/ast/parser.rs')
| -rw-r--r-- | compiler/src/ast/parser.rs | 19 |
1 files changed, 3 insertions, 16 deletions
diff --git a/compiler/src/ast/parser.rs b/compiler/src/ast/parser.rs index bb4e0ce..c0ad917 100644 --- a/compiler/src/ast/parser.rs +++ b/compiler/src/ast/parser.rs | |||
| @@ -9,19 +9,9 @@ use crate::{ | |||
| 9 | pub(super) const MAX_DEPTH: usize = 256; // TODO: make it a compile flag | 9 | pub(super) const MAX_DEPTH: usize = 256; // TODO: make it a compile flag |
| 10 | 10 | ||
| 11 | fn parse_number(number: &str) -> Result<Atom, Error> { | 11 | fn parse_number(number: &str) -> Result<Atom, Error> { |
| 12 | let is_float = number.bytes().any(|b| matches!(b, b'.' | b'e' | b'E')) | 12 | match number.parse() { |
| 13 | || matches!(number, "inf" | "+inf" | "-inf" | "nan"); | 13 | Ok(ok) => Ok(Atom::Integer(ok)), |
| 14 | 14 | Err(err) => Err(Error::InvalidIntegerLiteral(number.into(), err)), | |
| 15 | if is_float { | ||
| 16 | match number.parse() { | ||
| 17 | Ok(ok) => Ok(Atom::Float(ok)), | ||
| 18 | Err(err) => Err(Error::InvalidFloatLiteral(number.into(), err)), | ||
| 19 | } | ||
| 20 | } else { | ||
| 21 | match number.parse() { | ||
| 22 | Ok(ok) => Ok(Atom::Integer(ok)), | ||
| 23 | Err(err) => Err(Error::InvalidIntegerLiteral(number.into(), err)), | ||
| 24 | } | ||
| 25 | } | 15 | } |
| 26 | } | 16 | } |
| 27 | 17 | ||
| @@ -59,9 +49,6 @@ fn parse_symbol(symbol: &str) -> Atom { | |||
| 59 | "true" => Atom::Bool(true), | 49 | "true" => Atom::Bool(true), |
| 60 | "false" => Atom::Bool(false), | 50 | "false" => Atom::Bool(false), |
| 61 | "nil" => Atom::Nil, | 51 | "nil" => Atom::Nil, |
| 62 | "inf" | "+inf" => Atom::Float(f64::INFINITY), | ||
| 63 | "-inf" => Atom::Float(f64::NEG_INFINITY), | ||
| 64 | "nan" => Atom::Float(f64::NAN), | ||
| 65 | _ => Atom::Symbol(symbol.into()), | 52 | _ => Atom::Symbol(symbol.into()), |
| 66 | } | 53 | } |
| 67 | } | 54 | } |
