diff options
Diffstat (limited to 'compiler/src/ast/error.rs')
| -rw-r--r-- | compiler/src/ast/error.rs | 33 |
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)] |
| 8 | pub enum Error { | 8 | pub 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 | ||
| 26 | impl From<ParseFloatError> for Error { | ||
| 27 | fn from(value: ParseFloatError) -> Self { | ||
| 28 | Self::InvalidFloatLiteral(value) | ||
| 29 | } | ||
| 30 | } | ||
| 31 | |||
| 32 | impl From<ParseIntError> for Error { | ||
| 33 | fn from(value: ParseIntError) -> Self { | ||
| 34 | Self::InvalidIntegerLiteral(value) | ||
| 35 | } | ||
| 36 | } | ||
| 37 | |||
| 38 | impl fmt::Display for Error { | 26 | impl 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 | ||
