Apply a similar optimization to the detect element parser but also unify detection of affiliated keywords.

This commit is contained in:
Tom Alexander
2023-10-16 14:55:40 -04:00
parent 0020d71089
commit 7833a58461
6 changed files with 108 additions and 39 deletions

View File

@@ -125,7 +125,7 @@ fn footnote_definition_end<'b, 'g, 'r, 's>(
let (remaining, source) = alt((
recognize(tuple((
parser_with_context!(maybe_consume_trailing_whitespace)(context),
parser_with_context!(detect_footnote_definition)(context),
|i| detect_footnote_definition(std::iter::empty(), i, context, i),
))),
recognize(tuple((
start_of_line,
@@ -138,13 +138,20 @@ fn footnote_definition_end<'b, 'g, 'r, 's>(
Ok((remaining, source))
}
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
pub(crate) fn detect_footnote_definition<'b, 'g, 'r, 's>(
#[cfg_attr(
feature = "tracing",
tracing::instrument(ret, level = "debug", skip(context, affiliated_keywords))
)]
pub(crate) fn detect_footnote_definition<'b, 'g, 'r, 's, AK>(
affiliated_keywords: AK,
remaining: OrgSource<'s>,
context: RefContext<'b, 'g, 'r, 's>,
input: OrgSource<'s>,
) -> Res<OrgSource<'s>, ()> {
let (input, _) = many0(parser_with_context!(affiliated_keyword)(context))(input)?;
tuple((start_of_line, tag_no_case("[fn:"), label, tag("]")))(input)?;
) -> Res<OrgSource<'s>, ()>
where
AK: IntoIterator<Item = Keyword<'s>>,
{
tuple((start_of_line, tag_no_case("[fn:"), label, tag("]")))(remaining)?;
Ok((input, ()))
}