I think I finally got with_additional_fail_matcher building.

This commit is contained in:
Tom Alexander 2022-07-17 18:17:41 -04:00
parent 8321c071e4
commit 1506a86d97
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE

View File

@ -1,9 +1,12 @@
use nom::branch::alt;
use nom::combinator::recognize;
use nom::error::VerboseError;
use nom::IResult;
use std::cell::RefCell;
use std::rc::Rc;
use super::text::bold_end;
#[derive(Clone)]
pub struct NomContext<F>
where
@ -38,17 +41,27 @@ where
}
}
// 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,
// }
// }
pub fn with_additional_fail_matcher<G>(
self,
additional_fail_matcher: G,
) -> NomContext<
impl Clone + for<'o> FnMut(&'o str) -> IResult<&'o str, &'o str, VerboseError<&'o str>>,
>
where
G: for<'g> FnMut(&'g str) -> IResult<&'g str, &'g str, VerboseError<&'g str>>,
G: Clone,
{
let mut old_fail_matcher_clone = self.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 = self.can_match_bold;
new_context.can_match_link = self.can_match_link;
// NomContext {
// fail_matcher: move |i| alt((additional_fail_matcher, &mut old_fail_matcher_clone))(i),
// can_match_bold: self.can_match_bold,
// can_match_link: self.can_match_link,
// }
new_context
}
}