many_till ignoring context.

This commit is contained in:
Tom Alexander 2022-11-26 19:54:46 -05:00
parent c1778a4f12
commit d9f0eda5b7
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE
1 changed files with 29 additions and 3 deletions

View File

@ -49,8 +49,34 @@ where
E: ParseError<I>,
{
move |mut i: I| {
// todo
todo!()
let mut ret = Vec::new();
loop {
let len = i.input_len();
match till_matcher.parse(i.clone()) {
Ok((remaining, finish)) => return Ok((remaining, (ret, finish))),
Err(nom::Err::Error(_)) => {
match many_matcher.parse(i.clone()) {
Err(nom::Err::Error(err)) => {
return Err(nom::Err::Error(E::append(i, ErrorKind::ManyTill, err)))
}
Err(e) => return Err(e),
Ok((remaining, many_elem)) => {
// infinite loop check: the parser must always consume
if remaining.input_len() == len {
return Err(nom::Err::Error(E::from_error_kind(
remaining,
ErrorKind::ManyTill,
)));
}
ret.push(many_elem);
i = remaining;
}
}
}
Err(e) => return Err(e),
}
}
}
}
@ -70,7 +96,7 @@ pub fn paragraph<'s, 'r>(
let paragraph_context = context.with_additional_fail_matcher(&paragraph_end);
let text_element_parser = parser_with_context!(flat_text_element)(&paragraph_context);
let ret = context_many_till(&paragraph_context, text_element_parser, paragraph_end)(i);
let ret = many_till(text_element_parser, paragraph_end)(i);
// let ret = many_till(text_element_parser, paragraph_end)(i);
ret
}