From 6ca4dc8ffcb3d64ede645053a690383ea7c5ed6b Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Thu, 12 Oct 2023 16:06:59 -0400 Subject: [PATCH] Add a macro for calling parsers that take in the affiliated keywords. --- src/parser/element_parser.rs | 15 +++++++++++++++ src/parser/macros.rs | 24 ++++++++++++++++++++++++ src/parser/plain_list.rs | 2 +- 3 files changed, 40 insertions(+), 1 deletion(-) diff --git a/src/parser/element_parser.rs b/src/parser/element_parser.rs index 0be0504..ff9a8c2 100644 --- a/src/parser/element_parser.rs +++ b/src/parser/element_parser.rs @@ -32,6 +32,7 @@ use super::lesser_block::verse_block; use super::org_source::OrgSource; use super::paragraph::paragraph; use super::plain_list::detect_plain_list; +use super::plain_list::new_plain_list; use super::plain_list::plain_list; use super::table::detect_table; use crate::context::parser_with_context; @@ -39,6 +40,7 @@ use crate::context::RefContext; use crate::error::CustomError; use crate::error::MyError; use crate::error::Res; +use crate::parser::macros::ak_element; use crate::parser::table::org_mode_table; use crate::types::Element; @@ -62,6 +64,17 @@ fn _element<'b, 'g, 'r, 's>( ) -> Res, Element<'s>> { let (post_affiliated_keywords_input, affiliated_keywords) = many0(affiliated_keyword)(input)?; + let mut affiliated_keywords = affiliated_keywords.into_iter(); + + ak_element!( + new_plain_list, + &mut affiliated_keywords, + post_affiliated_keywords_input, + context, + input, + Element::PlainList + ); + let plain_list_matcher = parser_with_context!(plain_list)(context); let greater_block_matcher = parser_with_context!(greater_block)(context); let dynamic_block_matcher = parser_with_context!(dynamic_block)(context); @@ -131,6 +144,8 @@ fn _element<'b, 'g, 'r, 's>( } } + // TODO: These two paragraphs need to be revisited using the affiliated keywords parsed above. + if maybe_element.is_none() && can_be_paragraph { #[cfg(feature = "tracing")] let span = span!( diff --git a/src/parser/macros.rs b/src/parser/macros.rs index 8b13789..86659ba 100644 --- a/src/parser/macros.rs +++ b/src/parser/macros.rs @@ -1 +1,25 @@ +/// Parse an element that has affiliated keywords. +macro_rules! ak_element { + ($parser:ident, $affiliated_keywords:expr, $post_affiliated_keywords_input: expr, $context: expr, $input: expr, $wrapper: expr) => { + if let Ok((remaining, ele)) = $parser( + $affiliated_keywords, + $post_affiliated_keywords_input, + $context, + $input, + ) { + return Ok((remaining, $wrapper(ele))); + } + }; + ($parser:ident, $affiliated_keywords:expr, $post_affiliated_keywords_input: expr, $context: expr, $input: expr) => { + if let Ok((remaining, ele)) = $parser( + $affiliated_keywords, + $post_affiliated_keywords_input, + $context, + $input, + ) { + return Ok((remaining, ele)); + } + }; +} +pub(crate) use ak_element; diff --git a/src/parser/plain_list.rs b/src/parser/plain_list.rs index adb0dc3..18f1ae7 100644 --- a/src/parser/plain_list.rs +++ b/src/parser/plain_list.rs @@ -91,7 +91,7 @@ pub(crate) fn new_plain_list<'b, 'g, 'r, 's, AK>( input: OrgSource<'s>, ) -> Res, PlainList<'s>> where - AK: Iterator>, + AK: IntoIterator>, { todo!() }