Going to go back to fn objects in the hope that I don't have to specify lifetimes.

This commit is contained in:
Tom Alexander
2022-07-16 21:16:34 -04:00
parent 5c39a6a7bf
commit 9d8fddb44d
3 changed files with 39 additions and 61 deletions

View File

@@ -37,38 +37,13 @@ use nom::IResult;
// ))(i)
// });
pub trait ParserWithContext {
fn bind_context<'a, 'c>(
&mut self,
context: &mut NomContext<'c, &'a str, &'a str, VerboseError<&'a str>>,
) -> Box<dyn FnMut(&'a str) -> IResult<&'a str, TextElement<'a>, VerboseError<&'a str>>>;
}
impl<F> ParserWithContext for F
where
F: for<'a, 'c> FnMut(
&'a str,
&mut NomContext<'c, &'a str, &'a str, VerboseError<&'a str>>,
) -> Res<&'a str, TextElement<'a>>,
{
fn bind_context<'c>(
&mut self,
context: &mut NomContext<'c, &str, &str, VerboseError<&str>>,
) -> Box<
(dyn for<'a> FnMut(
&'a str,
)
-> Result<(&'a str, TextElement<'a>), nom::Err<VerboseError<&'a str>>>
+ 'static),
> {
Box::new(|i| self(i, context))
}
}
pub fn flat_text_element<'a, 'c>(
pub fn flat_text_element<'a, F>(
i: &'a str,
context: &mut NomContext<'c, &'a str, &'a str, VerboseError<&'a str>>,
) -> Res<&'a str, TextElement<'a>> {
context: &mut NomContext<F>,
) -> Res<&'a str, TextElement<'a>>
where
F: for<'b> FnMut(&'b str) -> IResult<&'b str, &'b str, VerboseError<&'b str>>,
{
// not(context.fail_matcher)(i)?;
// todo
todo!()