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>
|
pub struct NomContext<F>
|
||||||
where
|
where
|
||||||
F: for<'a> FnMut(&'a str) -> IResult<&'a str, &'a str, VerboseError<&'a str>>,
|
F: for<'a> FnMut(&'a str) -> IResult<&'a str, &'a str, VerboseError<&'a str>>,
|
||||||
|
F: Clone,
|
||||||
{
|
{
|
||||||
pub fail_matcher: F,
|
pub fail_matcher: F,
|
||||||
|
|
||||||
@ -37,20 +38,17 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn with_additional_fail_matcher<G>(
|
// pub fn with_additional_fail_matcher<G, O>(self, additional_fail_matcher: G) -> NomContext<O>
|
||||||
self,
|
// where
|
||||||
additional_fail_matcher: G,
|
// G: for<'g> FnMut(&'g str) -> IResult<&'g str, &'g str, VerboseError<&'g str>>,
|
||||||
) -> NomContext<impl (for<'b> FnMut(&'b str) -> IResult<&'b str, &'b str, VerboseError<&'b str>>)>
|
// G: Clone,
|
||||||
where
|
// O: for<'o> FnMut(&'o str) -> IResult<&'o str, &'o str, VerboseError<&'o str>>,
|
||||||
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,
|
// O: Clone,
|
||||||
{
|
// {
|
||||||
NomContext {
|
// NomContext {
|
||||||
fail_matcher: alt((additional_fail_matcher, self.fail_matcher)),
|
// fail_matcher: move |i| alt((additional_fail_matcher, self.fail_matcher))(i),
|
||||||
can_match_bold: self.can_match_bold,
|
// can_match_bold: self.can_match_bold,
|
||||||
can_match_link: self.can_match_link,
|
// can_match_link: self.can_match_link,
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
|
@ -26,7 +26,8 @@ pub fn flat_text_element<'a, F>(
|
|||||||
context: &mut NomContext<F>,
|
context: &mut NomContext<F>,
|
||||||
) -> Res<&'a str, TextElement<'a>>
|
) -> Res<&'a str, TextElement<'a>>
|
||||||
where
|
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)?;
|
not(&mut context.fail_matcher)(i)?;
|
||||||
if context.can_match_bold {
|
if context.can_match_bold {
|
||||||
@ -59,7 +60,11 @@ where
|
|||||||
F: Clone,
|
F: Clone,
|
||||||
{
|
{
|
||||||
not(&mut context.fail_matcher)(i)?;
|
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);
|
let text_element_parser = parser_with_context!(flat_text_element)(new_context);
|
||||||
map(
|
map(
|
||||||
recognize(tuple((
|
recognize(tuple((
|
||||||
|
Loading…
x
Reference in New Issue
Block a user