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
30
31
32
33
34
35
36
use std::fmt;
use source_span::Loc;
use super::lexer;
#[derive(Debug)]
pub enum Error {
Lexer(lexer::Error),
UnexpectedEos,
UnexpectedToken(lexer::Token)
}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
use self::Error::*;
match self {
Lexer(e) => write!(f, "{}", e),
UnexpectedEos => write!(f, "unexpected end of stream"),
UnexpectedToken(_) => write!(f, "unexpected token")
}
}
}
pub type Result<T> = std::result::Result<T, Loc<Error>>;
impl From<lexer::Error> for Error {
fn from(e: lexer::Error) -> Error {
Error::Lexer(e)
}
}