use std::{error, fmt, num::ParseIntError, rc::Rc}; #[derive(Clone, Debug, PartialEq, Eq)] pub enum Error { // Number InvalidIntegerLiteral(Rc, ParseIntError), // String UnclosedString(Rc), UnexpectedEscapeChar(char), // Par UnexpectedClosePar, UnclosedPar, UnexpectedToken, UnexpectedEof, RecursionLimit, } impl fmt::Display for Error { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match self { Error::InvalidIntegerLiteral(number, err) => { write!(f, "invalid integer literal {number}: {err}") } Error::UnclosedString(string) => write!(f, "unclosed string {string:?}"), Error::UnexpectedEscapeChar(ch) => write!(f, "unexpected escape char {ch:?}"), Error::UnexpectedClosePar => write!(f, "unexpected `)`"), Error::UnclosedPar => write!(f, "unclosed `(`"), Error::UnexpectedToken => write!(f, "unexpected token"), Error::UnexpectedEof => write!(f, "unexpected eof"), Error::RecursionLimit => write!(f, "recursion limit"), } } } impl error::Error for Error {}