diff options
Diffstat (limited to 'src/error.rs')
-rw-r--r-- | src/error.rs | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/src/error.rs b/src/error.rs index aa9e9d6..96be297 100644 --- a/src/error.rs +++ b/src/error.rs @@ -1,6 +1,10 @@ +type ParseError<'a> = + lalrpop_util::ParseError<usize, lalrpop_util::lexer::Token<'a>, &'a str>; + #[derive(Debug)] pub enum Error { IO(std::io::Error), + Parse(String), } impl std::error::Error for Error { } @@ -9,6 +13,7 @@ impl std::fmt::Display for Error { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match self { Error::IO(e) => e.fmt(f), + Error::Parse(e) => e.fmt(f), } } } @@ -18,6 +23,9 @@ impl std::cmp::PartialEq for Error { match (self, other) { (Error::IO(_), Error::IO(_)) => false, + (Error::Parse(_), Error::Parse(_)) => + false, + _ => false, } } } @@ -27,3 +35,10 @@ impl From<std::io::Error> for Error { Error::IO(e) } } + +impl From<ParseError<'_>> for Error { + fn from(e: ParseError<'_>) -> Error { + Error::Parse(format!("{}", e)) + } +} + |