|
| 1 | +#[doc(hidden)] |
| 2 | +#[macro_export] |
| 3 | +macro_rules! regex ( |
| 4 | + ($re: ident, $s:expr) => ( |
| 5 | + lazy_static! { |
| 6 | + static ref $re: ::regex::Regex = ::regex::Regex::new($s).unwrap(); |
| 7 | + } |
| 8 | + ); |
| 9 | +); |
| 10 | + |
| 11 | + |
1 | 12 | /// `re_match!(regexp) => &[T] -> IResult<&[T], &[T]>`
|
2 | 13 | /// Returns the whole input if a match is found
|
3 | 14 | ///
|
@@ -27,8 +38,8 @@ macro_rules! re_match_static (
|
27 | 38 | ($i:expr, $re:expr) => (
|
28 | 39 | {
|
29 | 40 | use $crate::InputLength;
|
30 |
| - let re = regex!($re); |
31 |
| - if re.is_match($i) { |
| 41 | + regex!(RE, $re); |
| 42 | + if RE.is_match($i) { |
32 | 43 | $crate::IResult::Done(&$i[$i.input_len()..], $i)
|
33 | 44 | } else {
|
34 | 45 | $crate::IResult::Error($crate::Err::Code($crate::ErrorKind::RegexpMatch))
|
@@ -65,8 +76,8 @@ macro_rules! re_find (
|
65 | 76 | macro_rules! re_find_static (
|
66 | 77 | ($i:expr, $re:expr) => (
|
67 | 78 | {
|
68 |
| - let re = regex!($re); |
69 |
| - if let Some((begin, end)) = re.find($i) { |
| 79 | + regex!(RE, $re); |
| 80 | + if let Some((begin, end)) = RE.find($i) { |
70 | 81 | $crate::IResult::Done(&$i[end..], &$i[begin..end])
|
71 | 82 | } else {
|
72 | 83 | $crate::IResult::Error($crate::Err::Code($crate::ErrorKind::RegexpFind))
|
@@ -108,8 +119,8 @@ macro_rules! re_matches (
|
108 | 119 | macro_rules! re_matches_static (
|
109 | 120 | ($i:expr, $re:expr) => (
|
110 | 121 | {
|
111 |
| - let re = regex!($re); |
112 |
| - let v: Vec<&str> = re.find_iter($i).map(|(begin,end)| &$i[begin..end]).collect(); |
| 122 | + regex!(RE, $re); |
| 123 | + let v: Vec<&str> = RE.find_iter($i).map(|(begin,end)| &$i[begin..end]).collect(); |
113 | 124 | if v.len() != 0 {
|
114 | 125 | let offset = {
|
115 | 126 | let end = v.last().unwrap();
|
@@ -155,8 +166,8 @@ macro_rules! re_capture (
|
155 | 166 | macro_rules! re_capture_static (
|
156 | 167 | ($i:expr, $re:expr) => (
|
157 | 168 | {
|
158 |
| - let re = regex!($re); |
159 |
| - if let Some(c) = re.captures($i) { |
| 169 | + regex!(RE, $re); |
| 170 | + if let Some(c) = RE.captures($i) { |
160 | 171 | let v:Vec<&str> = c.iter_pos().filter(|el| el.is_some()).map(|el| el.unwrap()).map(|(begin,end)| &$i[begin..end]).collect();
|
161 | 172 | let offset = {
|
162 | 173 | let end = v.last().unwrap();
|
@@ -202,8 +213,8 @@ macro_rules! re_captures (
|
202 | 213 | macro_rules! re_captures_static (
|
203 | 214 | ($i:expr, $re:expr) => (
|
204 | 215 | {
|
205 |
| - let re = regex!($re); |
206 |
| - let v:Vec<Vec<&str>> = re.captures_iter($i).map(|c| c.iter_pos().filter(|el| el.is_some()).map(|el| el.unwrap()).map(|(begin,end)| &$i[begin..end]).collect()).collect(); |
| 216 | + regex!(RE, $re); |
| 217 | + let v:Vec<Vec<&str>> = RE.captures_iter($i).map(|c| c.iter_pos().filter(|el| el.is_some()).map(|el| el.unwrap()).map(|(begin,end)| &$i[begin..end]).collect()).collect(); |
207 | 218 | if v.len() != 0 {
|
208 | 219 | let offset = {
|
209 | 220 | let end = v.last().unwrap().last().unwrap();
|
|
0 commit comments