From f39319702c241e40ccff76dd1385aa83ae3c60c9 Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Sun, 18 Dec 2022 06:42:02 -0500 Subject: [PATCH] Switch to nom's consumed. --- src/parser/combinator.rs | 24 ------------------------ src/parser/paragraph.rs | 4 ++-- 2 files changed, 2 insertions(+), 26 deletions(-) diff --git a/src/parser/combinator.rs b/src/parser/combinator.rs index fce936c..fc0ec87 100644 --- a/src/parser/combinator.rs +++ b/src/parser/combinator.rs @@ -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>, O, E: ParseError, F>( - mut parser: F, -) -> impl FnMut(I) -> IResult -where - F: Parser, -{ - 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>, diff --git a/src/parser/paragraph.rs b/src/parser/paragraph.rs index 391fc96..6097ec8 100644 --- a/src/parser/paragraph.rs +++ b/src/parser/paragraph.rs @@ -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( ¶graph_context, text_element, context_paragraph_end,