Skip to main content

plexus_parser/
error.rs

1use std::fmt;
2
3#[derive(Debug, Clone, PartialEq)]
4pub struct ParseError {
5    pub message: String,
6    pub line: u32,
7    pub col: u32,
8}
9
10impl ParseError {
11    pub fn new(message: impl Into<String>, line: u32, col: u32) -> Self {
12        Self {
13            message: message.into(),
14            line,
15            col,
16        }
17    }
18}
19
20impl fmt::Display for ParseError {
21    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
22        write!(
23            f,
24            "parse error at {}:{}: {}",
25            self.line, self.col, self.message
26        )
27    }
28}
29
30impl std::error::Error for ParseError {}