//! Error types for grammar, theme, and registry operations. //! //! The crate intentionally exposes a small error surface: invalid source data, //! invalid regexes, and failed registry lookups. Lower-level parser details are //! collapsed here so callers can report actionable load or selection failures //! without depending on the JSON or regex implementation. use std::fmt; /// Highlighting error. #[derive(Clone, Debug, Eq, PartialEq)] pub enum Error { /// Input could not be parsed as a valid grammar. InvalidGrammar, /// Input could not be parsed as a valid theme. InvalidTheme, /// Regex data could not be compiled. InvalidRegex(String), /// A named grammar was not found. UnknownSyntax(String), /// A named theme was not found. UnknownTheme(String), } impl fmt::Display for Error { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { Self::InvalidGrammar => f.write_str("invalid grammar"), Self::InvalidTheme => f.write_str("invalid theme"), Self::InvalidRegex(pattern) => write!(f, "invalid regex `{pattern}`"), Self::UnknownSyntax(name) => write!(f, "unknown syntax `{name}`"), Self::UnknownTheme(name) => write!(f, "unknown theme `{name}`"), } } } impl std::error::Error for Error {}