diff options
Diffstat (limited to 'chewed/src/error.rs')
-rw-r--r-- | chewed/src/error.rs | 24 |
1 files changed, 15 insertions, 9 deletions
diff --git a/chewed/src/error.rs b/chewed/src/error.rs index 420a376..afe65c0 100644 --- a/chewed/src/error.rs +++ b/chewed/src/error.rs @@ -1,17 +1,19 @@ use std::{error::Error, fmt}; +use super::position::LineCol; + #[derive(Clone, Debug, Eq, Hash, PartialEq)] pub enum TakeError { - BadBranch(char, &'static [char]), - BadString(String, &'static str), - EndOfStream, + BadBranch(LineCol, char, &'static [char]), + BadString(LineCol, String, &'static str), + EndOfStream(LineCol), } impl fmt::Display for TakeError { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { - Self::BadBranch(got, expected) => { - write!(f, "Unexpected character {:?}. ", got)?; + Self::BadBranch(pos, got, expected) => { + write!(f, "{}: Unexpected character {:?}. ", pos, got)?; if expected.is_empty() { write!(f, "Expected end of input.") @@ -28,8 +30,12 @@ impl fmt::Display for TakeError { Ok(()) } } - Self::BadString(got, expected) => write!(f, "Unexpected string {:?}. Expected {:?}", got, expected), - Self::EndOfStream => write!(f, "Unexpected end of input"), + Self::BadString(pos, got, expected) => write!( + f, + "{}: Unexpected string {:?}. Expected {:?}", + pos, got, expected + ), + Self::EndOfStream(pos) => write!(f, "{}: Unexpected end of input", pos), } } } @@ -39,14 +45,14 @@ impl Error for TakeError {} #[derive(Clone, Debug, Eq, Hash, PartialEq)] pub enum ParseError { TakeError(TakeError), - InputContinues, + InputContinues(LineCol), } impl fmt::Display for ParseError { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { Self::TakeError(e) => e.fmt(f), - Self::InputContinues => write!(f, "Expected end of input"), + Self::InputContinues(pos) => write!(f, "{}: Expected end of input", pos), } } } |