1use std::fmt;
2
3#[derive(Debug, Clone, PartialEq, Eq)]
5pub enum ParserError {
6 UnexpectedToken {
8 line: u64,
9 column: u64,
10 expected: String,
11 found: String,
12 },
13
14 ExpectedToken {
16 line: u64,
17 column: u64,
18 expected: String,
19 found: String,
20 },
21
22 UnterminatedString { line: u64, column: u64 },
24
25 InvalidNumber {
27 line: u64,
28 column: u64,
29 value: String,
30 },
31
32 InvalidVector { line: u64, column: u64 },
34
35 RecursionLimitExceeded { depth: usize },
37}
38
39impl fmt::Display for ParserError {
40 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
41 match self {
42 Self::UnexpectedToken {
43 line,
44 column,
45 expected,
46 found,
47 } => write!(
48 f,
49 "error[ALOPEX-P001]: unexpected token at line {line}, column {column}: expected {expected}, found {found}"
50 ),
51 Self::ExpectedToken {
52 line,
53 column,
54 expected,
55 found,
56 } => write!(
57 f,
58 "error[ALOPEX-P002]: expected {expected} but found {found} at line {line}, column {column}"
59 ),
60 Self::UnterminatedString { line, column } => write!(
61 f,
62 "error[ALOPEX-P003]: unterminated string literal starting at line {line}, column {column}"
63 ),
64 Self::InvalidNumber {
65 line,
66 column,
67 value,
68 } => write!(
69 f,
70 "error[ALOPEX-P004]: invalid number literal '{value}' at line {line}, column {column}"
71 ),
72 Self::InvalidVector { line, column } => write!(
73 f,
74 "error[ALOPEX-P005]: invalid vector literal at line {line}, column {column}"
75 ),
76 Self::RecursionLimitExceeded { depth } => write!(
77 f,
78 "error[ALOPEX-P006]: recursion limit exceeded (depth: {depth})"
79 ),
80 }
81 }
82}
83
84impl std::error::Error for ParserError {}
85
86pub type Result<T> = std::result::Result<T, ParserError>;