config_parser/
error.rs

1use super::lexer::Token;
2use std::result;
3
4pub type Result<T> = result::Result<T, Error>;
5
6#[derive(Debug, PartialEq, Eq)]
7pub enum ErrorType {
8    UnexpectedEOF,
9    Unexpected(Token),
10    MissingParameter(String)
11}
12
13pub trait CodePos {
14    fn location(&self) -> (u32, u16);
15}
16
17#[derive(Debug, PartialEq, Eq)]
18pub struct Error {
19    error_type: ErrorType,
20    line: u32,
21    col: u16,
22    expected: Option<&'static str>
23}
24
25impl Error {
26    pub fn new(line: u32, col: u16, etype: ErrorType, expected: Option<&'static str>) -> Error {
27        Error {
28            error_type: etype,
29            line: line,
30            col: col,
31            expected: expected
32        }
33    }
34
35    pub fn from_state<T> (pos: &T, etype: ErrorType, expected: Option<&'static str>) -> Error where T: CodePos {
36        let p = pos.location();
37        Error::new(p.0, p.1, etype, expected)
38    }
39}