Use macros for creating the intermediate stage.

This is to make it easier to change function signatures by consolidating the places where the signatures exist.
This commit is contained in:
Tom Alexander 2023-10-29 17:29:16 -04:00
parent ba511b7f9e
commit f98a09bc59
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE
62 changed files with 565 additions and 972 deletions

View File

@ -1,15 +1,5 @@
use super::macros::inoop;
use super::registry::Registry;
use crate::error::CustomError;
use super::registry::Registry;
#[derive(Debug, Clone)]
pub(crate) struct IAngleLink {}
impl IAngleLink {
pub(crate) async fn new<'b, 'parse>(
registry: &'b mut Registry<'parse>,
original: &'b organic::types::AngleLink<'parse>,
) -> Result<IAngleLink, CustomError> {
Ok(IAngleLink {})
}
}
inoop!(IAngleLink, AngleLink);

View File

@ -113,19 +113,19 @@ pub(crate) enum IAstNode {
}
pub(crate) trait IntoIAstNode {
fn into_ast_node<'parse, 'b>(
&'b self,
registry: &'b mut Registry<'parse>,
) -> BoxFuture<'b, Result<IAstNode, CustomError>>
fn into_ast_node<'reg, 'orig, 'parse, 'inp: 'reg + 'orig>(
&'orig self,
registry: &'reg mut Registry<'orig, 'parse>,
) -> BoxFuture<'inp, Result<IAstNode, CustomError>>
where
Self: 'parse;
}
impl IntoIAstNode for organic::types::DocumentElement<'_> {
fn into_ast_node<'parse, 'b>(
&'b self,
registry: &'b mut Registry<'parse>,
) -> BoxFuture<'b, Result<IAstNode, CustomError>>
fn into_ast_node<'reg, 'orig, 'parse, 'inp: 'reg + 'orig>(
&'orig self,
registry: &'reg mut Registry<'orig, 'parse>,
) -> BoxFuture<'inp, Result<IAstNode, CustomError>>
where
Self: 'parse,
{
@ -144,10 +144,10 @@ impl IntoIAstNode for organic::types::DocumentElement<'_> {
}
impl IntoIAstNode for organic::types::Element<'_> {
fn into_ast_node<'parse, 'b>(
&'b self,
registry: &'b mut Registry<'parse>,
) -> BoxFuture<'b, Result<IAstNode, CustomError>>
fn into_ast_node<'reg, 'orig, 'parse, 'inp: 'reg + 'orig>(
&'orig self,
registry: &'reg mut Registry<'orig, 'parse>,
) -> BoxFuture<'inp, Result<IAstNode, CustomError>>
where
Self: 'parse,
{
@ -232,10 +232,10 @@ impl IntoIAstNode for organic::types::Element<'_> {
}
impl IntoIAstNode for organic::types::Object<'_> {
fn into_ast_node<'parse, 'b>(
&'b self,
registry: &'b mut Registry<'parse>,
) -> BoxFuture<'b, Result<IAstNode, CustomError>>
fn into_ast_node<'reg, 'orig, 'parse, 'inp: 'reg + 'orig>(
&'orig self,
registry: &'reg mut Registry<'orig, 'parse>,
) -> BoxFuture<'inp, Result<IAstNode, CustomError>>
where
Self: 'parse,
{

View File

@ -1,15 +1,5 @@
use super::macros::inoop;
use super::registry::Registry;
use crate::error::CustomError;
use super::registry::Registry;
#[derive(Debug, Clone)]
pub(crate) struct IBabelCall {}
impl IBabelCall {
pub(crate) async fn new<'b, 'parse>(
registry: &'b mut Registry<'parse>,
original: &'b organic::types::BabelCall<'parse>,
) -> Result<IBabelCall, CustomError> {
Ok(IBabelCall {})
}
}
inoop!(IBabelCall, BabelCall);

View File

@ -1,15 +1,5 @@
use super::macros::inoop;
use super::registry::Registry;
use crate::error::CustomError;
use super::registry::Registry;
#[derive(Debug, Clone)]
pub(crate) struct IBold {}
impl IBold {
pub(crate) async fn new<'b, 'parse>(
registry: &'b mut Registry<'parse>,
original: &'b organic::types::Bold<'parse>,
) -> Result<IBold, CustomError> {
Ok(IBold {})
}
}
inoop!(IBold, Bold);

View File

@ -1,15 +1,5 @@
use super::macros::inoop;
use super::registry::Registry;
use crate::error::CustomError;
use super::registry::Registry;
#[derive(Debug, Clone)]
pub(crate) struct ICenterBlock {}
impl ICenterBlock {
pub(crate) async fn new<'b, 'parse>(
registry: &'b mut Registry<'parse>,
original: &'b organic::types::CenterBlock<'parse>,
) -> Result<ICenterBlock, CustomError> {
Ok(ICenterBlock {})
}
}
inoop!(ICenterBlock, CenterBlock);

View File

@ -1,15 +1,5 @@
use super::macros::inoop;
use super::registry::Registry;
use crate::error::CustomError;
use super::registry::Registry;
#[derive(Debug, Clone)]
pub(crate) struct ICitation {}
impl ICitation {
pub(crate) async fn new<'b, 'parse>(
registry: &'b mut Registry<'parse>,
original: &'b organic::types::Citation<'parse>,
) -> Result<ICitation, CustomError> {
Ok(ICitation {})
}
}
inoop!(ICitation, Citation);

View File

@ -1,15 +1,5 @@
use super::macros::inoop;
use super::registry::Registry;
use crate::error::CustomError;
use super::registry::Registry;
#[derive(Debug, Clone)]
pub(crate) struct ICitationReference {}
impl ICitationReference {
pub(crate) async fn new<'b, 'parse>(
registry: &'b mut Registry<'parse>,
original: &'b organic::types::CitationReference<'parse>,
) -> Result<ICitationReference, CustomError> {
Ok(ICitationReference {})
}
}
inoop!(ICitationReference, CitationReference);

View File

@ -1,15 +1,5 @@
use super::macros::inoop;
use super::registry::Registry;
use crate::error::CustomError;
use super::registry::Registry;
#[derive(Debug, Clone)]
pub(crate) struct IClock {}
impl IClock {
pub(crate) async fn new<'b, 'parse>(
registry: &'b mut Registry<'parse>,
original: &'b organic::types::Clock<'parse>,
) -> Result<IClock, CustomError> {
Ok(IClock {})
}
}
inoop!(IClock, Clock);

View File

@ -1,15 +1,5 @@
use super::macros::inoop;
use super::registry::Registry;
use crate::error::CustomError;
use super::registry::Registry;
#[derive(Debug, Clone)]
pub(crate) struct ICode {}
impl ICode {
pub(crate) async fn new<'b, 'parse>(
registry: &'b mut Registry<'parse>,
original: &'b organic::types::Code<'parse>,
) -> Result<ICode, CustomError> {
Ok(ICode {})
}
}
inoop!(ICode, Code);

View File

@ -1,16 +1,5 @@
use super::macros::inoop;
use super::registry::Registry;
use crate::error::CustomError;
use super::registry::Registry;
/// Essentially a no-op since the comment is not rendered.
#[derive(Debug, Clone)]
pub(crate) struct IComment {}
impl IComment {
pub(crate) async fn new<'b, 'parse>(
registry: &'b mut Registry<'parse>,
comment: &'b organic::types::Comment<'parse>,
) -> Result<IComment, CustomError> {
Ok(IComment {})
}
}
inoop!(IComment, Comment);

View File

@ -1,15 +1,5 @@
use super::macros::inoop;
use super::registry::Registry;
use crate::error::CustomError;
use super::registry::Registry;
#[derive(Debug, Clone)]
pub(crate) struct ICommentBlock {}
impl ICommentBlock {
pub(crate) async fn new<'b, 'parse>(
registry: &'b mut Registry<'parse>,
original: &'b organic::types::CommentBlock<'parse>,
) -> Result<ICommentBlock, CustomError> {
Ok(ICommentBlock {})
}
}
inoop!(ICommentBlock, CommentBlock);

View File

@ -1,15 +1,5 @@
use super::macros::inoop;
use super::registry::Registry;
use crate::error::CustomError;
use super::registry::Registry;
#[derive(Debug, Clone)]
pub(crate) struct IDiarySexp {}
impl IDiarySexp {
pub(crate) async fn new<'b, 'parse>(
registry: &'b mut Registry<'parse>,
original: &'b organic::types::DiarySexp<'parse>,
) -> Result<IDiarySexp, CustomError> {
Ok(IDiarySexp {})
}
}
inoop!(IDiarySexp, DiarySexp);

View File

@ -1,8 +1,8 @@
use crate::error::CustomError;
use super::macros::iselector;
use super::registry::Registry;
use super::IHeading;
use super::ISection;
use crate::error::CustomError;
use futures::future::{BoxFuture, FutureExt};
#[derive(Debug, Clone)]
@ -11,21 +11,17 @@ pub(crate) enum IDocumentElement {
Section(ISection),
}
impl IDocumentElement {
pub(crate) fn new<'parse, 'b>(
registry: &'b mut Registry<'parse>,
original: &'b organic::types::DocumentElement<'parse>,
) -> BoxFuture<'b, Result<IDocumentElement, CustomError>> {
async move {
match original {
organic::types::DocumentElement::Heading(inner) => Ok(IDocumentElement::Heading(
IHeading::new(registry, inner).await?,
)),
organic::types::DocumentElement::Section(inner) => Ok(IDocumentElement::Section(
ISection::new(registry, inner).await?,
)),
}
iselector!(
IDocumentElement,
DocumentElement,
|registry, original| async {
match &original {
organic::types::DocumentElement::Heading(inner) => Ok(IDocumentElement::Heading(
IHeading::new(registry, inner).await?,
)),
organic::types::DocumentElement::Section(inner) => Ok(IDocumentElement::Section(
ISection::new(registry, inner).await?,
)),
}
.boxed()
}
}
);

View File

@ -1,15 +1,5 @@
use super::macros::inoop;
use super::registry::Registry;
use crate::error::CustomError;
use super::registry::Registry;
#[derive(Debug, Clone)]
pub(crate) struct IDrawer {}
impl IDrawer {
pub(crate) async fn new<'b, 'parse>(
registry: &'b mut Registry<'parse>,
original: &'b organic::types::Drawer<'parse>,
) -> Result<IDrawer, CustomError> {
Ok(IDrawer {})
}
}
inoop!(IDrawer, Drawer);

View File

@ -1,15 +1,5 @@
use super::macros::inoop;
use super::registry::Registry;
use crate::error::CustomError;
use super::registry::Registry;
#[derive(Debug, Clone)]
pub(crate) struct IDynamicBlock {}
impl IDynamicBlock {
pub(crate) async fn new<'b, 'parse>(
registry: &'b mut Registry<'parse>,
original: &'b organic::types::DynamicBlock<'parse>,
) -> Result<IDynamicBlock, CustomError> {
Ok(IDynamicBlock {})
}
}
inoop!(IDynamicBlock, DynamicBlock);

View File

@ -1,7 +1,6 @@
use crate::error::CustomError;
use super::comment::IComment;
use super::keyword::IKeyword;
use super::macros::iselector;
use super::registry::Registry;
use super::IBabelCall;
use super::ICenterBlock;
@ -16,6 +15,7 @@ use super::IFixedWidthArea;
use super::IFootnoteDefinition;
use super::IHorizontalRule;
use super::ILatexEnvironment;
use super::IObject;
use super::IParagraph;
use super::IPlainList;
use super::IPlanning;
@ -25,6 +25,7 @@ use super::ISpecialBlock;
use super::ISrcBlock;
use super::ITable;
use super::IVerseBlock;
use crate::error::CustomError;
use futures::future::{BoxFuture, FutureExt};
#[derive(Debug, Clone)]
@ -55,87 +56,79 @@ pub(crate) enum IElement {
LatexEnvironment(ILatexEnvironment),
}
impl IElement {
pub(crate) fn new<'parse, 'b>(
registry: &'b mut Registry<'parse>,
elem: &'b organic::types::Element<'parse>,
) -> BoxFuture<'b, Result<IElement, CustomError>> {
async move {
match elem {
organic::types::Element::Paragraph(inner) => {
Ok(IElement::Paragraph(IParagraph::new(registry, inner).await?))
}
organic::types::Element::PlainList(inner) => {
Ok(IElement::PlainList(IPlainList::new(registry, inner).await?))
}
organic::types::Element::CenterBlock(inner) => Ok(IElement::CenterBlock(
ICenterBlock::new(registry, inner).await?,
)),
organic::types::Element::QuoteBlock(inner) => Ok(IElement::QuoteBlock(
IQuoteBlock::new(registry, inner).await?,
)),
organic::types::Element::SpecialBlock(inner) => Ok(IElement::SpecialBlock(
ISpecialBlock::new(registry, inner).await?,
)),
organic::types::Element::DynamicBlock(inner) => Ok(IElement::DynamicBlock(
IDynamicBlock::new(registry, inner).await?,
)),
organic::types::Element::FootnoteDefinition(inner) => Ok(
IElement::FootnoteDefinition(IFootnoteDefinition::new(registry, inner).await?),
),
organic::types::Element::Comment(inner) => {
Ok(IElement::Comment(IComment::new(registry, inner).await?))
}
organic::types::Element::Drawer(inner) => {
Ok(IElement::Drawer(IDrawer::new(registry, inner).await?))
}
organic::types::Element::PropertyDrawer(inner) => Ok(IElement::PropertyDrawer(
IPropertyDrawer::new(registry, inner).await?,
)),
organic::types::Element::Table(inner) => {
Ok(IElement::Table(ITable::new(registry, inner).await?))
}
organic::types::Element::VerseBlock(inner) => Ok(IElement::VerseBlock(
IVerseBlock::new(registry, inner).await?,
)),
organic::types::Element::CommentBlock(inner) => Ok(IElement::CommentBlock(
ICommentBlock::new(registry, inner).await?,
)),
organic::types::Element::ExampleBlock(inner) => Ok(IElement::ExampleBlock(
IExampleBlock::new(registry, inner).await?,
)),
organic::types::Element::ExportBlock(inner) => Ok(IElement::ExportBlock(
IExportBlock::new(registry, inner).await?,
)),
organic::types::Element::SrcBlock(inner) => {
Ok(IElement::SrcBlock(ISrcBlock::new(registry, inner).await?))
}
organic::types::Element::Clock(inner) => {
Ok(IElement::Clock(IClock::new(registry, inner).await?))
}
organic::types::Element::DiarySexp(inner) => {
Ok(IElement::DiarySexp(IDiarySexp::new(registry, inner).await?))
}
organic::types::Element::Planning(inner) => {
Ok(IElement::Planning(IPlanning::new(registry, inner).await?))
}
organic::types::Element::FixedWidthArea(inner) => Ok(IElement::FixedWidthArea(
IFixedWidthArea::new(registry, inner).await?,
)),
organic::types::Element::HorizontalRule(inner) => Ok(IElement::HorizontalRule(
IHorizontalRule::new(registry, inner).await?,
)),
organic::types::Element::Keyword(inner) => {
Ok(IElement::Keyword(IKeyword::new(registry, inner).await?))
}
organic::types::Element::BabelCall(inner) => {
Ok(IElement::BabelCall(IBabelCall::new(registry, inner).await?))
}
organic::types::Element::LatexEnvironment(inner) => Ok(IElement::LatexEnvironment(
ILatexEnvironment::new(registry, inner).await?,
)),
}
iselector!(IElement, Element, |registry, elem| async {
match elem {
organic::types::Element::Paragraph(inner) => {
Ok(IElement::Paragraph(IParagraph::new(registry, inner).await?))
}
.boxed()
organic::types::Element::PlainList(inner) => {
Ok(IElement::PlainList(IPlainList::new(registry, inner).await?))
}
organic::types::Element::CenterBlock(inner) => Ok(IElement::CenterBlock(
ICenterBlock::new(registry, inner).await?,
)),
organic::types::Element::QuoteBlock(inner) => Ok(IElement::QuoteBlock(
IQuoteBlock::new(registry, inner).await?,
)),
organic::types::Element::SpecialBlock(inner) => Ok(IElement::SpecialBlock(
ISpecialBlock::new(registry, inner).await?,
)),
organic::types::Element::DynamicBlock(inner) => Ok(IElement::DynamicBlock(
IDynamicBlock::new(registry, inner).await?,
)),
organic::types::Element::FootnoteDefinition(inner) => Ok(IElement::FootnoteDefinition(
IFootnoteDefinition::new(registry, inner).await?,
)),
organic::types::Element::Comment(inner) => {
Ok(IElement::Comment(IComment::new(registry, inner).await?))
}
organic::types::Element::Drawer(inner) => {
Ok(IElement::Drawer(IDrawer::new(registry, inner).await?))
}
organic::types::Element::PropertyDrawer(inner) => Ok(IElement::PropertyDrawer(
IPropertyDrawer::new(registry, inner).await?,
)),
organic::types::Element::Table(inner) => {
Ok(IElement::Table(ITable::new(registry, inner).await?))
}
organic::types::Element::VerseBlock(inner) => Ok(IElement::VerseBlock(
IVerseBlock::new(registry, inner).await?,
)),
organic::types::Element::CommentBlock(inner) => Ok(IElement::CommentBlock(
ICommentBlock::new(registry, inner).await?,
)),
organic::types::Element::ExampleBlock(inner) => Ok(IElement::ExampleBlock(
IExampleBlock::new(registry, inner).await?,
)),
organic::types::Element::ExportBlock(inner) => Ok(IElement::ExportBlock(
IExportBlock::new(registry, inner).await?,
)),
organic::types::Element::SrcBlock(inner) => {
Ok(IElement::SrcBlock(ISrcBlock::new(registry, inner).await?))
}
organic::types::Element::Clock(inner) => {
Ok(IElement::Clock(IClock::new(registry, inner).await?))
}
organic::types::Element::DiarySexp(inner) => {
Ok(IElement::DiarySexp(IDiarySexp::new(registry, inner).await?))
}
organic::types::Element::Planning(inner) => {
Ok(IElement::Planning(IPlanning::new(registry, inner).await?))
}
organic::types::Element::FixedWidthArea(inner) => Ok(IElement::FixedWidthArea(
IFixedWidthArea::new(registry, inner).await?,
)),
organic::types::Element::HorizontalRule(inner) => Ok(IElement::HorizontalRule(
IHorizontalRule::new(registry, inner).await?,
)),
organic::types::Element::Keyword(inner) => {
Ok(IElement::Keyword(IKeyword::new(registry, inner).await?))
}
organic::types::Element::BabelCall(inner) => {
Ok(IElement::BabelCall(IBabelCall::new(registry, inner).await?))
}
organic::types::Element::LatexEnvironment(inner) => Ok(IElement::LatexEnvironment(
ILatexEnvironment::new(registry, inner).await?,
)),
}
}
});

View File

@ -1,19 +1,14 @@
use crate::error::CustomError;
use super::macros::intermediate;
use super::registry::Registry;
use crate::error::CustomError;
#[derive(Debug, Clone)]
pub(crate) struct IEntity {
pub(crate) html: String,
}
impl IEntity {
pub(crate) async fn new<'b, 'parse>(
registry: &'b mut Registry<'parse>,
original: &'b organic::types::Entity<'parse>,
) -> Result<IEntity, CustomError> {
Ok(IEntity {
html: original.html.to_owned(),
})
}
}
intermediate!(IEntity, Entity, |registry, original| async {
Ok(IEntity {
html: original.html.to_owned(),
})
});

View File

@ -1,15 +1,5 @@
use super::macros::inoop;
use super::registry::Registry;
use crate::error::CustomError;
use super::registry::Registry;
#[derive(Debug, Clone)]
pub(crate) struct IExampleBlock {}
impl IExampleBlock {
pub(crate) async fn new<'b, 'parse>(
registry: &'b mut Registry<'parse>,
original: &'b organic::types::ExampleBlock<'parse>,
) -> Result<IExampleBlock, CustomError> {
Ok(IExampleBlock {})
}
}
inoop!(IExampleBlock, ExampleBlock);

View File

@ -1,15 +1,5 @@
use super::macros::inoop;
use super::registry::Registry;
use crate::error::CustomError;
use super::registry::Registry;
#[derive(Debug, Clone)]
pub(crate) struct IExportBlock {}
impl IExportBlock {
pub(crate) async fn new<'b, 'parse>(
registry: &'b mut Registry<'parse>,
original: &'b organic::types::ExportBlock<'parse>,
) -> Result<IExportBlock, CustomError> {
Ok(IExportBlock {})
}
}
inoop!(IExportBlock, ExportBlock);

View File

@ -1,15 +1,5 @@
use super::macros::inoop;
use super::registry::Registry;
use crate::error::CustomError;
use super::registry::Registry;
#[derive(Debug, Clone)]
pub(crate) struct IExportSnippet {}
impl IExportSnippet {
pub(crate) async fn new<'b, 'parse>(
registry: &'b mut Registry<'parse>,
original: &'b organic::types::ExportSnippet<'parse>,
) -> Result<IExportSnippet, CustomError> {
Ok(IExportSnippet {})
}
}
inoop!(IExportSnippet, ExportSnippet);

View File

@ -1,15 +1,5 @@
use super::macros::inoop;
use super::registry::Registry;
use crate::error::CustomError;
use super::registry::Registry;
#[derive(Debug, Clone)]
pub(crate) struct IFixedWidthArea {}
impl IFixedWidthArea {
pub(crate) async fn new<'b, 'parse>(
registry: &'b mut Registry<'parse>,
original: &'b organic::types::FixedWidthArea<'parse>,
) -> Result<IFixedWidthArea, CustomError> {
Ok(IFixedWidthArea {})
}
}
inoop!(IFixedWidthArea, FixedWidthArea);

View File

@ -1,24 +1,21 @@
use crate::error::CustomError;
use super::ast_node::IAstNode;
use super::macros::intermediate;
use super::registry::Registry;
use super::IElement;
use super::IObject;
use super::IAstNode;
use crate::error::CustomError;
#[derive(Debug, Clone)]
pub(crate) struct IFootnoteDefinition {}
impl IFootnoteDefinition {
pub(crate) async fn new<'b, 'parse>(
registry: &'b mut Registry<'parse>,
original: &'b organic::types::FootnoteDefinition<'parse>,
) -> Result<IFootnoteDefinition, CustomError> {
intermediate!(
IFootnoteDefinition,
FootnoteDefinition,
|registry, original| async {
registry
.register_footnote_definition(original.label, &original.children)
.await?;
Ok(IFootnoteDefinition {})
}
}
);
#[derive(Debug)]
pub(crate) struct IRealFootnoteDefinition {
@ -27,8 +24,8 @@ pub(crate) struct IRealFootnoteDefinition {
}
impl IRealFootnoteDefinition {
pub(crate) async fn new<'b, 'parse>(
registry: &'b mut Registry<'parse>,
pub(crate) async fn new<'reg, 'orig, 'parse>(
registry: &'reg mut Registry<'orig, 'parse>,
footnote_id: usize,
contents: Vec<IAstNode>,
) -> Result<IRealFootnoteDefinition, CustomError> {

View File

@ -1,6 +1,6 @@
use crate::error::CustomError;
use super::macros::intermediate;
use super::registry::Registry;
use crate::error::CustomError;
#[derive(Debug, Clone)]
pub(crate) struct IFootnoteReference {
@ -8,11 +8,10 @@ pub(crate) struct IFootnoteReference {
duplicate_offset: usize,
}
impl IFootnoteReference {
pub(crate) async fn new<'b, 'parse>(
registry: &'b mut Registry<'parse>,
original: &'b organic::types::FootnoteReference<'parse>,
) -> Result<IFootnoteReference, CustomError> {
intermediate!(
IFootnoteReference,
FootnoteReference,
|registry, original| async {
let footnote_id = registry
.get_footnote_reference_id(original.label, &original.definition)
.await?;
@ -21,7 +20,9 @@ impl IFootnoteReference {
duplicate_offset: 0, // TODO
})
}
);
impl IFootnoteReference {
pub(crate) fn get_display_label(&self) -> String {
format!("{}", self.footnote_id + 1)
}

View File

@ -1,8 +1,8 @@
use crate::error::CustomError;
use super::macros::intermediate;
use super::registry::Registry;
use super::IDocumentElement;
use super::IObject;
use crate::error::CustomError;
#[derive(Debug, Clone)]
pub(crate) struct IHeading {
@ -11,29 +11,24 @@ pub(crate) struct IHeading {
pub(crate) children: Vec<IDocumentElement>,
}
impl IHeading {
pub(crate) async fn new<'b, 'parse>(
registry: &'b mut Registry<'parse>,
original: &'b organic::types::Heading<'parse>,
) -> Result<IHeading, CustomError> {
let title = {
let mut ret = Vec::new();
for obj in original.title.iter() {
ret.push(IObject::new(registry, obj).await?);
}
ret
};
let children = {
let mut ret = Vec::new();
for obj in original.children.iter() {
ret.push(IDocumentElement::new(registry, obj).await?);
}
ret
};
Ok(IHeading {
title,
level: original.level,
children,
})
}
}
intermediate!(IHeading, Heading, |registry, original| async {
let title = {
let mut ret = Vec::new();
for obj in original.title.iter() {
ret.push(IObject::new(registry, obj).await?);
}
ret
};
let children = {
let mut ret = Vec::new();
for obj in original.children.iter() {
ret.push(IDocumentElement::new(registry, obj).await?);
}
ret
};
Ok(IHeading {
title,
level: original.level,
children,
})
});

View File

@ -1,15 +1,5 @@
use super::macros::inoop;
use super::registry::Registry;
use crate::error::CustomError;
use super::registry::Registry;
#[derive(Debug, Clone)]
pub(crate) struct IHorizontalRule {}
impl IHorizontalRule {
pub(crate) async fn new<'b, 'parse>(
registry: &'b mut Registry<'parse>,
original: &'b organic::types::HorizontalRule<'parse>,
) -> Result<IHorizontalRule, CustomError> {
Ok(IHorizontalRule {})
}
}
inoop!(IHorizontalRule, HorizontalRule);

View File

@ -1,15 +1,5 @@
use super::macros::inoop;
use super::registry::Registry;
use crate::error::CustomError;
use super::registry::Registry;
#[derive(Debug, Clone)]
pub(crate) struct IInlineBabelCall {}
impl IInlineBabelCall {
pub(crate) async fn new<'b, 'parse>(
registry: &'b mut Registry<'parse>,
original: &'b organic::types::InlineBabelCall<'parse>,
) -> Result<IInlineBabelCall, CustomError> {
Ok(IInlineBabelCall {})
}
}
inoop!(IInlineBabelCall, InlineBabelCall);

View File

@ -1,19 +1,18 @@
use crate::error::CustomError;
use super::macros::intermediate;
use super::registry::Registry;
use crate::error::CustomError;
#[derive(Debug, Clone)]
pub(crate) struct IInlineSourceBlock {
pub(crate) value: String,
}
impl IInlineSourceBlock {
pub(crate) async fn new<'b, 'parse>(
registry: &'b mut Registry<'parse>,
original: &'b organic::types::InlineSourceBlock<'parse>,
) -> Result<IInlineSourceBlock, CustomError> {
intermediate!(
IInlineSourceBlock,
InlineSourceBlock,
|registry, original| async {
Ok(IInlineSourceBlock {
value: original.value.to_owned(),
})
}
}
);

View File

@ -1,15 +1,5 @@
use super::macros::inoop;
use super::registry::Registry;
use crate::error::CustomError;
use super::registry::Registry;
#[derive(Debug, Clone)]
pub(crate) struct IItalic {}
impl IItalic {
pub(crate) async fn new<'b, 'parse>(
registry: &'b mut Registry<'parse>,
original: &'b organic::types::Italic<'parse>,
) -> Result<IItalic, CustomError> {
Ok(IItalic {})
}
}
inoop!(IItalic, Italic);

View File

@ -1,16 +1,5 @@
use super::macros::inoop;
use super::registry::Registry;
use crate::error::CustomError;
use super::registry::Registry;
/// Essentially a no-op since the keyword is not rendered and any relevant impact on other elements is pulled from the parsed form of keyword.
#[derive(Debug, Clone)]
pub(crate) struct IKeyword {}
impl IKeyword {
pub(crate) async fn new<'b, 'parse>(
registry: &'b mut Registry<'parse>,
keyword: &'b organic::types::Keyword<'parse>,
) -> Result<IKeyword, CustomError> {
Ok(IKeyword {})
}
}
inoop!(IKeyword, Keyword);

View File

@ -1,15 +1,5 @@
use super::macros::inoop;
use super::registry::Registry;
use crate::error::CustomError;
use super::registry::Registry;
#[derive(Debug, Clone)]
pub(crate) struct ILatexEnvironment {}
impl ILatexEnvironment {
pub(crate) async fn new<'b, 'parse>(
registry: &'b mut Registry<'parse>,
original: &'b organic::types::LatexEnvironment<'parse>,
) -> Result<ILatexEnvironment, CustomError> {
Ok(ILatexEnvironment {})
}
}
inoop!(ILatexEnvironment, LatexEnvironment);

View File

@ -1,15 +1,5 @@
use super::macros::inoop;
use super::registry::Registry;
use crate::error::CustomError;
use super::registry::Registry;
#[derive(Debug, Clone)]
pub(crate) struct ILatexFragment {}
impl ILatexFragment {
pub(crate) async fn new<'b, 'parse>(
registry: &'b mut Registry<'parse>,
original: &'b organic::types::LatexFragment<'parse>,
) -> Result<ILatexFragment, CustomError> {
Ok(ILatexFragment {})
}
}
inoop!(ILatexFragment, LatexFragment);

View File

@ -1,15 +1,5 @@
use super::macros::inoop;
use super::registry::Registry;
use crate::error::CustomError;
use super::registry::Registry;
#[derive(Debug, Clone)]
pub(crate) struct ILineBreak {}
impl ILineBreak {
pub(crate) async fn new<'b, 'parse>(
registry: &'b mut Registry<'parse>,
original: &'b organic::types::LineBreak<'parse>,
) -> Result<ILineBreak, CustomError> {
Ok(ILineBreak {})
}
}
inoop!(ILineBreak, LineBreak);

View File

@ -0,0 +1,56 @@
/// Write the implementation for the intermediate ast node for a type that is a noop or is not yet implemented.
///
/// This exists to make changing the type signature easier.
macro_rules! inoop {
($istruct:ident, $pstruct:ident) => {
#[derive(Debug, Clone)]
pub(crate) struct $istruct {}
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> {
Ok($istruct {})
}
}
};
}
pub(crate) use inoop;
/// Write the implementation for the intermediate ast node.
///
/// This exists to make changing the type signature easier.
macro_rules! intermediate {
($istruct:ident, $pstruct:ident, $fnbody:expr) => {
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
}
}
};
}
pub(crate) use intermediate;
/// Write the implementation for the intermediate ast node.
///
/// This exists to make changing the type signature easier.
macro_rules! iselector {
($istruct:ident, $pstruct:ident, $fnbody:expr) => {
impl $istruct {
pub(crate) fn new<'reg, 'orig, 'parse, 'inp: 'reg + 'orig>(
registry: &'reg mut Registry<'orig, 'parse>,
original: &'orig organic::types::$pstruct<'parse>,
) -> BoxFuture<'inp, Result<$istruct, CustomError>> {
$fnbody(registry, original).boxed()
}
}
};
}
pub(crate) use iselector;

View File

@ -32,6 +32,7 @@ mod keyword;
mod latex_environment;
mod latex_fragment;
mod line_break;
mod macros;
mod object;
mod org_macro;
mod page;

View File

@ -13,6 +13,7 @@ use super::inline_source_block::IInlineSourceBlock;
use super::italic::IItalic;
use super::latex_fragment::ILatexFragment;
use super::line_break::ILineBreak;
use super::macros::iselector;
use super::org_macro::IOrgMacro;
use super::plain_link::IPlainLink;
use super::plain_text::IPlainText;
@ -61,96 +62,88 @@ pub(crate) enum IObject {
Timestamp(ITimestamp),
}
impl IObject {
pub(crate) fn new<'parse, 'b>(
registry: &'b mut Registry<'parse>,
obj: &'b organic::types::Object<'parse>,
) -> BoxFuture<'b, Result<IObject, CustomError>> {
async move {
match obj {
organic::types::Object::Bold(inner) => {
Ok(IObject::Bold(IBold::new(registry, inner).await?))
}
organic::types::Object::Italic(inner) => {
Ok(IObject::Italic(IItalic::new(registry, inner).await?))
}
organic::types::Object::Underline(inner) => {
Ok(IObject::Underline(IUnderline::new(registry, inner).await?))
}
organic::types::Object::StrikeThrough(inner) => Ok(IObject::StrikeThrough(
IStrikeThrough::new(registry, inner).await?,
)),
organic::types::Object::Code(inner) => {
Ok(IObject::Code(ICode::new(registry, inner).await?))
}
organic::types::Object::Verbatim(inner) => {
Ok(IObject::Verbatim(IVerbatim::new(registry, inner).await?))
}
organic::types::Object::PlainText(inner) => {
Ok(IObject::PlainText(IPlainText::new(registry, inner).await?))
}
organic::types::Object::RegularLink(inner) => Ok(IObject::RegularLink(
IRegularLink::new(registry, inner).await?,
)),
organic::types::Object::RadioLink(inner) => {
Ok(IObject::RadioLink(IRadioLink::new(registry, inner).await?))
}
organic::types::Object::RadioTarget(inner) => Ok(IObject::RadioTarget(
IRadioTarget::new(registry, inner).await?,
)),
organic::types::Object::PlainLink(inner) => {
Ok(IObject::PlainLink(IPlainLink::new(registry, inner).await?))
}
organic::types::Object::AngleLink(inner) => {
Ok(IObject::AngleLink(IAngleLink::new(registry, inner).await?))
}
organic::types::Object::OrgMacro(inner) => {
Ok(IObject::OrgMacro(IOrgMacro::new(registry, inner).await?))
}
organic::types::Object::Entity(inner) => {
Ok(IObject::Entity(IEntity::new(registry, inner).await?))
}
organic::types::Object::LatexFragment(inner) => Ok(IObject::LatexFragment(
ILatexFragment::new(registry, inner).await?,
)),
organic::types::Object::ExportSnippet(inner) => Ok(IObject::ExportSnippet(
IExportSnippet::new(registry, inner).await?,
)),
organic::types::Object::FootnoteReference(inner) => Ok(IObject::FootnoteReference(
IFootnoteReference::new(registry, inner).await?,
)),
organic::types::Object::Citation(inner) => {
Ok(IObject::Citation(ICitation::new(registry, inner).await?))
}
organic::types::Object::CitationReference(inner) => Ok(IObject::CitationReference(
ICitationReference::new(registry, inner).await?,
)),
organic::types::Object::InlineBabelCall(inner) => Ok(IObject::InlineBabelCall(
IInlineBabelCall::new(registry, inner).await?,
)),
organic::types::Object::InlineSourceBlock(inner) => Ok(IObject::InlineSourceBlock(
IInlineSourceBlock::new(registry, inner).await?,
)),
organic::types::Object::LineBreak(inner) => {
Ok(IObject::LineBreak(ILineBreak::new(registry, inner).await?))
}
organic::types::Object::Target(inner) => {
Ok(IObject::Target(ITarget::new(registry, inner).await?))
}
organic::types::Object::StatisticsCookie(inner) => Ok(IObject::StatisticsCookie(
IStatisticsCookie::new(registry, inner).await?,
)),
organic::types::Object::Subscript(inner) => {
Ok(IObject::Subscript(ISubscript::new(registry, inner).await?))
}
organic::types::Object::Superscript(inner) => Ok(IObject::Superscript(
ISuperscript::new(registry, inner).await?,
)),
organic::types::Object::Timestamp(inner) => {
Ok(IObject::Timestamp(ITimestamp::new(registry, inner).await?))
}
}
iselector!(IObject, Object, |registry, obj| async {
match &obj {
organic::types::Object::Bold(inner) => {
Ok(IObject::Bold(IBold::new(registry, inner).await?))
}
organic::types::Object::Italic(inner) => {
Ok(IObject::Italic(IItalic::new(registry, inner).await?))
}
organic::types::Object::Underline(inner) => {
Ok(IObject::Underline(IUnderline::new(registry, inner).await?))
}
organic::types::Object::StrikeThrough(inner) => Ok(IObject::StrikeThrough(
IStrikeThrough::new(registry, inner).await?,
)),
organic::types::Object::Code(inner) => {
Ok(IObject::Code(ICode::new(registry, inner).await?))
}
organic::types::Object::Verbatim(inner) => {
Ok(IObject::Verbatim(IVerbatim::new(registry, inner).await?))
}
organic::types::Object::PlainText(inner) => {
Ok(IObject::PlainText(IPlainText::new(registry, inner).await?))
}
organic::types::Object::RegularLink(inner) => Ok(IObject::RegularLink(
IRegularLink::new(registry, inner).await?,
)),
organic::types::Object::RadioLink(inner) => {
Ok(IObject::RadioLink(IRadioLink::new(registry, inner).await?))
}
organic::types::Object::RadioTarget(inner) => Ok(IObject::RadioTarget(
IRadioTarget::new(registry, inner).await?,
)),
organic::types::Object::PlainLink(inner) => {
Ok(IObject::PlainLink(IPlainLink::new(registry, inner).await?))
}
organic::types::Object::AngleLink(inner) => {
Ok(IObject::AngleLink(IAngleLink::new(registry, inner).await?))
}
organic::types::Object::OrgMacro(inner) => {
Ok(IObject::OrgMacro(IOrgMacro::new(registry, inner).await?))
}
organic::types::Object::Entity(inner) => {
Ok(IObject::Entity(IEntity::new(registry, inner).await?))
}
organic::types::Object::LatexFragment(inner) => Ok(IObject::LatexFragment(
ILatexFragment::new(registry, inner).await?,
)),
organic::types::Object::ExportSnippet(inner) => Ok(IObject::ExportSnippet(
IExportSnippet::new(registry, inner).await?,
)),
organic::types::Object::FootnoteReference(inner) => Ok(IObject::FootnoteReference(
IFootnoteReference::new(registry, inner).await?,
)),
organic::types::Object::Citation(inner) => {
Ok(IObject::Citation(ICitation::new(registry, inner).await?))
}
organic::types::Object::CitationReference(inner) => Ok(IObject::CitationReference(
ICitationReference::new(registry, inner).await?,
)),
organic::types::Object::InlineBabelCall(inner) => Ok(IObject::InlineBabelCall(
IInlineBabelCall::new(registry, inner).await?,
)),
organic::types::Object::InlineSourceBlock(inner) => Ok(IObject::InlineSourceBlock(
IInlineSourceBlock::new(registry, inner).await?,
)),
organic::types::Object::LineBreak(inner) => {
Ok(IObject::LineBreak(ILineBreak::new(registry, inner).await?))
}
organic::types::Object::Target(inner) => {
Ok(IObject::Target(ITarget::new(registry, inner).await?))
}
organic::types::Object::StatisticsCookie(inner) => Ok(IObject::StatisticsCookie(
IStatisticsCookie::new(registry, inner).await?,
)),
organic::types::Object::Subscript(inner) => {
Ok(IObject::Subscript(ISubscript::new(registry, inner).await?))
}
organic::types::Object::Superscript(inner) => Ok(IObject::Superscript(
ISuperscript::new(registry, inner).await?,
)),
organic::types::Object::Timestamp(inner) => {
Ok(IObject::Timestamp(ITimestamp::new(registry, inner).await?))
}
.boxed()
}
}
});

View File

@ -1,15 +1,5 @@
use super::macros::inoop;
use super::registry::Registry;
use crate::error::CustomError;
use super::registry::Registry;
#[derive(Debug, Clone)]
pub(crate) struct IOrgMacro {}
impl IOrgMacro {
pub(crate) async fn new<'b, 'parse>(
registry: &'b mut Registry<'parse>,
original: &'b organic::types::OrgMacro<'parse>,
) -> Result<IOrgMacro, CustomError> {
Ok(IOrgMacro {})
}
}
inoop!(IOrgMacro, OrgMacro);

View File

@ -21,9 +21,10 @@ pub(crate) struct BlogPostPage {
}
impl BlogPostPage {
pub(crate) async fn new<'b, 'parse, P: Into<PathBuf>>(
// TODO: Move path into the registry so I can give this a standard interface like the others.
pub(crate) async fn new<'a, 'b, 'parse, P: Into<PathBuf>>(
path: P,
registry: &'b mut Registry<'parse>,
registry: &'a mut Registry<'b, 'parse>,
document: &'b organic::types::Document<'parse>,
) -> Result<BlogPostPage, CustomError> {
let path = path.into();

View File

@ -1,26 +1,21 @@
use crate::error::CustomError;
use super::macros::intermediate;
use super::registry::Registry;
use super::IObject;
use crate::error::CustomError;
#[derive(Debug, Clone)]
pub(crate) struct IParagraph {
pub(crate) children: Vec<IObject>,
}
impl IParagraph {
pub(crate) async fn new<'b, 'parse>(
registry: &'b mut Registry<'parse>,
original: &'b organic::types::Paragraph<'parse>,
) -> Result<IParagraph, CustomError> {
let children = {
let mut ret = Vec::new();
for obj in original.children.iter() {
ret.push(IObject::new(registry, obj).await?);
}
ret
};
intermediate!(IParagraph, Paragraph, |registry, original| async {
let children = {
let mut ret = Vec::new();
for obj in original.children.iter() {
ret.push(IObject::new(registry, obj).await?);
}
ret
};
Ok(IParagraph { children })
}
}
Ok(IParagraph { children })
});

View File

@ -1,15 +1,5 @@
use super::macros::inoop;
use super::registry::Registry;
use crate::error::CustomError;
use super::registry::Registry;
#[derive(Debug, Clone)]
pub(crate) struct IPlainLink {}
impl IPlainLink {
pub(crate) async fn new<'b, 'parse>(
registry: &'b mut Registry<'parse>,
original: &'b organic::types::PlainLink<'parse>,
) -> Result<IPlainLink, CustomError> {
Ok(IPlainLink {})
}
}
inoop!(IPlainLink, PlainLink);

View File

@ -1,7 +1,7 @@
use crate::error::CustomError;
use super::macros::intermediate;
use super::registry::Registry;
use super::IPlainListItem;
use crate::error::CustomError;
#[derive(Debug, Clone)]
pub(crate) struct IPlainList {
@ -9,22 +9,17 @@ pub(crate) struct IPlainList {
pub(crate) children: Vec<IPlainListItem>,
}
impl IPlainList {
pub(crate) async fn new<'b, 'parse>(
registry: &'b mut Registry<'parse>,
original: &'b organic::types::PlainList<'parse>,
) -> Result<IPlainList, CustomError> {
let children = {
let mut ret = Vec::new();
for obj in original.children.iter() {
ret.push(IPlainListItem::new(registry, obj).await?);
}
ret
};
intermediate!(IPlainList, PlainList, |registry, original| async {
let children = {
let mut ret = Vec::new();
for obj in original.children.iter() {
ret.push(IPlainListItem::new(registry, obj).await?);
}
ret
};
Ok(IPlainList {
list_type: original.list_type,
children,
})
}
}
Ok(IPlainList {
list_type: original.list_type,
children,
})
});

View File

@ -1,8 +1,8 @@
use crate::error::CustomError;
use super::macros::intermediate;
use super::registry::Registry;
use super::IElement;
use super::IObject;
use crate::error::CustomError;
#[derive(Debug, Clone)]
pub(crate) struct IPlainListItem {
@ -10,27 +10,22 @@ pub(crate) struct IPlainListItem {
pub(crate) children: Vec<IElement>,
}
impl IPlainListItem {
pub(crate) async fn new<'b, 'parse>(
registry: &'b mut Registry<'parse>,
original: &'b organic::types::PlainListItem<'parse>,
) -> Result<IPlainListItem, CustomError> {
let tag = {
let mut ret = Vec::new();
for obj in original.tag.iter() {
ret.push(IObject::new(registry, obj).await?);
}
ret
};
intermediate!(IPlainListItem, PlainListItem, |registry, original| async {
let tag = {
let mut ret = Vec::new();
for obj in original.tag.iter() {
ret.push(IObject::new(registry, obj).await?);
}
ret
};
let children = {
let mut ret = Vec::new();
for elem in original.children.iter() {
ret.push(IElement::new(registry, elem).await?);
}
ret
};
let children = {
let mut ret = Vec::new();
for elem in original.children.iter() {
ret.push(IElement::new(registry, elem).await?);
}
ret
};
Ok(IPlainListItem { tag, children })
}
}
Ok(IPlainListItem { tag, children })
});

View File

@ -1,20 +1,15 @@
use crate::error::CustomError;
use crate::intermediate::util::coalesce_whitespace;
use super::macros::intermediate;
use super::registry::Registry;
use super::util::coalesce_whitespace;
use crate::error::CustomError;
#[derive(Debug, Clone)]
pub(crate) struct IPlainText {
pub(crate) source: String,
}
impl IPlainText {
pub(crate) async fn new<'b, 'parse>(
registry: &'b mut Registry<'parse>,
plain_text: &'b organic::types::PlainText<'parse>,
) -> Result<IPlainText, CustomError> {
Ok(IPlainText {
source: coalesce_whitespace(plain_text.source).into_owned(),
})
}
}
intermediate!(IPlainText, PlainText, |registry, original| async {
Ok(IPlainText {
source: coalesce_whitespace(original.source).into_owned(),
})
});

View File

@ -1,15 +1,5 @@
use super::macros::inoop;
use super::registry::Registry;
use crate::error::CustomError;
use super::registry::Registry;
#[derive(Debug, Clone)]
pub(crate) struct IPlanning {}
impl IPlanning {
pub(crate) async fn new<'b, 'parse>(
registry: &'b mut Registry<'parse>,
original: &'b organic::types::Planning<'parse>,
) -> Result<IPlanning, CustomError> {
Ok(IPlanning {})
}
}
inoop!(IPlanning, Planning);

View File

@ -1,15 +1,5 @@
use super::macros::inoop;
use super::registry::Registry;
use crate::error::CustomError;
use super::registry::Registry;
#[derive(Debug, Clone)]
pub(crate) struct IPropertyDrawer {}
impl IPropertyDrawer {
pub(crate) async fn new<'b, 'parse>(
registry: &'b mut Registry<'parse>,
original: &'b organic::types::PropertyDrawer<'parse>,
) -> Result<IPropertyDrawer, CustomError> {
Ok(IPropertyDrawer {})
}
}
inoop!(IPropertyDrawer, PropertyDrawer);

View File

@ -1,26 +1,21 @@
use crate::error::CustomError;
use super::macros::intermediate;
use super::registry::Registry;
use super::IElement;
use crate::error::CustomError;
#[derive(Debug, Clone)]
pub(crate) struct IQuoteBlock {
pub(crate) children: Vec<IElement>,
}
impl IQuoteBlock {
pub(crate) async fn new<'b, 'parse>(
registry: &'b mut Registry<'parse>,
original: &'b organic::types::QuoteBlock<'parse>,
) -> Result<IQuoteBlock, CustomError> {
let children = {
let mut ret = Vec::new();
for obj in original.children.iter() {
ret.push(IElement::new(registry, obj).await?);
}
ret
};
intermediate!(IQuoteBlock, QuoteBlock, |registry, original| async {
let children = {
let mut ret = Vec::new();
for obj in original.children.iter() {
ret.push(IElement::new(registry, obj).await?);
}
ret
};
Ok(IQuoteBlock { children })
}
}
Ok(IQuoteBlock { children })
});

View File

@ -1,15 +1,5 @@
use super::macros::inoop;
use super::registry::Registry;
use crate::error::CustomError;
use super::registry::Registry;
#[derive(Debug, Clone)]
pub(crate) struct IRadioLink {}
impl IRadioLink {
pub(crate) async fn new<'b, 'parse>(
registry: &'b mut Registry<'parse>,
original: &'b organic::types::RadioLink<'parse>,
) -> Result<IRadioLink, CustomError> {
Ok(IRadioLink {})
}
}
inoop!(IRadioLink, RadioLink);

View File

@ -1,15 +1,5 @@
use super::macros::inoop;
use super::registry::Registry;
use crate::error::CustomError;
use super::registry::Registry;
#[derive(Debug, Clone)]
pub(crate) struct IRadioTarget {}
impl IRadioTarget {
pub(crate) async fn new<'b, 'parse>(
registry: &'b mut Registry<'parse>,
original: &'b organic::types::RadioTarget<'parse>,
) -> Result<IRadioTarget, CustomError> {
Ok(IRadioTarget {})
}
}
inoop!(IRadioTarget, RadioTarget);

View File

@ -9,14 +9,17 @@ use super::ast_node::IAstNode;
type IdCounter = u16;
pub(crate) struct Registry<'parse> {
pub(crate) struct Registry<'orig, 'parse> {
id_counter: IdCounter,
targets: HashMap<&'parse str, String>,
footnote_ids: Vec<(Option<&'parse str>, Vec<IAstNode>)>,
footnote_ids: Vec<(
Option<&'parse str>,
FootnoteDefinitionContents<'orig, 'parse>,
)>,
}
impl<'parse> Registry<'parse> {
pub(crate) fn new() -> Registry<'parse> {
impl<'orig, 'parse> Registry<'orig, 'parse> {
pub(crate) fn new() -> Registry<'orig, 'parse> {
Registry {
id_counter: 0,
targets: HashMap::new(),
@ -24,7 +27,7 @@ impl<'parse> Registry<'parse> {
}
}
pub(crate) fn get_target<'b>(&'b mut self, body: &'parse str) -> &'b String {
pub(crate) fn get_target<'reg>(&'reg mut self, body: &'parse str) -> &'reg String {
self.targets.entry(body).or_insert_with(|| {
self.id_counter += 1;
format!("target_{}", self.id_counter)
@ -32,19 +35,21 @@ impl<'parse> Registry<'parse> {
}
pub(crate) fn get_footnote_ids(&self) -> impl Iterator<Item = (usize, &Vec<IAstNode>)> {
self.footnote_ids
.iter()
.map(|(_label, definition)| definition)
.enumerate()
// TODO
std::iter::empty()
// self.footnote_ids
// .iter()
// .map(|(_label, definition)| definition)
// .enumerate()
}
/// Get a 0-indexed ID for a footnote.
///
/// This needs to be incremented to be 1-indexed for render.
pub(crate) async fn get_footnote_reference_id<'b>(
&'b mut self,
pub(crate) async fn get_footnote_reference_id<'reg>(
&'reg mut self,
label: Option<&'parse str>,
definition: &'b Vec<Object<'parse>>,
definition: &'orig Vec<Object<'parse>>,
) -> Result<usize, CustomError> {
if let None = label {
// If it has no label then it must always get a new ID.
@ -75,10 +80,10 @@ impl<'parse> Registry<'parse> {
}
/// Update the definition to a footnote but do not mark it as referenced.
pub(crate) async fn register_footnote_definition<'b>(
&'b mut self,
pub(crate) async fn register_footnote_definition<'reg>(
&'reg mut self,
label: &'parse str,
definition: &'b Vec<Element<'parse>>,
definition: &'orig Vec<Element<'parse>>,
) -> Result<(), CustomError> {
let contents = convert_definition_contents(self, definition).await?;
if let Some((_existing_id, existing_definition)) = self
@ -92,9 +97,9 @@ impl<'parse> Registry<'parse> {
}
}
async fn convert_reference_contents<'b, 'parse>(
registry: &'b mut Registry<'parse>,
contents: &'b Vec<Object<'parse>>,
async fn convert_reference_contents<'reg, 'orig, 'parse>(
registry: &'reg mut Registry<'orig, 'parse>,
contents: &'orig Vec<Object<'parse>>,
) -> Result<Vec<IAstNode>, CustomError> {
let contents = {
let mut ret = Vec::new();
@ -107,9 +112,9 @@ async fn convert_reference_contents<'b, 'parse>(
Ok(contents)
}
async fn convert_definition_contents<'b, 'parse>(
registry: &'b mut Registry<'parse>,
contents: &'b Vec<Element<'parse>>,
async fn convert_definition_contents<'reg, 'orig, 'parse>(
registry: &'reg mut Registry<'orig, 'parse>,
contents: &'orig Vec<Element<'parse>>,
) -> Result<Vec<IAstNode>, CustomError> {
let contents = {
let mut ret = Vec::new();
@ -121,3 +126,8 @@ async fn convert_definition_contents<'b, 'parse>(
Ok(contents)
}
enum FootnoteDefinitionContents<'orig, 'parse> {
FromReference(&'orig Vec<Object<'parse>>),
FromDefinition(&'orig Vec<Object<'parse>>),
}

View File

@ -1,7 +1,7 @@
use crate::error::CustomError;
use super::macros::intermediate;
use super::registry::Registry;
use super::IObject;
use crate::error::CustomError;
#[derive(Debug, Clone)]
pub(crate) struct IRegularLink {
@ -9,21 +9,16 @@ pub(crate) struct IRegularLink {
pub(crate) children: Vec<IObject>,
}
impl IRegularLink {
pub(crate) async fn new<'b, 'parse>(
registry: &'b mut Registry<'parse>,
original: &'b organic::types::RegularLink<'parse>,
) -> Result<IRegularLink, CustomError> {
let children = {
let mut ret = Vec::new();
for obj in original.children.iter() {
ret.push(IObject::new(registry, obj).await?);
}
ret
};
Ok(IRegularLink {
raw_link: original.get_raw_link().into_owned(),
children,
})
}
}
intermediate!(IRegularLink, RegularLink, |registry, original| async {
let children = {
let mut ret = Vec::new();
for obj in original.children.iter() {
ret.push(IObject::new(registry, obj).await?);
}
ret
};
Ok(IRegularLink {
raw_link: original.get_raw_link().into_owned(),
children,
})
});

View File

@ -1,26 +1,21 @@
use crate::error::CustomError;
use super::macros::intermediate;
use super::registry::Registry;
use super::IElement;
use crate::error::CustomError;
#[derive(Debug, Clone)]
pub(crate) struct ISection {
pub(crate) children: Vec<IElement>,
}
impl ISection {
pub(crate) async fn new<'b, 'parse>(
registry: &'b mut Registry<'parse>,
section: &'b organic::types::Section<'parse>,
) -> Result<ISection, CustomError> {
let children = {
let mut ret = Vec::new();
for elem in section.children.iter() {
ret.push(IElement::new(registry, elem).await?);
}
ret
};
intermediate!(ISection, Section, |registry, original| async {
let children = {
let mut ret = Vec::new();
for elem in original.children.iter() {
ret.push(IElement::new(registry, elem).await?);
}
ret
};
Ok(ISection { children })
}
}
Ok(ISection { children })
});

View File

@ -1,15 +1,5 @@
use super::macros::inoop;
use super::registry::Registry;
use crate::error::CustomError;
use super::registry::Registry;
#[derive(Debug, Clone)]
pub(crate) struct ISpecialBlock {}
impl ISpecialBlock {
pub(crate) async fn new<'b, 'parse>(
registry: &'b mut Registry<'parse>,
original: &'b organic::types::SpecialBlock<'parse>,
) -> Result<ISpecialBlock, CustomError> {
Ok(ISpecialBlock {})
}
}
inoop!(ISpecialBlock, SpecialBlock);

View File

@ -1,22 +1,17 @@
use crate::error::CustomError;
use super::macros::intermediate;
use super::registry::Registry;
use crate::error::CustomError;
#[derive(Debug, Clone)]
pub(crate) struct ISrcBlock {
pub(crate) lines: Vec<String>,
}
impl ISrcBlock {
pub(crate) async fn new<'b, 'parse>(
registry: &'b mut Registry<'parse>,
original: &'b organic::types::SrcBlock<'parse>,
) -> Result<ISrcBlock, CustomError> {
let lines = original
.contents
.split_inclusive('\n')
.map(|s| s.to_owned())
.collect();
Ok(ISrcBlock { lines })
}
}
intermediate!(ISrcBlock, SrcBlock, |registry, original| async {
let lines = original
.contents
.split_inclusive('\n')
.map(|s| s.to_owned())
.collect();
Ok(ISrcBlock { lines })
});

View File

@ -1,15 +1,5 @@
use super::macros::inoop;
use super::registry::Registry;
use crate::error::CustomError;
use super::registry::Registry;
#[derive(Debug, Clone)]
pub(crate) struct IStatisticsCookie {}
impl IStatisticsCookie {
pub(crate) async fn new<'b, 'parse>(
registry: &'b mut Registry<'parse>,
original: &'b organic::types::StatisticsCookie<'parse>,
) -> Result<IStatisticsCookie, CustomError> {
Ok(IStatisticsCookie {})
}
}
inoop!(IStatisticsCookie, StatisticsCookie);

View File

@ -1,15 +1,5 @@
use super::macros::inoop;
use super::registry::Registry;
use crate::error::CustomError;
use super::registry::Registry;
#[derive(Debug, Clone)]
pub(crate) struct IStrikeThrough {}
impl IStrikeThrough {
pub(crate) async fn new<'b, 'parse>(
registry: &'b mut Registry<'parse>,
original: &'b organic::types::StrikeThrough<'parse>,
) -> Result<IStrikeThrough, CustomError> {
Ok(IStrikeThrough {})
}
}
inoop!(IStrikeThrough, StrikeThrough);

View File

@ -1,15 +1,5 @@
use super::macros::inoop;
use super::registry::Registry;
use crate::error::CustomError;
use super::registry::Registry;
#[derive(Debug, Clone)]
pub(crate) struct ISubscript {}
impl ISubscript {
pub(crate) async fn new<'b, 'parse>(
registry: &'b mut Registry<'parse>,
original: &'b organic::types::Subscript<'parse>,
) -> Result<ISubscript, CustomError> {
Ok(ISubscript {})
}
}
inoop!(ISubscript, Subscript);

View File

@ -1,15 +1,5 @@
use super::macros::inoop;
use super::registry::Registry;
use crate::error::CustomError;
use super::registry::Registry;
#[derive(Debug, Clone)]
pub(crate) struct ISuperscript {}
impl ISuperscript {
pub(crate) async fn new<'b, 'parse>(
registry: &'b mut Registry<'parse>,
original: &'b organic::types::Superscript<'parse>,
) -> Result<ISuperscript, CustomError> {
Ok(ISuperscript {})
}
}
inoop!(ISuperscript, Superscript);

View File

@ -1,15 +1,5 @@
use super::macros::inoop;
use super::registry::Registry;
use crate::error::CustomError;
use super::registry::Registry;
#[derive(Debug, Clone)]
pub(crate) struct ITable {}
impl ITable {
pub(crate) async fn new<'b, 'parse>(
registry: &'b mut Registry<'parse>,
original: &'b organic::types::Table<'parse>,
) -> Result<ITable, CustomError> {
Ok(ITable {})
}
}
inoop!(ITable, Table);

View File

@ -1,7 +1,6 @@
use crate::error::CustomError;
use crate::intermediate::util::coalesce_whitespace;
use super::macros::intermediate;
use super::registry::Registry;
use crate::error::CustomError;
#[derive(Debug, Clone)]
pub(crate) struct ITarget {
@ -9,15 +8,10 @@ pub(crate) struct ITarget {
value: String,
}
impl ITarget {
pub(crate) async fn new<'b, 'parse>(
registry: &'b mut Registry<'parse>,
target: &'b organic::types::Target<'parse>,
) -> Result<ITarget, CustomError> {
let id = registry.get_target(target.value);
Ok(ITarget {
id: id.clone(),
value: target.value.to_owned(),
})
}
}
intermediate!(ITarget, Target, |registry, original| async {
let id = registry.get_target(original.value);
Ok(ITarget {
id: id.clone(),
value: original.value.to_owned(),
})
});

View File

@ -1,15 +1,6 @@
use crate::error::CustomError;
use super::macros::inoop;
use super::registry::Registry;
#[derive(Debug, Clone)]
pub(crate) struct ITimestamp {}
impl ITimestamp {
pub(crate) async fn new<'b, 'parse>(
registry: &'b mut Registry<'parse>,
original: &'b organic::types::Timestamp<'parse>,
) -> Result<ITimestamp, CustomError> {
Ok(ITimestamp {})
}
}
inoop!(ITimestamp, Timestamp);

View File

@ -1,15 +1,6 @@
use crate::error::CustomError;
use super::macros::inoop;
use super::registry::Registry;
#[derive(Debug, Clone)]
pub(crate) struct IUnderline {}
impl IUnderline {
pub(crate) async fn new<'b, 'parse>(
registry: &'b mut Registry<'parse>,
original: &'b organic::types::Underline<'parse>,
) -> Result<IUnderline, CustomError> {
Ok(IUnderline {})
}
}
inoop!(IUnderline, Underline);

View File

@ -1,15 +1,6 @@
use crate::error::CustomError;
use super::macros::inoop;
use super::registry::Registry;
#[derive(Debug, Clone)]
pub(crate) struct IVerbatim {}
impl IVerbatim {
pub(crate) async fn new<'b, 'parse>(
registry: &'b mut Registry<'parse>,
original: &'b organic::types::Verbatim<'parse>,
) -> Result<IVerbatim, CustomError> {
Ok(IVerbatim {})
}
}
inoop!(IVerbatim, Verbatim);

View File

@ -1,15 +1,6 @@
use crate::error::CustomError;
use super::macros::inoop;
use super::registry::Registry;
#[derive(Debug, Clone)]
pub(crate) struct IVerseBlock {}
impl IVerseBlock {
pub(crate) async fn new<'b, 'parse>(
registry: &'b mut Registry<'parse>,
original: &'b organic::types::VerseBlock<'parse>,
) -> Result<IVerseBlock, CustomError> {
Ok(IVerseBlock {})
}
}
inoop!(IVerseBlock, VerseBlock);