Avoid closures for the intermediate macro.
This commit is contained in:
parent
3d44d20384
commit
24b9782146
@ -7,7 +7,7 @@ pub(crate) struct IEntity {
|
|||||||
pub(crate) html: String,
|
pub(crate) html: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
intermediate!(IEntity, Entity, |registry, original| async {
|
intermediate!(IEntity, Entity, original, registry, {
|
||||||
Ok(IEntity {
|
Ok(IEntity {
|
||||||
html: original.html.to_owned(),
|
html: original.html.to_owned(),
|
||||||
})
|
})
|
||||||
|
@ -9,7 +9,9 @@ pub(crate) struct IFootnoteDefinition {}
|
|||||||
intermediate!(
|
intermediate!(
|
||||||
IFootnoteDefinition,
|
IFootnoteDefinition,
|
||||||
FootnoteDefinition,
|
FootnoteDefinition,
|
||||||
|registry, original| async {
|
original,
|
||||||
|
registry,
|
||||||
|
{
|
||||||
registry
|
registry
|
||||||
.register_footnote_definition(original.label, &original.children)
|
.register_footnote_definition(original.label, &original.children)
|
||||||
.await?;
|
.await?;
|
||||||
|
@ -8,10 +8,7 @@ pub(crate) struct IFootnoteReference {
|
|||||||
duplicate_offset: usize,
|
duplicate_offset: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
intermediate!(
|
intermediate!(IFootnoteReference, FootnoteReference, original, registry, {
|
||||||
IFootnoteReference,
|
|
||||||
FootnoteReference,
|
|
||||||
|registry, original| async {
|
|
||||||
let footnote_id = registry
|
let footnote_id = registry
|
||||||
.get_footnote_reference_id(original.label, &original.definition)
|
.get_footnote_reference_id(original.label, &original.definition)
|
||||||
.await?;
|
.await?;
|
||||||
@ -19,8 +16,7 @@ intermediate!(
|
|||||||
footnote_id,
|
footnote_id,
|
||||||
duplicate_offset: 0, // TODO
|
duplicate_offset: 0, // TODO
|
||||||
})
|
})
|
||||||
}
|
});
|
||||||
);
|
|
||||||
|
|
||||||
impl IFootnoteReference {
|
impl IFootnoteReference {
|
||||||
pub(crate) fn get_display_label(&self) -> String {
|
pub(crate) fn get_display_label(&self) -> String {
|
||||||
|
@ -11,7 +11,7 @@ pub(crate) struct IHeading {
|
|||||||
pub(crate) children: Vec<IDocumentElement>,
|
pub(crate) children: Vec<IDocumentElement>,
|
||||||
}
|
}
|
||||||
|
|
||||||
intermediate!(IHeading, Heading, |registry, original| async {
|
intermediate!(IHeading, Heading, original, registry, {
|
||||||
let title = {
|
let title = {
|
||||||
let mut ret = Vec::new();
|
let mut ret = Vec::new();
|
||||||
for obj in original.title.iter() {
|
for obj in original.title.iter() {
|
||||||
|
@ -7,12 +7,8 @@ pub(crate) struct IInlineSourceBlock {
|
|||||||
pub(crate) value: String,
|
pub(crate) value: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
intermediate!(
|
intermediate!(IInlineSourceBlock, InlineSourceBlock, original, registry, {
|
||||||
IInlineSourceBlock,
|
|
||||||
InlineSourceBlock,
|
|
||||||
|registry, original| async {
|
|
||||||
Ok(IInlineSourceBlock {
|
Ok(IInlineSourceBlock {
|
||||||
value: original.value.to_owned(),
|
value: original.value.to_owned(),
|
||||||
})
|
})
|
||||||
}
|
});
|
||||||
);
|
|
||||||
|
@ -23,13 +23,15 @@ pub(crate) use inoop;
|
|||||||
///
|
///
|
||||||
/// This exists to make changing the type signature easier.
|
/// This exists to make changing the type signature easier.
|
||||||
macro_rules! intermediate {
|
macro_rules! intermediate {
|
||||||
($istruct:ident, $pstruct:ident, $fnbody:expr) => {
|
($istruct:ident, $pstruct:ident, $original:ident, $registry:ident, $fnbody:tt) => {
|
||||||
impl $istruct {
|
impl $istruct {
|
||||||
pub(crate) async fn new<'reg, 'orig, 'parse>(
|
pub(crate) async fn new<'reg, 'orig, 'parse>(
|
||||||
registry: &'reg mut Registry<'orig, 'parse>,
|
registry: &'reg mut Registry<'orig, 'parse>,
|
||||||
original: &'orig organic::types::$pstruct<'parse>,
|
original: &'orig organic::types::$pstruct<'parse>,
|
||||||
) -> Result<$istruct, CustomError> {
|
) -> Result<$istruct, CustomError> {
|
||||||
$fnbody(registry, original).await
|
let $original = original;
|
||||||
|
let $registry = registry;
|
||||||
|
$fnbody
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -8,7 +8,7 @@ pub(crate) struct IParagraph {
|
|||||||
pub(crate) children: Vec<IObject>,
|
pub(crate) children: Vec<IObject>,
|
||||||
}
|
}
|
||||||
|
|
||||||
intermediate!(IParagraph, Paragraph, |registry, original| async {
|
intermediate!(IParagraph, Paragraph, original, registry, {
|
||||||
let children = {
|
let children = {
|
||||||
let mut ret = Vec::new();
|
let mut ret = Vec::new();
|
||||||
for obj in original.children.iter() {
|
for obj in original.children.iter() {
|
||||||
|
@ -9,7 +9,7 @@ pub(crate) struct IPlainList {
|
|||||||
pub(crate) children: Vec<IPlainListItem>,
|
pub(crate) children: Vec<IPlainListItem>,
|
||||||
}
|
}
|
||||||
|
|
||||||
intermediate!(IPlainList, PlainList, |registry, original| async {
|
intermediate!(IPlainList, PlainList, original, registry, {
|
||||||
let children = {
|
let children = {
|
||||||
let mut ret = Vec::new();
|
let mut ret = Vec::new();
|
||||||
for obj in original.children.iter() {
|
for obj in original.children.iter() {
|
||||||
|
@ -10,7 +10,7 @@ pub(crate) struct IPlainListItem {
|
|||||||
pub(crate) children: Vec<IElement>,
|
pub(crate) children: Vec<IElement>,
|
||||||
}
|
}
|
||||||
|
|
||||||
intermediate!(IPlainListItem, PlainListItem, |registry, original| async {
|
intermediate!(IPlainListItem, PlainListItem, original, registry, {
|
||||||
let tag = {
|
let tag = {
|
||||||
let mut ret = Vec::new();
|
let mut ret = Vec::new();
|
||||||
for obj in original.tag.iter() {
|
for obj in original.tag.iter() {
|
||||||
|
@ -8,7 +8,7 @@ pub(crate) struct IPlainText {
|
|||||||
pub(crate) source: String,
|
pub(crate) source: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
intermediate!(IPlainText, PlainText, |registry, original| async {
|
intermediate!(IPlainText, PlainText, original, registry, {
|
||||||
Ok(IPlainText {
|
Ok(IPlainText {
|
||||||
source: coalesce_whitespace(original.source).into_owned(),
|
source: coalesce_whitespace(original.source).into_owned(),
|
||||||
})
|
})
|
||||||
|
@ -8,7 +8,7 @@ pub(crate) struct IQuoteBlock {
|
|||||||
pub(crate) children: Vec<IElement>,
|
pub(crate) children: Vec<IElement>,
|
||||||
}
|
}
|
||||||
|
|
||||||
intermediate!(IQuoteBlock, QuoteBlock, |registry, original| async {
|
intermediate!(IQuoteBlock, QuoteBlock, original, registry, {
|
||||||
let children = {
|
let children = {
|
||||||
let mut ret = Vec::new();
|
let mut ret = Vec::new();
|
||||||
for obj in original.children.iter() {
|
for obj in original.children.iter() {
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
use std::marker::PhantomData;
|
||||||
|
|
||||||
use super::ast_node::IntoIAstNode;
|
use super::ast_node::IntoIAstNode;
|
||||||
use crate::error::CustomError;
|
use crate::error::CustomError;
|
||||||
@ -12,10 +13,8 @@ type IdCounter = u16;
|
|||||||
pub(crate) struct Registry<'orig, 'parse> {
|
pub(crate) struct Registry<'orig, 'parse> {
|
||||||
id_counter: IdCounter,
|
id_counter: IdCounter,
|
||||||
targets: HashMap<&'parse str, String>,
|
targets: HashMap<&'parse str, String>,
|
||||||
footnote_ids: Vec<(
|
footnote_ids: Vec<(Option<&'parse str>, Vec<IAstNode>)>,
|
||||||
Option<&'parse str>,
|
_phantom: PhantomData<&'orig ()>,
|
||||||
FootnoteDefinitionContents<'orig, 'parse>,
|
|
||||||
)>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'orig, 'parse> Registry<'orig, 'parse> {
|
impl<'orig, 'parse> Registry<'orig, 'parse> {
|
||||||
@ -24,6 +23,7 @@ impl<'orig, 'parse> Registry<'orig, 'parse> {
|
|||||||
id_counter: 0,
|
id_counter: 0,
|
||||||
targets: HashMap::new(),
|
targets: HashMap::new(),
|
||||||
footnote_ids: Vec::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<Item = (usize, &Vec<IAstNode>)> {
|
pub(crate) fn get_footnote_ids(&self) -> impl Iterator<Item = (usize, &Vec<IAstNode>)> {
|
||||||
// TODO
|
self.footnote_ids
|
||||||
std::iter::empty()
|
.iter()
|
||||||
// self.footnote_ids
|
.map(|(_label, definition)| definition)
|
||||||
// .iter()
|
.enumerate()
|
||||||
// .map(|(_label, definition)| definition)
|
|
||||||
// .enumerate()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get a 0-indexed ID for a footnote.
|
/// Get a 0-indexed ID for a footnote.
|
||||||
@ -126,8 +124,3 @@ async fn convert_definition_contents<'reg, 'orig, 'parse>(
|
|||||||
|
|
||||||
Ok(contents)
|
Ok(contents)
|
||||||
}
|
}
|
||||||
|
|
||||||
enum FootnoteDefinitionContents<'orig, 'parse> {
|
|
||||||
FromReference(&'orig Vec<Object<'parse>>),
|
|
||||||
FromDefinition(&'orig Vec<Object<'parse>>),
|
|
||||||
}
|
|
||||||
|
@ -9,7 +9,7 @@ pub(crate) struct IRegularLink {
|
|||||||
pub(crate) children: Vec<IObject>,
|
pub(crate) children: Vec<IObject>,
|
||||||
}
|
}
|
||||||
|
|
||||||
intermediate!(IRegularLink, RegularLink, |registry, original| async {
|
intermediate!(IRegularLink, RegularLink, original, registry, {
|
||||||
let children = {
|
let children = {
|
||||||
let mut ret = Vec::new();
|
let mut ret = Vec::new();
|
||||||
for obj in original.children.iter() {
|
for obj in original.children.iter() {
|
||||||
|
@ -8,7 +8,7 @@ pub(crate) struct ISection {
|
|||||||
pub(crate) children: Vec<IElement>,
|
pub(crate) children: Vec<IElement>,
|
||||||
}
|
}
|
||||||
|
|
||||||
intermediate!(ISection, Section, |registry, original| async {
|
intermediate!(ISection, Section, original, registry, {
|
||||||
let children = {
|
let children = {
|
||||||
let mut ret = Vec::new();
|
let mut ret = Vec::new();
|
||||||
for elem in original.children.iter() {
|
for elem in original.children.iter() {
|
||||||
|
@ -7,7 +7,7 @@ pub(crate) struct ISrcBlock {
|
|||||||
pub(crate) lines: Vec<String>,
|
pub(crate) lines: Vec<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
intermediate!(ISrcBlock, SrcBlock, |registry, original| async {
|
intermediate!(ISrcBlock, SrcBlock, original, registry, {
|
||||||
let lines = original
|
let lines = original
|
||||||
.contents
|
.contents
|
||||||
.split_inclusive('\n')
|
.split_inclusive('\n')
|
||||||
|
@ -8,7 +8,7 @@ pub(crate) struct ITarget {
|
|||||||
value: String,
|
value: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
intermediate!(ITarget, Target, |registry, original| async {
|
intermediate!(ITarget, Target, original, registry, {
|
||||||
let id = registry.get_target(original.value);
|
let id = registry.get_target(original.value);
|
||||||
Ok(ITarget {
|
Ok(ITarget {
|
||||||
id: id.clone(),
|
id: id.clone(),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user