Skip to main content

polyspec_crudui_validator/expr/
error.rs

1//! Parse error for the CRUDUI expression engine.
2//!
3//! Carries a single human-readable message (the 4-language token/AST contract
4//! does not include positions, so neither does this error). Mirrors PHP
5//! `ParseError` — message only.
6
7use std::fmt;
8
9/// An error raised by the lexer or parser.
10#[derive(Debug, Clone, PartialEq, Eq)]
11pub struct ParseError {
12    /// Human-readable failure description.
13    pub message: String,
14}
15
16impl ParseError {
17    /// Build a parse error from a message.
18    pub fn new(message: impl Into<String>) -> Self {
19        ParseError {
20            message: message.into(),
21        }
22    }
23}
24
25impl fmt::Display for ParseError {
26    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
27        write!(f, "{}", self.message)
28    }
29}
30
31impl std::error::Error for ParseError {}