1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
use std::error;
use std::fmt;
use regex_syntax;
#[derive(Debug)]
pub enum Error {
Syntax(regex_syntax::Error),
CompiledTooBig(usize),
TooManyStates(usize),
NoLazy,
NoWordBoundary,
NoEmpty,
NoBytes,
}
impl From<regex_syntax::Error> for Error {
fn from(err: regex_syntax::Error) -> Error {
Error::Syntax(err)
}
}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
use self::Error::*;
match *self {
Syntax(ref err) => err.fmt(f),
CompiledTooBig(size_limit) => {
write!(f, "Compiled regex exceeds size limit of {} bytes",
size_limit)
}
TooManyStates(size_limit) => {
write!(f, "Compiled regex exceeds size limit of {} states",
size_limit)
}
NoLazy => write!(f, "Lazy reptition operators such as '+?' are \
not allowed."),
NoWordBoundary => write!(f, "Word boundary operators are not \
allowed."),
NoEmpty => write!(f, "Empty match operators are not allowed \
(hopefully temporary)."),
NoBytes => write!(f, "Byte literals are not allowed."),
}
}
}
impl error::Error for Error {
fn description(&self) -> &str {
use self::Error::*;
match *self {
Syntax(ref err) => err.description(),
CompiledTooBig(_) => "compiled regex is too big",
TooManyStates(_) => "compiled regex has too many states",
NoLazy => "lazy repetition operators are not allowed",
NoWordBoundary => "word boundary operators are not allowed",
NoEmpty => "empty match operators are not allowed",
NoBytes => "byte literals are not allowed",
}
}
fn cause(&self) -> Option<&error::Error> {
use self::Error::*;
match *self {
Syntax(ref err) => Some(err),
_ => None,
}
}
}