Add a macro for calling parsers that take in the affiliated keywords.

This commit is contained in:
Tom Alexander 2023-10-12 16:06:59 -04:00
parent a6f36ba679
commit 6ca4dc8ffc
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE
3 changed files with 40 additions and 1 deletions

View File

@ -32,6 +32,7 @@ use super::lesser_block::verse_block;
use super::org_source::OrgSource; use super::org_source::OrgSource;
use super::paragraph::paragraph; use super::paragraph::paragraph;
use super::plain_list::detect_plain_list; use super::plain_list::detect_plain_list;
use super::plain_list::new_plain_list;
use super::plain_list::plain_list; use super::plain_list::plain_list;
use super::table::detect_table; use super::table::detect_table;
use crate::context::parser_with_context; use crate::context::parser_with_context;
@ -39,6 +40,7 @@ use crate::context::RefContext;
use crate::error::CustomError; use crate::error::CustomError;
use crate::error::MyError; use crate::error::MyError;
use crate::error::Res; use crate::error::Res;
use crate::parser::macros::ak_element;
use crate::parser::table::org_mode_table; use crate::parser::table::org_mode_table;
use crate::types::Element; use crate::types::Element;
@ -62,6 +64,17 @@ fn _element<'b, 'g, 'r, 's>(
) -> Res<OrgSource<'s>, Element<'s>> { ) -> Res<OrgSource<'s>, Element<'s>> {
let (post_affiliated_keywords_input, affiliated_keywords) = many0(affiliated_keyword)(input)?; 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 plain_list_matcher = parser_with_context!(plain_list)(context);
let greater_block_matcher = parser_with_context!(greater_block)(context); let greater_block_matcher = parser_with_context!(greater_block)(context);
let dynamic_block_matcher = parser_with_context!(dynamic_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 { if maybe_element.is_none() && can_be_paragraph {
#[cfg(feature = "tracing")] #[cfg(feature = "tracing")]
let span = span!( let span = span!(

View File

@ -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;

View File

@ -91,7 +91,7 @@ pub(crate) fn new_plain_list<'b, 'g, 'r, 's, AK>(
input: OrgSource<'s>, input: OrgSource<'s>,
) -> Res<OrgSource<'s>, PlainList<'s>> ) -> Res<OrgSource<'s>, PlainList<'s>>
where where
AK: Iterator<Item = Keyword<'s>>, AK: IntoIterator<Item = Keyword<'s>>,
{ {
todo!() todo!()
} }