lua_pattern/error.rs
1use crate::Token;
2
3/// The default result type. The error variant is [`Error`].
4pub type Result<T> = std::result::Result<T, Error>;
5
6/// The crate's main error type.
7#[derive(Debug, thiserror::Error, PartialEq, Eq)]
8pub enum Error {
9 /// The input ended with a single `%` character.
10 #[error("unfinished escape: finish `%` with a class or escape character or use `%%` to match `%` literally")]
11 UnfinishedEscape,
12
13 /// The closing bracket `]` for a [character set](crate::PatternObject::Set) is missing.
14 #[error("missing `]` to close set")]
15 UnclosedSet,
16
17 /// A [balanced pattern `%b`](crate::PatternObject::Balanced) was present without two
18 /// characters following it.
19 #[error("missing characters for `%b` pattern. Example: `%b()`")]
20 MissingCharsForBalanced,
21
22 /// A [frontier pattern `%f`](crate::PatternObject::Frontier) was present without a
23 /// [character set](crate::PatternObject::Set) following it.
24 #[error("missing `[` after `%f` in pattern. Example: `%f[%w]`")]
25 MissingSetForFrontier,
26
27 /// The input contained an unexpected token, such as an extra closing bracket or a
28 /// [quantifier](crate::PatternObject::Quantifier) without a leading
29 /// [pattern](crate::PatternObject).
30 #[error("unexpected token in input: `{0}`")]
31 UnexpectedToken(Token),
32
33 /// A [capture group backreference](crate::PatternObject::CaptureRef) referenced a group that
34 /// does not exist.
35 #[error("reference to unknown capture with id `{0}`")]
36 InvalidCaptureRef(u8),
37
38 /// A [character range](crate::SetPatternObject::Range) in a
39 /// [character set](crate::PatternObject::Set) is missing its upper bound. The given token was
40 /// found instead.
41 #[error("range is open ended: token after `-` was `{0}`")]
42 OpenEndedRange(Token),
43}