1use std::fmt::{ Display, Formatter };
2
3use backyard_lexer::{ error::LexError, token::Token };
4
5#[derive(Debug, Clone, PartialEq)]
6pub enum ParserError {
7 LexError(LexError),
8 Internal,
9 Eof,
10 UnexpectedToken(Token),
11}
12
13impl Display for ParserError {
14 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
15 match self {
16 ParserError::LexError(err) => write!(f, "{}", err),
17 ParserError::Internal => { write!(f, "Internal parser error") }
18 ParserError::Eof => { write!(f, "End of file") }
19 ParserError::UnexpectedToken(token) => {
20 write!(
21 f,
22 "Unexpected character '{}' at line {}, column {}",
23 token.value,
24 token.line,
25 token.column
26 )
27 }
28 }
29 }
30}