Switch to nom's consumed.
This commit is contained in:
parent
89758721ed
commit
f39319702c
@ -1,5 +1,3 @@
|
|||||||
use std::ops::RangeTo;
|
|
||||||
|
|
||||||
use super::parser_context::ContextElement;
|
use super::parser_context::ContextElement;
|
||||||
use super::parser_context::PreviousElementNode;
|
use super::parser_context::PreviousElementNode;
|
||||||
use super::token::Token;
|
use super::token::Token;
|
||||||
@ -8,28 +6,6 @@ use nom::error::ErrorKind;
|
|||||||
use nom::error::ParseError;
|
use nom::error::ParseError;
|
||||||
use nom::IResult;
|
use nom::IResult;
|
||||||
use nom::InputLength;
|
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>(
|
pub fn context_many1<'r, 's, I, O, E, M>(
|
||||||
context: Context<'r, 's>,
|
context: Context<'r, 's>,
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
use super::combinator::also_recognize;
|
|
||||||
use super::combinator::context_many_till;
|
use super::combinator::context_many_till;
|
||||||
use super::error::Res;
|
use super::error::Res;
|
||||||
use super::parser_context::ChainBehavior;
|
use super::parser_context::ChainBehavior;
|
||||||
@ -12,6 +11,7 @@ use super::token::TextElement;
|
|||||||
use super::token::Token;
|
use super::token::Token;
|
||||||
use super::Context;
|
use super::Context;
|
||||||
use nom::branch::alt;
|
use nom::branch::alt;
|
||||||
|
use nom::combinator::consumed;
|
||||||
use nom::combinator::eof;
|
use nom::combinator::eof;
|
||||||
use nom::combinator::map;
|
use nom::combinator::map;
|
||||||
use nom::combinator::not;
|
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)),
|
exit_matcher: ChainBehavior::AndParent(Some(&context_paragraph_end)),
|
||||||
}))
|
}))
|
||||||
.with_additional_node(ContextElement::StartOfParagraph);
|
.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,
|
¶graph_context,
|
||||||
text_element,
|
text_element,
|
||||||
context_paragraph_end,
|
context_paragraph_end,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user