aboutsummaryrefslogtreecommitdiff
path: root/lib/xixanta/src/errors.rs
blob: d9a12cd62c7b2a9c9795a12b462d5742d8cfbc1e (plain)
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
use std::fmt;

// TODO: global error
#[derive(Debug, Clone, PartialEq)]
pub struct ParseError {
    pub line: usize,
    pub message: String,
}

impl std::error::Error for ParseError {}

impl From<std::io::Error> for ParseError {
    fn from(err: std::io::Error) -> Self {
        // TODO
        ParseError {
            line: 0,
            message: err.to_string(),
        }
    }
}

impl fmt::Display for ParseError {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        write!(f, "parser (line {}): {}.", self.line + 1, self.message)
    }
}