perl_regex/error.rs
1use thiserror::Error;
2
3/// Error type for Perl regex validation failures.
4#[derive(Error, Debug, Clone, PartialEq)]
5pub enum RegexError {
6 /// Syntax error at a specific byte offset in the regex pattern.
7 #[error("{message} at offset {offset}")]
8 Syntax {
9 /// Human-readable description of the syntax issue.
10 message: String,
11 /// Byte offset where the error was detected.
12 offset: usize,
13 },
14}
15
16impl RegexError {
17 /// Create a new syntax error with a message and byte offset.
18 pub fn syntax(message: impl Into<String>, offset: usize) -> Self {
19 Self::Syntax { message: message.into(), offset }
20 }
21}