Weird lifetime issue.
This commit is contained in:
parent
11cf24a500
commit
ff65776607
@ -39,12 +39,12 @@ use nom::Parser;
|
||||
use tracing::instrument;
|
||||
use tracing::trace;
|
||||
|
||||
type UnboundMatcher<'r, I, O, E> = dyn for<'s> Fn(Context<'r>, I) -> IResult<I, O, E>;
|
||||
type UnboundMatcher<'r, I, O, E> = dyn Fn(Context<'r>, I) -> IResult<I, O, E>;
|
||||
|
||||
fn context_many_till<'r, I, O, E, F>(
|
||||
context: Context<'r>,
|
||||
mut many_matcher: UnboundMatcher<'r, I, O, E>,
|
||||
mut till_matcher: UnboundMatcher<'r, I, F, E>,
|
||||
mut many_matcher: &UnboundMatcher<'r, I, O, E>,
|
||||
mut till_matcher: &UnboundMatcher<'r, I, F, E>,
|
||||
) -> impl FnMut(I) -> IResult<I, (Vec<O>, F), E>
|
||||
where
|
||||
I: Clone + InputLength,
|
||||
@ -54,10 +54,12 @@ where
|
||||
let mut ret = Vec::new();
|
||||
loop {
|
||||
let len = i.input_len();
|
||||
match till_matcher.parse(i.clone()) {
|
||||
let till_parser = parser_with_context!(till_matcher);
|
||||
match till_parser(context.clone())(i.clone()) {
|
||||
Ok((remaining, finish)) => return Ok((remaining, (ret, finish))),
|
||||
Err(nom::Err::Error(_)) => {
|
||||
match many_matcher.parse(i.clone()) {
|
||||
let many_parser = parser_with_context!(many_matcher);
|
||||
match many_parser(context.clone())(i.clone()) {
|
||||
Err(nom::Err::Error(err)) => {
|
||||
return Err(nom::Err::Error(E::append(i, ErrorKind::ManyTill, err)))
|
||||
}
|
||||
@ -77,7 +79,7 @@ where
|
||||
}
|
||||
}
|
||||
Err(e) => return Err(e),
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -89,6 +91,10 @@ pub fn document(input: &str) -> Res<&str, Vec<(Vec<TextElement>, &str)>> {
|
||||
ret
|
||||
}
|
||||
|
||||
pub fn context_paragraph_end<'s, 'r>(context: Context<'r>, input: &str) -> Res<&str, &str> {
|
||||
paragraph_end(input)
|
||||
}
|
||||
|
||||
pub fn paragraph<'s, 'r>(
|
||||
context: Context<'r>,
|
||||
i: &'s str,
|
||||
@ -100,8 +106,11 @@ pub fn paragraph<'s, 'r>(
|
||||
fail_matcher: ChainBehavior::AndParent(Some(¶graph_end)),
|
||||
}));
|
||||
let ret = {
|
||||
let text_element_parser = parser_with_context!(flat_text_element)(paragraph_context);
|
||||
context_many_till(¶graph_context, text_element_parser, paragraph_end)(i)
|
||||
context_many_till(
|
||||
¶graph_context,
|
||||
&flat_text_element,
|
||||
&context_paragraph_end,
|
||||
)(i)
|
||||
};
|
||||
ret
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user