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
48
49
50
51
52
53
54
55
|
#[derive(Debug, Clone, Default)]
pub struct ParsingExceptionLoc {
pub first_line: i64,
pub first_column: i64,
pub last_line: i64,
pub last_column: i64,
}
#[derive(Debug, Clone)]
pub enum ParsingExceptionToken {
Name(String),
Symbol(i64),
}
#[derive(Debug, Clone, Default)]
pub struct ParsingExceptionDetails {
pub text: Option<String>,
pub token: Option<ParsingExceptionToken>,
pub line: Option<i64>,
pub loc: Option<ParsingExceptionLoc>,
pub expected: Option<Vec<String>>,
}
#[derive(Debug)]
pub struct ParsingException {
pub message: String,
pub code: i64,
pub(crate) details: ParsingExceptionDetails,
}
impl ParsingException {
pub fn new(message: String, details: ParsingExceptionDetails) -> Self {
Self {
message,
code: 0,
details,
}
}
pub fn get_message(&self) -> &str {
&self.message
}
pub fn get_details(&self) -> &ParsingExceptionDetails {
&self.details
}
}
impl std::fmt::Display for ParsingException {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self.message)
}
}
impl std::error::Error for ParsingException {}
|