Switch to nom's consumed.

This commit is contained in:
Tom Alexander 2022-12-18 06:42:02 -05:00
parent 89758721ed
commit f39319702c
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE
2 changed files with 2 additions and 26 deletions

View File

@ -1,5 +1,3 @@
use std::ops::RangeTo;
use super::parser_context::ContextElement;
use super::parser_context::PreviousElementNode;
use super::token::Token;
@ -8,28 +6,6 @@ use nom::error::ErrorKind;
use nom::error::ParseError;
use nom::IResult;
use nom::InputLength;
use nom::Offset;
use nom::Parser;
use nom::Slice;
/// Return both the parsed output and the output of recognize() together without having to run the child parser twice.
pub fn also_recognize<I: Clone + Offset + Slice<RangeTo<usize>>, O, E: ParseError<I>, F>(
mut parser: F,
) -> impl FnMut(I) -> IResult<I, (I, O), E>
where
F: Parser<I, O, E>,
{
move |input: I| {
let i = input.clone();
match parser.parse(i) {
Ok((i, val)) => {
let index = input.offset(&i);
Ok((i, (input.slice(..index), val)))
}
Err(e) => Err(e),
}
}
}
pub fn context_many1<'r, 's, I, O, E, M>(
context: Context<'r, 's>,

View File

@ -1,4 +1,3 @@
use super::combinator::also_recognize;
use super::combinator::context_many_till;
use super::error::Res;
use super::parser_context::ChainBehavior;
@ -12,6 +11,7 @@ use super::token::TextElement;
use super::token::Token;
use super::Context;
use nom::branch::alt;
use nom::combinator::consumed;
use nom::combinator::eof;
use nom::combinator::map;
use nom::combinator::not;
@ -27,7 +27,7 @@ pub fn paragraph<'r, 's>(context: Context<'r, 's>, i: &'s str) -> Res<&'s str, P
exit_matcher: ChainBehavior::AndParent(Some(&context_paragraph_end)),
}))
.with_additional_node(ContextElement::StartOfParagraph);
let (remaining, (source, (many, till))) = also_recognize(context_many_till(
let (remaining, (source, (many, till))) = consumed(context_many_till(
&paragraph_context,
text_element,
context_paragraph_end,