.cargo/
crates/
brain/
diff/
files/
highlight/
benches/
src/
grammar/
blob.rs
14.3 KiB
error.rs
1.3 KiB
grammar.rs
10.3 KiB
json.rs
5.4 KiB
lib.rs
1.4 KiB
raw.rs
7.0 KiB
registry.rs
3.0 KiB
syntaxes.rs
2.2 KiB
tests.rs
34.0 KiB
theme.rs
18.7 KiB
util.rs
1.8 KiB
syntaxes/
tests/
Cargo.toml
492 B
repo/
signals/
tui/
tui-core/
tui-termion/
tui-widgets/
scripts/
src/
.gitignore
30 B
.gitsigners
198 B
AGENTS.md
1.9 KiB
CONTRIBUTING
1.7 KiB
Cargo.lock
5.4 KiB
Cargo.toml
1.9 KiB
LICENSE
1.1 KiB
README.md
245 B
STYLE
3.7 KiB
clippy.toml
213 B
crates/highlight/src/error.rs
raw
| 1 | //! Error types for grammar, theme, and registry operations. |
| 2 | //! |
| 3 | //! The crate intentionally exposes a small error surface: invalid source data, |
| 4 | //! invalid regexes, and failed registry lookups. Lower-level parser details are |
| 5 | //! collapsed here so callers can report actionable load or selection failures |
| 6 | //! without depending on the JSON or regex implementation. |
| 7 | |
| 8 | use std::fmt; |
| 9 | |
| 10 | /// Highlighting error. |
| 11 | #[derive(Clone, Debug, Eq, PartialEq)] |
| 12 | pub enum Error { |
| 13 | /// Input could not be parsed as a valid grammar. |
| 14 | InvalidGrammar, |
| 15 | /// Input could not be parsed as a valid theme. |
| 16 | InvalidTheme, |
| 17 | /// Regex data could not be compiled. |
| 18 | InvalidRegex(String), |
| 19 | /// A named grammar was not found. |
| 20 | UnknownSyntax(String), |
| 21 | /// A named theme was not found. |
| 22 | UnknownTheme(String), |
| 23 | } |
| 24 | |
| 25 | impl fmt::Display for Error { |
| 26 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
| 27 | match self { |
| 28 | Self::InvalidGrammar => f.write_str("invalid grammar"), |
| 29 | Self::InvalidTheme => f.write_str("invalid theme"), |
| 30 | Self::InvalidRegex(pattern) => write!(f, "invalid regex `{pattern}`"), |
| 31 | Self::UnknownSyntax(name) => write!(f, "unknown syntax `{name}`"), |
| 32 | Self::UnknownTheme(name) => write!(f, "unknown theme `{name}`"), |
| 33 | } |
| 34 | } |
| 35 | } |
| 36 | |
| 37 | impl std::error::Error for Error {} |