diff options
Diffstat (limited to 'src/error.rs')
| -rw-r--r-- | src/error.rs | 59 |
1 files changed, 0 insertions, 59 deletions
diff --git a/src/error.rs b/src/error.rs deleted file mode 100644 index bbb5d6f..0000000 --- a/src/error.rs +++ /dev/null | |||
| @@ -1,59 +0,0 @@ | |||
| 1 | |||
| 2 | use core::error::Error; | ||
| 3 | use std::fmt; | ||
| 4 | |||
| 5 | use crate::position::*; | ||
| 6 | |||
| 7 | #[derive(Debug)] | ||
| 8 | pub struct CrimError { | ||
| 9 | position: Position, | ||
| 10 | what: String, | ||
| 11 | } | ||
| 12 | |||
| 13 | impl CrimError { | ||
| 14 | pub fn parse( position: Position, what: String ) -> Self { | ||
| 15 | Self { | ||
| 16 | position, | ||
| 17 | what, | ||
| 18 | } | ||
| 19 | } | ||
| 20 | |||
| 21 | pub fn other(what: String) -> Self { | ||
| 22 | Self { | ||
| 23 | position: Position::none(), | ||
| 24 | what, | ||
| 25 | } | ||
| 26 | } | ||
| 27 | |||
| 28 | pub fn broken( position: Position, what: &str ) -> Self { | ||
| 29 | Self { | ||
| 30 | position, | ||
| 31 | what: format!("Broken parser? {}", what), | ||
| 32 | } | ||
| 33 | } | ||
| 34 | |||
| 35 | pub fn eos( context: &str ) -> Self { | ||
| 36 | Self { | ||
| 37 | position: Position::none(), | ||
| 38 | what: format!("Premature end of stream while looking for {}", context), | ||
| 39 | } | ||
| 40 | } | ||
| 41 | |||
| 42 | pub fn what(&self) -> &str { | ||
| 43 | &self.what | ||
| 44 | } | ||
| 45 | |||
| 46 | pub fn start(&self) -> &Position { | ||
| 47 | &self.position | ||
| 48 | } | ||
| 49 | } | ||
| 50 | |||
| 51 | impl fmt::Display for CrimError { | ||
| 52 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
| 53 | write!(f, "Error parsing input: {}", "yeah") | ||
| 54 | } | ||
| 55 | } | ||
| 56 | |||
| 57 | impl Error for CrimError { } | ||
| 58 | |||
| 59 | pub type CrimResult<T> = Result<T, CrimError>; | ||
