diff options
| author | Tolmachev Igor <me@igorek.dev> | 2026-05-09 19:04:27 +0300 |
|---|---|---|
| committer | Tolmachev Igor <me@igorek.dev> | 2026-05-09 19:04:46 +0300 |
| commit | 6be28381d6081dfb3a1dc9d1ec15062b67ba1ef9 (patch) | |
| tree | 1bf89581879ce76f27d69881a6afa4e72e30bf61 /compiler/src/ast/parser.rs | |
| parent | 6c5c627dd441b0e7ac52cfd05e1923584dd213ae (diff) | |
| download | crisp-6be28381d6081dfb3a1dc9d1ec15062b67ba1ef9.tar.gz crisp-6be28381d6081dfb3a1dc9d1ec15062b67ba1ef9.zip | |
Implement fmt::Display for Error
Replaces the todo!() stub. InvalidFloatLiteral and InvalidIntegerLiteral now also take the original
string.
Diffstat (limited to 'compiler/src/ast/parser.rs')
| -rw-r--r-- | compiler/src/ast/parser.rs | 16 |
1 files changed, 10 insertions, 6 deletions
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<Atom, Error> { | |||
| 12 | let is_float = number.bytes().any(|b| matches!(b, b'.' | b'e' | b'E')) | 12 | let is_float = number.bytes().any(|b| matches!(b, b'.' | b'e' | b'E')) |
| 13 | || matches!(number, "inf" | "+inf" | "-inf" | "nan"); | 13 | || matches!(number, "inf" | "+inf" | "-inf" | "nan"); |
| 14 | 14 | ||
| 15 | let atom = if is_float { | 15 | if is_float { |
| 16 | Atom::Float(number.parse()?) | 16 | match number.parse() { |
| 17 | Ok(ok) => Ok(Atom::Float(ok)), | ||
| 18 | Err(err) => Err(Error::InvalidFloatLiteral(number.into(), err)), | ||
| 19 | } | ||
| 17 | } else { | 20 | } else { |
| 18 | Atom::Integer(number.parse()?) | 21 | match number.parse() { |
| 19 | }; | 22 | Ok(ok) => Ok(Atom::Integer(ok)), |
| 20 | 23 | Err(err) => Err(Error::InvalidIntegerLiteral(number.into(), err)), | |
| 21 | Ok(atom) | 24 | } |
| 25 | } | ||
| 22 | } | 26 | } |
| 23 | 27 | ||
| 24 | fn parse_string(string: &str) -> Result<Atom, Error> { | 28 | fn parse_string(string: &str) -> Result<Atom, Error> { |
