1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
use std::fmt;
pub type Result<T> = std::result::Result<T, Error>;
#[derive(Debug, Clone, PartialEq)]
pub enum Error {
Eof,
Unexpected { pos: usize },
Invalid { reason: &'static str, pos: usize },
TokenLimit { limit: usize },
DepthLimit { limit: usize },
Overflow { pos: usize },
TypeMismatch(&'static str),
Other(&'static str),
}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::Eof => write!(f, "Unexpected End of File"),
Self::Unexpected { pos } => write!(f, "Unexpected character at {}", pos),
Self::Invalid { reason, pos } => write!(f, "Invalid input at {}: {}", pos, reason),
Self::TokenLimit { limit } => write!(f, "Exceeded Token limit of {}", limit),
Self::DepthLimit { limit } => write!(f, "Exceeded Depth limit of {}", limit),
Self::Overflow { pos } => write!(f, "Integer overflow at {}", pos),
Self::TypeMismatch(reason) => write!(f, "Type mismatch: {}", reason),
Self::Other(reason) => f.write_str(reason),
}
}
}
impl std::error::Error for Error {}