ankql/
error.rs

1use crate::grammar;
2
3/// Custom error type for parsing errors
4#[derive(Debug)]
5pub enum ParseError {
6    SyntaxError(String),
7    EmptyExpression,
8    UnexpectedRule { expected: &'static str, got: grammar::Rule },
9    InvalidPredicate(String),
10    MissingOperand(&'static str),
11}
12
13impl std::fmt::Display for ParseError {
14    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
15        match self {
16            Self::SyntaxError(msg) => write!(f, "Syntax error: {}", msg),
17            Self::EmptyExpression => write!(f, "Empty expression"),
18            Self::UnexpectedRule { expected, got } => {
19                write!(f, "Expected {}, got {:?}", expected, got)
20            }
21            Self::InvalidPredicate(msg) => write!(f, "Invalid predicate: {}", msg),
22            Self::MissingOperand(side) => write!(f, "Missing {} operand", side),
23        }
24    }
25}
26
27impl std::error::Error for ParseError {}