From 59448a4f2c7f4736c504d599d7d8634c9e3fa0be Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Thu, 12 Oct 2023 16:27:57 -0400 Subject: [PATCH] Port greater blocker over to ak_element!(). --- src/parser/element_parser.rs | 10 ++++++-- src/parser/greater_block.rs | 50 +++++++++++++++++++++++------------- 2 files changed, 40 insertions(+), 20 deletions(-) diff --git a/src/parser/element_parser.rs b/src/parser/element_parser.rs index 59edad62..ef67395f 100644 --- a/src/parser/element_parser.rs +++ b/src/parser/element_parser.rs @@ -74,7 +74,14 @@ fn _element<'b, 'g, 'r, 's>( 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 footnote_definition_matcher = parser_with_context!(footnote_definition)(context); let comment_matcher = parser_with_context!(comment)(context); @@ -101,7 +108,6 @@ fn _element<'b, 'g, 'r, 's>( let _enter = span.enter(); opt(alt(( - greater_block_matcher, map(dynamic_block_matcher, Element::DynamicBlock), map(footnote_definition_matcher, Element::FootnoteDefinition), map(comment_matcher, Element::Comment), diff --git a/src/parser/greater_block.rs b/src/parser/greater_block.rs index 17ba0723..daf59dfc 100644 --- a/src/parser/greater_block.rs +++ b/src/parser/greater_block.rs @@ -18,7 +18,6 @@ use nom::sequence::preceded; use nom::sequence::tuple; use super::affiliated_keyword::parse_affiliated_keywords; -use super::keyword::affiliated_keyword; use super::org_source::OrgSource; use super::util::in_section; use super::util::maybe_consume_trailing_whitespace_if_not_exiting; @@ -48,12 +47,15 @@ use crate::types::SpecialBlock; feature = "tracing", tracing::instrument(ret, level = "debug", skip(context)) )] -pub(crate) fn greater_block<'b, 'g, 'r, 's>( - context: RefContext<'b, 'g, 'r, 's>, +pub(crate) fn greater_block<'b, 'g, 'r, 's, AK>( + affiliated_keywords: AK, input: OrgSource<'s>, -) -> Res, Element<'s>> { - let pre_affiliated_keywords_input = input; - let (input, affiliated_keywords) = many0(affiliated_keyword)(input)?; + context: RefContext<'b, 'g, 'r, 's>, + pre_affiliated_keywords_input: OrgSource<'s>, +) -> Res, Element<'s>> +where + AK: IntoIterator>, +{ start_of_line(input)?; let (remaining, _leading_whitespace) = space0(input)?; let (remaining, (_begin, name)) = tuple(( @@ -93,12 +95,15 @@ pub(crate) fn greater_block<'b, 'g, 'r, 's>( feature = "tracing", 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>, input: OrgSource<'s>, pre_affiliated_keywords_input: OrgSource<'s>, - affiliated_keywords: Vec>, -) -> Res, Element<'s>> { + affiliated_keywords: AK, +) -> Res, Element<'s>> +where + AK: IntoIterator>, +{ let (remaining, (source, children)) = greater_block_body( context, input, @@ -123,12 +128,15 @@ fn center_block<'b, 'g, 'r, 's>( feature = "tracing", 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>, input: OrgSource<'s>, pre_affiliated_keywords_input: OrgSource<'s>, - affiliated_keywords: Vec>, -) -> Res, Element<'s>> { + affiliated_keywords: AK, +) -> Res, Element<'s>> +where + AK: IntoIterator>, +{ let (remaining, (source, children)) = greater_block_body( context, input, @@ -149,15 +157,18 @@ fn quote_block<'b, 'g, 'r, 's>( )) } -fn special_block<'s>( +fn special_block<'s, AK>( name: &'s str, ) -> impl for<'b, 'g, 'r> Fn( RefContext<'b, 'g, 'r, 's>, OrgSource<'s>, OrgSource<'s>, - Vec>, + AK, ) -> Res, Element<'s>> - + 's { + + 's +where + AK: IntoIterator>, +{ let context_name = format!("special block {}", name); move |context, input, pre_affiliated_keywords_input, affiliated_keywords| { _special_block( @@ -175,14 +186,17 @@ fn special_block<'s>( feature = "tracing", 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>, input: OrgSource<'s>, pre_affiliated_keywords_input: OrgSource<'s>, name: &'s str, context_name: &'c str, - affiliated_keywords: Vec>, -) -> Res, Element<'s>> { + affiliated_keywords: AK, +) -> Res, Element<'s>> +where + AK: IntoIterator>, +{ let (remaining, parameters) = opt(tuple((space1, parameters)))(input)?; let (remaining, (source, children)) = greater_block_body( context,