mini_builder_rs/parser/
parser_error.rs1use crate::tokenizer::token::TokenType;
2
3#[derive(Debug)]
6pub enum ParserError {
7 ExpectedButFound(String, String),
10 ExpectedButReachedEnd(String),
12 UnexpectedToken(usize, TokenType),
14 UnclosedDirective,
16}
17
18impl std::fmt::Display for ParserError {
19 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
20 match self {
21 Self::ExpectedButFound(s1, s2) => write!(f, "expected: {s1}, but found: {s2}"),
22 Self::ExpectedButReachedEnd(s) => write!(f, "expected: {s}, but reached the end"),
23 Self::UnexpectedToken(token_location, token_type) => write!(
24 f,
25 "unexpected token at character {token_location}, got: {:?}",
26 token_type
27 ),
28 Self::UnclosedDirective => write!(f, "directive was not closed"),
29 }
30 }
31}
32
33impl std::error::Error for ParserError {}