1use thiserror::Error;
2
3pub type Result<T> = std::result::Result<T, ParseError>;
4
5#[derive(Error, Debug, Clone)]
6pub enum ParseError {
7 #[error("Syntax error at line {line}, column {column}: {message}")]
8 SyntaxError {
9 line: usize,
10 column: usize,
11 message: String,
12 },
13
14 #[error("Invalid model definition: {0}")]
15 InvalidModel(String),
16
17 #[error("Invalid API definition: {0}")]
18 InvalidApi(String),
19
20 #[error("Invalid event definition: {0}")]
21 InvalidEvent(String),
22
23 #[error("Invalid cron definition: {0}")]
24 InvalidCron(String),
25
26 #[error("Invalid type: {0}")]
27 InvalidType(String),
28
29 #[error("Invalid attribute: {0}")]
30 InvalidAttribute(String),
31
32 #[error("Duplicate definition: {0}")]
33 DuplicateDefinition(String),
34
35 #[error("Undefined reference: {0}")]
36 UndefinedReference(String),
37
38 #[error("File not found: {0}")]
39 FileNotFound(String),
40
41 #[error("IO error: {0}")]
42 IoError(String),
43
44 #[error("Parse error: {0}")]
45 ParseError(String),
46}
47
48impl From<std::io::Error> for ParseError {
49 fn from(err: std::io::Error) -> Self {
50 ParseError::IoError(err.to_string())
51 }
52}
53
54impl From<pest::error::Error<crate::grammar::Rule>> for ParseError {
55 fn from(err: pest::error::Error<crate::grammar::Rule>) -> Self {
56 let (line, column) = match err.line_col {
57 pest::error::LineColLocation::Pos((line, col)) => (line, col),
58 pest::error::LineColLocation::Span((line, col), _) => (line, col),
59 };
60 ParseError::SyntaxError {
61 line,
62 column,
63 message: err.variant.to_string(),
64 }
65 }
66}