aboutsummaryrefslogtreecommitdiff
path: root/lib/xixanta/src/errors.rs
blob: 6c99f5789ace39e9a61b6bc95edb4cf2e5812041 (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
27
28
29
use std::fmt;

// TODO: global error
// TODO: more errors, the `parse` thing is a hack!
#[derive(Debug, Clone, PartialEq)]
pub struct ParseError {
    pub line: usize,
    pub message: String,
    pub parse: bool,
}

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(),
            parse: true,
        }
    }
}

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