use regex_syntax;
use std::error;
use std::fmt;
#[derive(Debug)]
pub enum Error {
RegexSyntax(regex_syntax::Error),
TooManyStates,
InvalidEngine(&'static str),
}
use error::Error::*;
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self {
RegexSyntax(ref e) => write!(f, "Regex syntax error: {}", e),
TooManyStates => write!(f, "State overflow"),
InvalidEngine(s) => write!(f, "Invalid engine: {}", s),
}
}
}
impl error::Error for Error {
fn description(&self) -> &str {
match *self {
RegexSyntax(ref e) => e.description(),
TooManyStates => "This NFA required too many states to represent as a DFA.",
InvalidEngine(_) => "The regex was not compatible with the requested engine.",
}
}
}
impl From<regex_syntax::Error> for Error {
fn from(e: regex_syntax::Error) -> Error {
RegexSyntax(e)
}
}