Skip to main content

haz_query_lang/
error.rs

1//! Errors produced by the filter-expression parser.
2
3use snafu::Snafu;
4
5/// A parse failure produced by [`crate::parser::parse`].
6///
7/// Variants describe shape-level problems only: the empty input,
8/// unmatched parens, operators in disallowed positions, and
9/// trailing characters after a complete expression. Atom-content
10/// validation (identifier rules, path-pattern grammar, relational
11/// kind) is the consumer crate's responsibility.
12#[derive(Debug, Clone, PartialEq, Eq, Snafu)]
13pub enum ParseError {
14    /// The input contained no atoms after trimming whitespace.
15    #[snafu(display("filter expression is empty"))]
16    EmptyExpression,
17
18    /// An atom was expected at the given byte offset but the
19    /// next character was an operator or end-of-input.
20    #[snafu(display("expected atom at byte {position}"))]
21    ExpectedAtom {
22        /// Byte offset where the atom was expected.
23        position: usize,
24    },
25
26    /// An operator appeared in a position the grammar does not
27    /// permit (for example, as the leading character of an
28    /// expression, or immediately after another binary operator).
29    #[snafu(display("unexpected operator '{op}' at byte {position}"))]
30    UnexpectedOperator {
31        /// The offending operator byte.
32        op: char,
33        /// Byte offset at which it appears.
34        position: usize,
35    },
36
37    /// Unconsumed input remained after a complete expression was
38    /// parsed (typically a missing operator between two atoms).
39    #[snafu(display("unexpected character '{ch}' at byte {position}"))]
40    UnexpectedChar {
41        /// The offending character.
42        ch: char,
43        /// Byte offset at which it appears.
44        position: usize,
45    },
46
47    /// An opening parenthesis was never matched by a closing one.
48    #[snafu(display("unmatched '(' at byte {position}"))]
49    UnmatchedOpenParen {
50        /// Byte offset of the unmatched opener.
51        position: usize,
52    },
53
54    /// A closing parenthesis appeared with no matching opener.
55    #[snafu(display("unmatched ')' at byte {position}"))]
56    UnmatchedCloseParen {
57        /// Byte offset of the unmatched closer.
58        position: usize,
59    },
60}