Skip to main content

xgrammar/functor/
error.rs

1//! Errors raised by grammar passes that reject their input.
2
3/// A grammar pass rejected its input grammar.
4#[derive(Debug, Clone, PartialEq, Eq, thiserror::Error)]
5pub enum FunctorError {
6    /// A repetition range with a negative lower bound, or an upper bound below the lower one.
7    #[error("Invalid repetition range {{{lower}, {upper}}}")]
8    InvalidRepetitionRange {
9        /// The minimum repetition count.
10        lower: i64,
11        /// The maximum repetition count, or `-1` for unbounded.
12        upper: i64,
13    },
14    /// A rule body could not be compiled into an automaton (e.g. an invalid regex).
15    #[error("{0}")]
16    FsmBuild(String),
17    /// A lazy rule whose body is not a choices of terminal-like sequences.
18    #[error("lazy rule '{rule_name}' must have a terminal-like body")]
19    LazyRuleBodyNotChoices {
20        /// The name of the lazy rule.
21        rule_name: String,
22    },
23    /// A lazy rule whose body contains an element that does not compile into the rule's own FSM.
24    #[error(
25        "lazy rule '{rule_name}' must have a terminal-like body (strings, character classes, and regexes that \
26         compile to a single FSM); rule references and repetition ranges are not supported"
27    )]
28    LazyRuleElementNotTerminal {
29        /// The name of the lazy rule.
30        rule_name: String,
31    },
32}