pub struct DynamicBoxedRegex<'a, C, R> { /* private fields */ }Implementations§
Trait Implementations§
Source§impl<'a, C, O, H, A> Ctor<'a, C, O, O, H, A> for DynamicBoxedRegex<'_, C, Span>
impl<'a, C, O, H, A> Ctor<'a, C, O, O, H, A> for DynamicBoxedRegex<'_, C, Span>
Source§impl<C, R> Regex<C> for DynamicBoxedRegex<'_, C, R>
impl<C, R> Regex<C> for DynamicBoxedRegex<'_, C, R>
Auto Trait Implementations§
impl<'a, C, R> Freeze for DynamicBoxedRegex<'a, C, R>
impl<'a, C, R> !RefUnwindSafe for DynamicBoxedRegex<'a, C, R>
impl<'a, C, R> !Send for DynamicBoxedRegex<'a, C, R>
impl<'a, C, R> !Sync for DynamicBoxedRegex<'a, C, R>
impl<'a, C, R> Unpin for DynamicBoxedRegex<'a, C, R>
impl<'a, C, R> !UnwindSafe for DynamicBoxedRegex<'a, C, R>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> ConstructIntoOp for T
impl<T> ConstructIntoOp for T
Source§fn into_box(self) -> WrappedTy<BoxedCtor<T>>
fn into_box(self) -> WrappedTy<BoxedCtor<T>>
Return a type that wraps Ctor with Box.
§Example
let re = b'+'
.or(b'-')
.then(u8::is_ascii_hexdigit)
.then(u8::is_ascii_hexdigit.repeat_times::<3>())
.pat()
.map(|v: &[u8]| String::from_utf8(v.to_vec()).map_err(|_| Error::Uid(0)))
.into_box();
assert_eq!(BytesCtx::new(b"+AE00").ctor(&re)?, "+AE00");
assert!(BytesCtx::new(b"-GH66").ctor(&re).is_err());
assert_eq!(BytesCtx::new(b"-83FD").ctor(&re)?, "-83FD");
Ok(())Source§fn into_rc(self) -> WrappedTy<Rc<T>>
fn into_rc(self) -> WrappedTy<Rc<T>>
Return a type that wrap Ctor with Rc.
§Example
color_eyre::install()?;
let year = char::is_ascii_digit.repeat_times::<4>();
let num = char::is_ascii_digit.repeat_times::<2>();
let date = year.sep_once("-", num.sep_once("-", num)).into_rc();
let time = num.sep_once(":", num.sep_once(":", num));
let datetime = date.clone().sep_once(" ", time);
assert_eq!(
CharsCtx::new("2024-01-08").ctor(&date)?,
("2024", ("01", "08"))
);
assert_eq!(
CharsCtx::new("2024-01-08 10:01:13").ctor(&datetime)?,
(("2024", ("01", "08")), ("10", ("01", "13")))
);
Ok(())Source§fn into_dyn<'a, 'b, C, M, O, H, A>(
self,
) -> WrappedTy<DynamicBoxedCtor<'a, 'b, C, M, O, H, A>>
fn into_dyn<'a, 'b, C, M, O, H, A>( self, ) -> WrappedTy<DynamicBoxedCtor<'a, 'b, C, M, O, H, A>>
§Example 2
color_eyre::install()?;
let num = u8::is_ascii_digit
.repeat_one()
.map(|v: &[u8]| String::from_utf8(v.to_vec()).map_err(|_| Error::Uid(0)))
.map(map::from_str::<usize>());
let num = num.clone().sep_once(b",", num);
let re = num.into_dyn();
assert_eq!(BytesCtx::new(b"3,0").ctor(&re)?, (3, 0));
assert_eq!(BytesCtx::new(b"2,1").ctor(&re)?, (2, 1));
assert_eq!(BytesCtx::new(b"0,3").ctor(&re)?, (0, 3));
Ok(())fn into_arc(self) -> WrappedTy<Arc<T>>
fn into_cell(self) -> WrappedTy<Cell<T>>
fn into_refcell(self) -> WrappedTy<RefCell<T>>
fn into_mutex(self) -> WrappedTy<Mutex<T>>
fn into_dyn_sync<'a, 'b, C, M, O, H, A>( self, ) -> WrappedTy<DynamicBoxedCtorSync<'a, 'b, C, M, O, H, A>>
fn into_dyn_arc<'a, 'b, C, M, O, H, A>( self, ) -> WrappedTy<DynamicArcCtor<'a, 'b, C, M, O, H, A>>
fn into_dyn_rc<'a, 'b, C, M, O, H, A>( self, ) -> WrappedTy<DynamicRcCtor<'a, 'b, C, M, O, H, A>>
Source§impl<'a, C, T> ConstructOp<'a, C> for T
impl<'a, C, T> ConstructOp<'a, C> for T
Source§fn pat(self) -> Pattern<C, T>
fn pat(self) -> Pattern<C, T>
Call .try_mat to match regex P.
§Example
let digit = re!(['0' - '9']+);
let digit = digit.map(|v: &str| Ok(v.parse::<i64>().unwrap()));
let digits = digit.sep(",".ws());
let array = digits.quote("[", "]");
let mut ctx = CharsCtx::new("[2, 4, 8, 16, 42]");
assert_eq!(ctx.ctor(&array)?, vec![2, 4, 8, 16, 42]);
assert_eq!(ctx.reset().ctor(&array.pat())?, "[2, 4, 8, 16, 42]");
Ok(())Source§fn opt(self) -> OptionPat<C, T>
fn opt(self) -> OptionPat<C, T>
Match P and return the result wrapped by Option, ignoring the error.
§Example
let num = neu::digit(10)
.repeat_one_more()
.map(map::from_str::<usize>())
.opt();
assert_eq!(CharsCtx::new("foo").ctor(&num)?, None);
assert_eq!(CharsCtx::new("955").ctor(&num)?, Some(955));
Ok(())Source§fn quote<L, R>(self, left: L, right: R) -> Quote<C, T, L, R>
fn quote<L, R>(self, left: L, right: R) -> Quote<C, T, L, R>
First try to match L. If it is succeeds, then try to match P.
If it is succeeds, then try to match R.
§Example
let ascii = neu::ascii().repeat_one();
let lit = ascii.quote("'", "'");
let ele = lit.sep(",".ws());
let arr = ele.quote("[", "]");
let mut ctx = CharsCtx::new("['a', 'c', 'd', 'f']");
assert_eq!(ctx.ctor(&arr)?, ["a", "c", "d", "f"]);
Ok(())Source§fn sep<S>(self, sep: S) -> Separate<C, T, S>
fn sep<S>(self, sep: S) -> Separate<C, T, S>
Match regex P as many times as possible, with S as the delimiter.
§Example
let name = re!([^ ',' ']' '[']+);
let sep = ','.repeat_one().ws();
let arr = name.sep(sep);
let arr = arr.quote("[", "]");
let mut ctx = CharsCtx::new(r#"[c, rust, java, c++]"#);
assert_eq!(ctx.ctor(&arr)?, vec!["c", "rust", "java", "c++"]);
Ok(())Source§fn sep_once<S, R>(self, sep: S, right: R) -> SepOnce<C, T, S, R>
fn sep_once<S, R>(self, sep: S, right: R) -> SepOnce<C, T, S, R>
Match L and R separated by S.
§Example
let key = neu::alphabetic().repeat_one_more().ws();
let val = neu::whitespace().or(',').not().repeat_one_more().ws();
let sep = "=>".ws();
let ele = key.sep_once(sep, val);
let hash = ele.sep(",".ws()).quote("{".ws(), "}");
let mut ctx = CharsCtx::new(
r#"{
c => c11,
cpp => c++23,
rust => 2021,
}"#,
);
assert_eq!(
ctx.ctor(&hash)?,
[("c", "c11"), ("cpp", "c++23"), ("rust", "2021")]
);
Ok(())Source§fn sep_collect<S, O, V>(self, sep: S) -> SepCollect<C, T, S, O, V>
fn sep_collect<S, O, V>(self, sep: S) -> SepCollect<C, T, S, O, V>
Match regex P as many times as possible, with S as the delimiter.
§Example
let key = neu::alphabetic().repeat_one_more().ws();
let val = neu::whitespace().or(',').not().repeat_one_more().ws();
let sep = "=>".ws();
let ele = key.sep_once(sep, val);
let hash = ele.sep_collect(",".ws()).quote("{".ws(), "}");
let mut ctx = CharsCtx::new(
r#"{
c => c11,
cpp => c++23,
rust => 2021,
}"#,
);
let hash: HashMap<&str, &str> = ctx.ctor(&hash)?;
assert_eq!(hash.get("c"), Some(&"c11"));
assert_eq!(hash.get("cpp"), Some(&"c++23"));
assert_eq!(hash.get("rust"), Some(&"2021"));
Ok(())Source§fn or<P>(self, pat: P) -> Or<C, T, P>
fn or<P>(self, pat: P) -> Or<C, T, P>
First try to match L, if it fails, then try to match R.
§Example
#[derive(Debug, PartialEq, Eq)]
pub enum V<'a> {
S(&'a str),
}
let cond = neu::re_cond(re::not("\\\""));
let str = re!([^ '"' ]+).set_cond(cond).or("\\\"").repeat(1..).pat();
let str = str.quote("\"", "\"");
let str = str.map(|v| Ok(V::S(v)));
let vals = str.sep(",".ws());
let text = r#""lily\"", "lilei", "lucy""#;
let mut ctx = CharsCtx::new(text);
assert_eq!(
ctx.ctor(&vals)?,
[V::S("lily\\\""), V::S("lilei"), V::S("lucy")]
);
Ok(())Source§fn ltm<P>(self, pat: P) -> LongestTokenMatch<C, T, P>
fn ltm<P>(self, pat: P) -> LongestTokenMatch<C, T, P>
Match L and R, return the longest match result.
§Example
#[derive(Debug, PartialEq, Eq)]
pub struct Val<'a>(&'a str);
let val = "v".ltm("val".ltm("value"));
let val = val.map(|v| Ok(Val(v)));
let val = val.sep(",".ws());
let val = val.quote("{", "}");
let mut ctx = CharsCtx::new(r#"{val, v, value}"#);
assert_eq!(ctx.ctor(&val)?, [Val("val"), Val("v"), Val("value")]);
Ok(())Source§fn then<P>(self, then: P) -> Then<C, T, P>
fn then<P>(self, then: P) -> Then<C, T, P>
First try to match P. If it succeeds, then try to match T.
§Example
let ws = neu::whitespace().repeat_full();
let id = neu::ascii_alphabetic().repeat_one_more();
let st = "struct".ws().then(id)._1();
let en = "enum".ws().then(id)._1();
let ty = st.or(en);
let ty = ty.ws().then(ws.quote("{", "}"))._0();
let mut ctx = CharsCtx::new(r#"struct widget { }"#);
assert_eq!(ctx.ctor(&ty)?, "widget");
Ok(())Source§fn if_then<I, P>(self, if: I, then: P) -> IfThen<C, T, I, P>
fn if_then<I, P>(self, if: I, then: P) -> IfThen<C, T, I, P>
First try to match P. If it succeeds, then try to match I.
If it succeeds, then try to match T.
§Example
let sp = neu::whitespace().repeat_full();
let using = "use"
.sep_once(
"",
neu::ascii_alphanumeric()
.or('*')
.or('_')
.repeat_one_more()
.sep("::"),
)
._1()
.if_then("as", neu::ascii_alphanumeric().repeat_one_more());
for (str, res) in [
(
"use neure::prelude::*",
(vec!["neure", "prelude", "*"], None),
),
("use neure as regex", (vec!["neure"], Some("regex"))),
] {
assert_eq!(CharsCtx::new(str).ignore(sp).ctor(&using)?, res);
}
Ok(())Source§fn repeat(self, range: impl Into<CRange<usize>>) -> Repeat<C, T>
fn repeat(self, range: impl Into<CRange<usize>>) -> Repeat<C, T>
Repeatedly match regex P, and the number of matches must meet the given range.
§Example
let int = neu::digit(10).repeat_one_more();
let int = int.map(map::from_str_radix::<i32>(10));
let num = int.ws().repeat(3..5);
let mut ctx = CharsCtx::new(r#"1 2 3 4"#);
assert_eq!(ctx.ctor(&num)?, [1, 2, 3, 4]);
Ok(())Source§fn if<I, E>(self, if: I, else: E) -> IfRegex<C, T, I, E>
fn if<I, E>(self, if: I, else: E) -> IfRegex<C, T, I, E>
Construct a branch struct base on the test I(Fn(&C) -> Result<bool, Error>).
§Example
let val = "file://".r#if(
// test if it is a file url
|ctx: &CharsCtx| Ok(ctx.orig()?.starts_with("file")),
"http://",
);
assert_eq!(CharsCtx::new("file://").ctor(&val)?, "file://");
assert_eq!(CharsCtx::new("http://").ctor(&val)?, "http://");
Ok(())Source§fn pad<P>(self, pat: P) -> Pad<C, T, P>
fn pad<P>(self, pat: P) -> Pad<C, T, P>
First try to match P. If the match succeeds, then try to match T.
§Example
let sep = neu!([',' ';']);
let end = neu!(['。' '?' '!']);
let word = sep.or(end).not().repeat_one_more();
let sent = word.sep(sep.repeat_one().ws()).pad(end.repeat_one());
let sent = sent.repeat(1..);
let mut ctx = CharsCtx::new(
r#"暖日晴风初破冻。柳眼眉腮,已觉春心动。酒意诗情谁与共。泪融残粉花钿重。乍试夹衫金缕缝。山枕斜敧,枕损钗头凤。独抱浓愁无好梦。夜阑犹剪灯花弄。"#,
);
assert_eq!(ctx.ctor(&sent)?.len(), 8);
Ok(())Source§fn padded<P>(self, pat: P) -> Padded<C, T, P>
fn padded<P>(self, pat: P) -> Padded<C, T, P>
First try to match T. If it succeeds, try to match P.
§Example
let num = neu::digit(10).repeat_times::<2>();
let time = num.sep_once(":", num);
let time = time.quote("[", "]").ws();
let star = '*'.repeat_times::<3>().ws();
let name = neu::whitespace().not().repeat_one_more().ws();
let status = "left".or("joined").ws();
let record = name.padded(star).then(status);
let record = time.then(record).repeat(1..);
let mut ctx = CharsCtx::new(
r#"[20:59] *** jpn left
[21:00] *** jpn joined
[21:06] *** guifa left
[21:07] *** guifa joined"#,
);
let records = ctx.ctor(&record)?;
assert_eq!(records[0], (("20", "59"), ("jpn", "left")));
assert_eq!(records[1], (("21", "00"), ("jpn", "joined")));
assert_eq!(records[2], (("21", "06"), ("guifa", "left")));
assert_eq!(records[3], (("21", "07"), ("guifa", "joined")));
Ok(())Source§fn ws(
self,
) -> Pad<C, T, NeureZeroMore<C, AsciiWhiteSpace, <C as Context<'a>>::Item, NullCond>>
fn ws( self, ) -> Pad<C, T, NeureZeroMore<C, AsciiWhiteSpace, <C as Context<'a>>::Item, NullCond>>
A shortcut for matching trailing ascii spaces.
§Example
let str = "file:// ";
let val = "file://".ws();
assert_eq!(CharsCtx::new(str).ctor(&val)?, "file://");
assert_eq!(CharsCtx::new(str).try_mat(&val)?, Span::new(0, 13));
Ok(())fn map<F, O>(self, func: F) -> Map<C, T, F, O>
Source§impl<'a, C, T> DynamicCreateCtorThenHelper<'a, C> for T
impl<'a, C, T> DynamicCreateCtorThenHelper<'a, C> for T
Source§fn dyn_then_ctor<F>(self, func: F) -> DynamicCreateCtorThen<C, T, F>
fn dyn_then_ctor<F>(self, func: F) -> DynamicCreateCtorThen<C, T, F>
Construct a new regex with Ctor implementation based on previous result.
§Example
let num = u8::is_ascii_digit
.repeat_one()
.map(|v: &[u8]| String::from_utf8(v.to_vec()).map_err(|_| Error::Uid(0)))
.map(map::from_str::<usize>());
let num = num.clone().sep_once(b",", num);
let re = num.dyn_then_ctor(|a: &(usize, usize)| {
// leave the a's type empty cause rustc reject compile
Ok(b'+'
.repeat_range(a.0..a.0 + 1)
.then(b'-'.repeat_range(a.1..a.1 + 1)))
});
assert_eq!(
BytesCtx::new(b"3,0+++").ctor(&re)?,
((3, 0), ([43, 43, 43].as_slice(), [].as_slice()))
);
assert_eq!(
BytesCtx::new(b"2,1++-").ctor(&re)?,
((2, 1), ([43, 43].as_slice(), [45].as_slice()))
);
assert_eq!(
BytesCtx::new(b"0,3---").ctor(&re)?,
((0, 3), ([].as_slice(), [45, 45, 45].as_slice()))
);
Ok(())