Skip to main content

re_parser/
error.rs

1use thiserror::Error;
2
3#[derive(Debug, Error, PartialEq, Clone)]
4pub enum ParseError {
5    #[error("unexpected end of pattern")]
6    UnexpectedEnd,
7
8    #[error("unexpected character '{0}' at position {1}")]
9    UnexpectedChar(char, usize),
10
11    #[error("unmatched '(' at position {0}")]
12    UnmatchedOpenParen(usize),
13
14    #[error("unmatched ')' at position {0}")]
15    UnmatchedCloseParen(usize),
16
17    #[error("unmatched '[' at position {0}")]
18    UnmatchedOpenBracket(usize),
19
20    #[error("invalid quantifier at position {0}: {1}")]
21    InvalidQuantifier(usize, String),
22
23    #[error("invalid escape sequence '\\{0}' at position {1}")]
24    InvalidEscape(char, usize),
25
26    #[error("invalid range '{0}-{1}' in character class: start must be <= end")]
27    InvalidRange(char, char),
28
29    #[error("invalid group syntax at position {0}: {1}")]
30    InvalidGroup(usize, String),
31
32    #[error("named group '{0}' contains invalid characters")]
33    InvalidGroupName(String),
34}
35
36pub type Result<T> = std::result::Result<T, ParseError>;