diff --git a/src/intermediate/entity.rs b/src/intermediate/entity.rs index 6b22e7b..0f47742 100644 --- a/src/intermediate/entity.rs +++ b/src/intermediate/entity.rs @@ -7,7 +7,7 @@ pub(crate) struct IEntity { pub(crate) html: String, } -intermediate!(IEntity, Entity, |registry, original| async { +intermediate!(IEntity, Entity, original, registry, { Ok(IEntity { html: original.html.to_owned(), }) diff --git a/src/intermediate/footnote_definition.rs b/src/intermediate/footnote_definition.rs index 1b51fd4..6049f14 100644 --- a/src/intermediate/footnote_definition.rs +++ b/src/intermediate/footnote_definition.rs @@ -9,7 +9,9 @@ pub(crate) struct IFootnoteDefinition {} intermediate!( IFootnoteDefinition, FootnoteDefinition, - |registry, original| async { + original, + registry, + { registry .register_footnote_definition(original.label, &original.children) .await?; diff --git a/src/intermediate/footnote_reference.rs b/src/intermediate/footnote_reference.rs index d06ffa7..aabd7e9 100644 --- a/src/intermediate/footnote_reference.rs +++ b/src/intermediate/footnote_reference.rs @@ -8,19 +8,15 @@ pub(crate) struct IFootnoteReference { duplicate_offset: usize, } -intermediate!( - IFootnoteReference, - FootnoteReference, - |registry, original| async { - let footnote_id = registry - .get_footnote_reference_id(original.label, &original.definition) - .await?; - Ok(IFootnoteReference { - footnote_id, - duplicate_offset: 0, // TODO - }) - } -); +intermediate!(IFootnoteReference, FootnoteReference, original, registry, { + let footnote_id = registry + .get_footnote_reference_id(original.label, &original.definition) + .await?; + Ok(IFootnoteReference { + footnote_id, + duplicate_offset: 0, // TODO + }) +}); impl IFootnoteReference { pub(crate) fn get_display_label(&self) -> String { diff --git a/src/intermediate/heading.rs b/src/intermediate/heading.rs index 501b706..8236652 100644 --- a/src/intermediate/heading.rs +++ b/src/intermediate/heading.rs @@ -11,7 +11,7 @@ pub(crate) struct IHeading { pub(crate) children: Vec, } -intermediate!(IHeading, Heading, |registry, original| async { +intermediate!(IHeading, Heading, original, registry, { let title = { let mut ret = Vec::new(); for obj in original.title.iter() { diff --git a/src/intermediate/inline_source_block.rs b/src/intermediate/inline_source_block.rs index 195afdc..700f2fd 100644 --- a/src/intermediate/inline_source_block.rs +++ b/src/intermediate/inline_source_block.rs @@ -7,12 +7,8 @@ pub(crate) struct IInlineSourceBlock { pub(crate) value: String, } -intermediate!( - IInlineSourceBlock, - InlineSourceBlock, - |registry, original| async { - Ok(IInlineSourceBlock { - value: original.value.to_owned(), - }) - } -); +intermediate!(IInlineSourceBlock, InlineSourceBlock, original, registry, { + Ok(IInlineSourceBlock { + value: original.value.to_owned(), + }) +}); diff --git a/src/intermediate/macros.rs b/src/intermediate/macros.rs index 42f9de0..8c65d1f 100644 --- a/src/intermediate/macros.rs +++ b/src/intermediate/macros.rs @@ -23,13 +23,15 @@ pub(crate) use inoop; /// /// This exists to make changing the type signature easier. macro_rules! intermediate { - ($istruct:ident, $pstruct:ident, $fnbody:expr) => { + ($istruct:ident, $pstruct:ident, $original:ident, $registry:ident, $fnbody:tt) => { impl $istruct { pub(crate) async fn new<'reg, 'orig, 'parse>( registry: &'reg mut Registry<'orig, 'parse>, original: &'orig organic::types::$pstruct<'parse>, ) -> Result<$istruct, CustomError> { - $fnbody(registry, original).await + let $original = original; + let $registry = registry; + $fnbody } } }; diff --git a/src/intermediate/paragraph.rs b/src/intermediate/paragraph.rs index 6a33a4c..90df531 100644 --- a/src/intermediate/paragraph.rs +++ b/src/intermediate/paragraph.rs @@ -8,7 +8,7 @@ pub(crate) struct IParagraph { pub(crate) children: Vec, } -intermediate!(IParagraph, Paragraph, |registry, original| async { +intermediate!(IParagraph, Paragraph, original, registry, { let children = { let mut ret = Vec::new(); for obj in original.children.iter() { diff --git a/src/intermediate/plain_list.rs b/src/intermediate/plain_list.rs index 61ec964..2b208a1 100644 --- a/src/intermediate/plain_list.rs +++ b/src/intermediate/plain_list.rs @@ -9,7 +9,7 @@ pub(crate) struct IPlainList { pub(crate) children: Vec, } -intermediate!(IPlainList, PlainList, |registry, original| async { +intermediate!(IPlainList, PlainList, original, registry, { let children = { let mut ret = Vec::new(); for obj in original.children.iter() { diff --git a/src/intermediate/plain_list_item.rs b/src/intermediate/plain_list_item.rs index 7af4933..774c838 100644 --- a/src/intermediate/plain_list_item.rs +++ b/src/intermediate/plain_list_item.rs @@ -10,7 +10,7 @@ pub(crate) struct IPlainListItem { pub(crate) children: Vec, } -intermediate!(IPlainListItem, PlainListItem, |registry, original| async { +intermediate!(IPlainListItem, PlainListItem, original, registry, { let tag = { let mut ret = Vec::new(); for obj in original.tag.iter() { diff --git a/src/intermediate/plain_text.rs b/src/intermediate/plain_text.rs index 24c6a68..1dceef4 100644 --- a/src/intermediate/plain_text.rs +++ b/src/intermediate/plain_text.rs @@ -8,7 +8,7 @@ pub(crate) struct IPlainText { pub(crate) source: String, } -intermediate!(IPlainText, PlainText, |registry, original| async { +intermediate!(IPlainText, PlainText, original, registry, { Ok(IPlainText { source: coalesce_whitespace(original.source).into_owned(), }) diff --git a/src/intermediate/quote_block.rs b/src/intermediate/quote_block.rs index 27ef6e2..0a74a35 100644 --- a/src/intermediate/quote_block.rs +++ b/src/intermediate/quote_block.rs @@ -8,7 +8,7 @@ pub(crate) struct IQuoteBlock { pub(crate) children: Vec, } -intermediate!(IQuoteBlock, QuoteBlock, |registry, original| async { +intermediate!(IQuoteBlock, QuoteBlock, original, registry, { let children = { let mut ret = Vec::new(); for obj in original.children.iter() { diff --git a/src/intermediate/registry.rs b/src/intermediate/registry.rs index 4fe888f..256a5a6 100644 --- a/src/intermediate/registry.rs +++ b/src/intermediate/registry.rs @@ -1,4 +1,5 @@ use std::collections::HashMap; +use std::marker::PhantomData; use super::ast_node::IntoIAstNode; use crate::error::CustomError; @@ -12,10 +13,8 @@ type IdCounter = u16; pub(crate) struct Registry<'orig, 'parse> { id_counter: IdCounter, targets: HashMap<&'parse str, String>, - footnote_ids: Vec<( - Option<&'parse str>, - FootnoteDefinitionContents<'orig, 'parse>, - )>, + footnote_ids: Vec<(Option<&'parse str>, Vec)>, + _phantom: PhantomData<&'orig ()>, } impl<'orig, 'parse> Registry<'orig, 'parse> { @@ -24,6 +23,7 @@ impl<'orig, 'parse> Registry<'orig, 'parse> { id_counter: 0, targets: HashMap::new(), footnote_ids: Vec::new(), + _phantom: PhantomData, } } @@ -35,12 +35,10 @@ impl<'orig, 'parse> Registry<'orig, 'parse> { } pub(crate) fn get_footnote_ids(&self) -> impl Iterator)> { - // TODO - std::iter::empty() - // self.footnote_ids - // .iter() - // .map(|(_label, definition)| definition) - // .enumerate() + self.footnote_ids + .iter() + .map(|(_label, definition)| definition) + .enumerate() } /// Get a 0-indexed ID for a footnote. @@ -126,8 +124,3 @@ async fn convert_definition_contents<'reg, 'orig, 'parse>( Ok(contents) } - -enum FootnoteDefinitionContents<'orig, 'parse> { - FromReference(&'orig Vec>), - FromDefinition(&'orig Vec>), -} diff --git a/src/intermediate/regular_link.rs b/src/intermediate/regular_link.rs index 6b155cc..8b8ada5 100644 --- a/src/intermediate/regular_link.rs +++ b/src/intermediate/regular_link.rs @@ -9,7 +9,7 @@ pub(crate) struct IRegularLink { pub(crate) children: Vec, } -intermediate!(IRegularLink, RegularLink, |registry, original| async { +intermediate!(IRegularLink, RegularLink, original, registry, { let children = { let mut ret = Vec::new(); for obj in original.children.iter() { diff --git a/src/intermediate/section.rs b/src/intermediate/section.rs index e1c81ee..dea8f2e 100644 --- a/src/intermediate/section.rs +++ b/src/intermediate/section.rs @@ -8,7 +8,7 @@ pub(crate) struct ISection { pub(crate) children: Vec, } -intermediate!(ISection, Section, |registry, original| async { +intermediate!(ISection, Section, original, registry, { let children = { let mut ret = Vec::new(); for elem in original.children.iter() { diff --git a/src/intermediate/src_block.rs b/src/intermediate/src_block.rs index 2a1c608..e780497 100644 --- a/src/intermediate/src_block.rs +++ b/src/intermediate/src_block.rs @@ -7,7 +7,7 @@ pub(crate) struct ISrcBlock { pub(crate) lines: Vec, } -intermediate!(ISrcBlock, SrcBlock, |registry, original| async { +intermediate!(ISrcBlock, SrcBlock, original, registry, { let lines = original .contents .split_inclusive('\n') diff --git a/src/intermediate/target.rs b/src/intermediate/target.rs index 1e41833..138d491 100644 --- a/src/intermediate/target.rs +++ b/src/intermediate/target.rs @@ -8,7 +8,7 @@ pub(crate) struct ITarget { value: String, } -intermediate!(ITarget, Target, |registry, original| async { +intermediate!(ITarget, Target, original, registry, { let id = registry.get_target(original.value); Ok(ITarget { id: id.clone(),