aboutsummaryrefslogtreecommitdiff
path: root/compiler/src/ast/error.rs
diff options
context:
space:
mode:
authorTolmachev Igor <me@igorek.dev>2026-05-09 19:04:27 +0300
committerTolmachev Igor <me@igorek.dev>2026-05-09 19:04:46 +0300
commit6be28381d6081dfb3a1dc9d1ec15062b67ba1ef9 (patch)
tree1bf89581879ce76f27d69881a6afa4e72e30bf61 /compiler/src/ast/error.rs
parent6c5c627dd441b0e7ac52cfd05e1923584dd213ae (diff)
downloadcrisp-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/error.rs')
-rw-r--r--compiler/src/ast/error.rs33
1 files changed, 17 insertions, 16 deletions
diff --git a/compiler/src/ast/error.rs b/compiler/src/ast/error.rs
index c3283f4..8117513 100644
--- a/compiler/src/ast/error.rs
+++ b/compiler/src/ast/error.rs
@@ -7,8 +7,8 @@ use std::{
7#[derive(Clone, Debug, PartialEq, Eq)] 7#[derive(Clone, Debug, PartialEq, Eq)]
8pub enum Error { 8pub enum Error {
9 // Number 9 // Number
10 InvalidFloatLiteral(ParseFloatError), 10 InvalidFloatLiteral(Rc<str>, ParseFloatError),
11 InvalidIntegerLiteral(ParseIntError), 11 InvalidIntegerLiteral(Rc<str>, ParseIntError),
12 12
13 // String 13 // String
14 UnclosedString(Rc<str>), 14 UnclosedString(Rc<str>),
@@ -23,21 +23,22 @@ pub enum Error {
23 RecursionLimit, 23 RecursionLimit,
24} 24}
25 25
26impl From<ParseFloatError> for Error {
27 fn from(value: ParseFloatError) -> Self {
28 Self::InvalidFloatLiteral(value)
29 }
30}
31
32impl From<ParseIntError> for Error {
33 fn from(value: ParseIntError) -> Self {
34 Self::InvalidIntegerLiteral(value)
35 }
36}
37
38impl fmt::Display for Error { 26impl fmt::Display for Error {
39 fn fmt(&self, _f: &mut fmt::Formatter) -> fmt::Result { 27 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
40 todo!() 28 match self {
29 Error::InvalidFloatLiteral(number, err) => {
30 write!(f, "invalid float literal {number}: {err}")
31 }
32 Error::InvalidIntegerLiteral(number, err) => {
33 write!(f, "invalid integer literal {number}: {err}")
34 }
35 Error::UnclosedString(string) => write!(f, "unclosed string {string:?}"),
36 Error::UnexpectedEscapeChar(ch) => write!(f, "unexpected escape char {ch:?}"),
37 Error::UnexpectedRightPar => write!(f, "unexpected right par"),
38 Error::UnclosedLeftPar => write!(f, "unclosed left par"),
39 Error::UnexpectedEof => write!(f, "unexpected eof"),
40 Error::RecursionLimit => write!(f, "recursion limit"),
41 }
41 } 42 }
42} 43}
43 44