use super::Span;
use thiserror::Error;
#[derive(Debug)]
#[cfg_attr(test, derive(PartialEq, Eq))]
pub struct CompileError {
pub pattern: String,
pub kind: ErrorKind,
}
#[derive(Debug)]
#[cfg_attr(test, derive(PartialEq, Eq))]
pub enum ErrorKind {
Syntax(SyntaxError),
}
#[derive(Copy, Clone, Debug)]
#[cfg_attr(test, derive(PartialEq, Eq))]
pub struct SyntaxError {
pub span: Span,
pub msg: SyntaxErrorKind,
pub help: &'static [HelpMsg],
}
#[derive(Copy, Clone, Debug, Error)]
#[cfg_attr(test, derive(PartialEq, Eq))]
pub enum SyntaxErrorKind {
#[error("pattern must be non-empty")]
EmptyPattern,
#[error("open {name} has no matching close {name}")]
UnclosedDelim { name: &'static str }, #[error("unexpected close {name}")]
UnexpectedCloseDelim { name: &'static str }, }
#[derive(Copy, Clone, Debug, Error)]
#[cfg_attr(test, derive(PartialEq, Eq))]
pub enum HelpMsg {
#[error("to match a literal {name}, use '{escaped}'")]
EscapeToMatchLiteral { name: &'static str, escaped: &'static str },
}
impl HelpMsg {
pub fn kind(&self) -> HelpKind {
match self {
HelpMsg::EscapeToMatchLiteral { .. } => HelpKind::RegexWriter,
}
}
}
#[derive(Copy, Clone, Debug)]
#[cfg_attr(test, derive(PartialEq, Eq))]
pub enum HelpKind {
Programmer,
RegexWriter,
}