Create an also_recognize combinator to make providing source slices fast and safe.

This commit is contained in:
Tom Alexander
2022-12-18 04:30:44 -05:00
parent 60d9487fdf
commit 448dcfac72
3 changed files with 33 additions and 19 deletions

View File

@@ -1,3 +1,4 @@
use super::combinator::also_recognize;
use super::combinator::context_many_till;
use super::error::Res;
use super::parser_context::ChainBehavior;
@@ -26,8 +27,11 @@ 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, (many, till)) =
context_many_till(&paragraph_context, text_element, context_paragraph_end)(i)?;
let (remaining, (source, (many, till))) = also_recognize(context_many_till(
&paragraph_context,
text_element,
context_paragraph_end,
))(i)?;
let many = many
.into_iter()
.filter_map(|token| match token {
@@ -40,6 +44,7 @@ pub fn paragraph<'r, 's>(context: Context<'r, 's>, i: &'s str) -> Res<&'s str, P
Paragraph {
contents: many,
paragraph_end: till,
source,
},
))
}