Working now that we use clone and manually instantiate it.
This commit is contained in:
parent
3519c76c61
commit
8321c071e4
@ -8,6 +8,7 @@ use std::rc::Rc;
|
||||
pub struct NomContext<F>
|
||||
where
|
||||
F: for<'a> FnMut(&'a str) -> IResult<&'a str, &'a str, VerboseError<&'a str>>,
|
||||
F: Clone,
|
||||
{
|
||||
pub fail_matcher: F,
|
||||
|
||||
@ -37,20 +38,17 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
pub fn with_additional_fail_matcher<G>(
|
||||
self,
|
||||
additional_fail_matcher: G,
|
||||
) -> NomContext<impl (for<'b> FnMut(&'b str) -> IResult<&'b str, &'b str, VerboseError<&'b str>>)>
|
||||
where
|
||||
G: for<'b> FnMut(&'b str) -> IResult<&'b str, &'b str, VerboseError<&'b str>>,
|
||||
G: Clone,
|
||||
// O: for<'b> FnMut(&'b str) -> IResult<&'b str, &'b str, VerboseError<&'b str>>,
|
||||
// O: Clone,
|
||||
{
|
||||
NomContext {
|
||||
fail_matcher: alt((additional_fail_matcher, self.fail_matcher)),
|
||||
can_match_bold: self.can_match_bold,
|
||||
can_match_link: self.can_match_link,
|
||||
}
|
||||
}
|
||||
// pub fn with_additional_fail_matcher<G, O>(self, additional_fail_matcher: G) -> NomContext<O>
|
||||
// where
|
||||
// G: for<'g> FnMut(&'g str) -> IResult<&'g str, &'g str, VerboseError<&'g str>>,
|
||||
// G: Clone,
|
||||
// O: for<'o> FnMut(&'o str) -> IResult<&'o str, &'o str, VerboseError<&'o str>>,
|
||||
// O: Clone,
|
||||
// {
|
||||
// NomContext {
|
||||
// fail_matcher: move |i| alt((additional_fail_matcher, self.fail_matcher))(i),
|
||||
// can_match_bold: self.can_match_bold,
|
||||
// can_match_link: self.can_match_link,
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
@ -26,7 +26,8 @@ pub fn flat_text_element<'a, F>(
|
||||
context: &mut NomContext<F>,
|
||||
) -> Res<&'a str, TextElement<'a>>
|
||||
where
|
||||
F: for<'b> FnMut(&'b str) -> IResult<&'b str, &'b str, VerboseError<&'b str>>,
|
||||
F: for<'b> FnMut(&'b str) -> IResult<&'b str, &'b str, VerboseError<&'b str>>
|
||||
+ std::clone::Clone,
|
||||
{
|
||||
not(&mut context.fail_matcher)(i)?;
|
||||
if context.can_match_bold {
|
||||
@ -59,7 +60,11 @@ where
|
||||
F: Clone,
|
||||
{
|
||||
not(&mut context.fail_matcher)(i)?;
|
||||
let new_context = context.without_bold();
|
||||
let mut old_fail_matcher_clone = context.fail_matcher.clone();
|
||||
let mut new_context =
|
||||
NomContext::new(move |i| alt((recognize(bold_end), &mut old_fail_matcher_clone))(i));
|
||||
new_context.can_match_bold = context.can_match_bold;
|
||||
new_context.can_match_link = context.can_match_link;
|
||||
let text_element_parser = parser_with_context!(flat_text_element)(new_context);
|
||||
map(
|
||||
recognize(tuple((
|
||||
|
Loading…
Reference in New Issue
Block a user