Port greater blocker over to ak_element!().

This commit is contained in:
Tom Alexander 2023-10-12 16:27:57 -04:00
parent 5136880532
commit 59448a4f2c
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE
2 changed files with 40 additions and 20 deletions

View File

@ -74,7 +74,14 @@ fn _element<'b, 'g, 'r, 's>(
Element::PlainList Element::PlainList
); );
let greater_block_matcher = parser_with_context!(greater_block)(context); ak_element!(
greater_block,
&mut affiliated_keywords,
post_affiliated_keywords_input,
context,
input
);
let dynamic_block_matcher = parser_with_context!(dynamic_block)(context); let dynamic_block_matcher = parser_with_context!(dynamic_block)(context);
let footnote_definition_matcher = parser_with_context!(footnote_definition)(context); let footnote_definition_matcher = parser_with_context!(footnote_definition)(context);
let comment_matcher = parser_with_context!(comment)(context); let comment_matcher = parser_with_context!(comment)(context);
@ -101,7 +108,6 @@ fn _element<'b, 'g, 'r, 's>(
let _enter = span.enter(); let _enter = span.enter();
opt(alt(( opt(alt((
greater_block_matcher,
map(dynamic_block_matcher, Element::DynamicBlock), map(dynamic_block_matcher, Element::DynamicBlock),
map(footnote_definition_matcher, Element::FootnoteDefinition), map(footnote_definition_matcher, Element::FootnoteDefinition),
map(comment_matcher, Element::Comment), map(comment_matcher, Element::Comment),

View File

@ -18,7 +18,6 @@ use nom::sequence::preceded;
use nom::sequence::tuple; use nom::sequence::tuple;
use super::affiliated_keyword::parse_affiliated_keywords; use super::affiliated_keyword::parse_affiliated_keywords;
use super::keyword::affiliated_keyword;
use super::org_source::OrgSource; use super::org_source::OrgSource;
use super::util::in_section; use super::util::in_section;
use super::util::maybe_consume_trailing_whitespace_if_not_exiting; use super::util::maybe_consume_trailing_whitespace_if_not_exiting;
@ -48,12 +47,15 @@ use crate::types::SpecialBlock;
feature = "tracing", feature = "tracing",
tracing::instrument(ret, level = "debug", skip(context)) tracing::instrument(ret, level = "debug", skip(context))
)] )]
pub(crate) fn greater_block<'b, 'g, 'r, 's>( pub(crate) fn greater_block<'b, 'g, 'r, 's, AK>(
context: RefContext<'b, 'g, 'r, 's>, affiliated_keywords: AK,
input: OrgSource<'s>, input: OrgSource<'s>,
) -> Res<OrgSource<'s>, Element<'s>> { context: RefContext<'b, 'g, 'r, 's>,
let pre_affiliated_keywords_input = input; pre_affiliated_keywords_input: OrgSource<'s>,
let (input, affiliated_keywords) = many0(affiliated_keyword)(input)?; ) -> Res<OrgSource<'s>, Element<'s>>
where
AK: IntoIterator<Item = Keyword<'s>>,
{
start_of_line(input)?; start_of_line(input)?;
let (remaining, _leading_whitespace) = space0(input)?; let (remaining, _leading_whitespace) = space0(input)?;
let (remaining, (_begin, name)) = tuple(( let (remaining, (_begin, name)) = tuple((
@ -93,12 +95,15 @@ pub(crate) fn greater_block<'b, 'g, 'r, 's>(
feature = "tracing", feature = "tracing",
tracing::instrument(ret, level = "debug", skip(context)) tracing::instrument(ret, level = "debug", skip(context))
)] )]
fn center_block<'b, 'g, 'r, 's>( fn center_block<'b, 'g, 'r, 's, AK>(
context: RefContext<'b, 'g, 'r, 's>, context: RefContext<'b, 'g, 'r, 's>,
input: OrgSource<'s>, input: OrgSource<'s>,
pre_affiliated_keywords_input: OrgSource<'s>, pre_affiliated_keywords_input: OrgSource<'s>,
affiliated_keywords: Vec<Keyword<'s>>, affiliated_keywords: AK,
) -> Res<OrgSource<'s>, Element<'s>> { ) -> Res<OrgSource<'s>, Element<'s>>
where
AK: IntoIterator<Item = Keyword<'s>>,
{
let (remaining, (source, children)) = greater_block_body( let (remaining, (source, children)) = greater_block_body(
context, context,
input, input,
@ -123,12 +128,15 @@ fn center_block<'b, 'g, 'r, 's>(
feature = "tracing", feature = "tracing",
tracing::instrument(ret, level = "debug", skip(context)) tracing::instrument(ret, level = "debug", skip(context))
)] )]
fn quote_block<'b, 'g, 'r, 's>( fn quote_block<'b, 'g, 'r, 's, AK>(
context: RefContext<'b, 'g, 'r, 's>, context: RefContext<'b, 'g, 'r, 's>,
input: OrgSource<'s>, input: OrgSource<'s>,
pre_affiliated_keywords_input: OrgSource<'s>, pre_affiliated_keywords_input: OrgSource<'s>,
affiliated_keywords: Vec<Keyword<'s>>, affiliated_keywords: AK,
) -> Res<OrgSource<'s>, Element<'s>> { ) -> Res<OrgSource<'s>, Element<'s>>
where
AK: IntoIterator<Item = Keyword<'s>>,
{
let (remaining, (source, children)) = greater_block_body( let (remaining, (source, children)) = greater_block_body(
context, context,
input, input,
@ -149,15 +157,18 @@ fn quote_block<'b, 'g, 'r, 's>(
)) ))
} }
fn special_block<'s>( fn special_block<'s, AK>(
name: &'s str, name: &'s str,
) -> impl for<'b, 'g, 'r> Fn( ) -> impl for<'b, 'g, 'r> Fn(
RefContext<'b, 'g, 'r, 's>, RefContext<'b, 'g, 'r, 's>,
OrgSource<'s>, OrgSource<'s>,
OrgSource<'s>, OrgSource<'s>,
Vec<Keyword<'s>>, AK,
) -> Res<OrgSource<'s>, Element<'s>> ) -> Res<OrgSource<'s>, Element<'s>>
+ 's { + 's
where
AK: IntoIterator<Item = Keyword<'s>>,
{
let context_name = format!("special block {}", name); let context_name = format!("special block {}", name);
move |context, input, pre_affiliated_keywords_input, affiliated_keywords| { move |context, input, pre_affiliated_keywords_input, affiliated_keywords| {
_special_block( _special_block(
@ -175,14 +186,17 @@ fn special_block<'s>(
feature = "tracing", feature = "tracing",
tracing::instrument(ret, level = "debug", skip(context)) tracing::instrument(ret, level = "debug", skip(context))
)] )]
fn _special_block<'c, 'b, 'g, 'r, 's>( fn _special_block<'c, 'b, 'g, 'r, 's, AK>(
context: RefContext<'b, 'g, 'r, 's>, context: RefContext<'b, 'g, 'r, 's>,
input: OrgSource<'s>, input: OrgSource<'s>,
pre_affiliated_keywords_input: OrgSource<'s>, pre_affiliated_keywords_input: OrgSource<'s>,
name: &'s str, name: &'s str,
context_name: &'c str, context_name: &'c str,
affiliated_keywords: Vec<Keyword<'s>>, affiliated_keywords: AK,
) -> Res<OrgSource<'s>, Element<'s>> { ) -> Res<OrgSource<'s>, Element<'s>>
where
AK: IntoIterator<Item = Keyword<'s>>,
{
let (remaining, parameters) = opt(tuple((space1, parameters)))(input)?; let (remaining, parameters) = opt(tuple((space1, parameters)))(input)?;
let (remaining, (source, children)) = greater_block_body( let (remaining, (source, children)) = greater_block_body(
context, context,