Remove intermediate lifetime.

This commit is contained in:
Tom Alexander 2023-10-29 14:14:10 -04:00
parent 6109902945
commit 645ae26701
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE
60 changed files with 266 additions and 249 deletions

View File

@ -6,9 +6,9 @@ use super::registry::Registry;
pub(crate) struct IAngleLink {} pub(crate) struct IAngleLink {}
impl IAngleLink { impl IAngleLink {
pub(crate) async fn new<'intermediate, 'parse>( pub(crate) async fn new<'b, 'parse>(
registry: &mut Registry<'intermediate, 'parse>, registry: &'b mut Registry<'parse>,
original: &organic::types::AngleLink<'parse>, original: &'b organic::types::AngleLink<'parse>,
) -> Result<IAngleLink, CustomError> { ) -> Result<IAngleLink, CustomError> {
Ok(IAngleLink {}) Ok(IAngleLink {})
} }

View File

@ -112,20 +112,23 @@ pub(crate) enum IAstNode {
Timestamp(ITimestamp), Timestamp(ITimestamp),
} }
trait IntoIAstNode<'intermediate, 'parse> { pub(crate) trait IntoIAstNode {
fn new<'b>( fn into_ast_node<'parse, 'b>(
&'intermediate self, &'b self,
registry: &'b mut Registry<'intermediate, 'parse>, registry: &'b mut Registry<'parse>,
) -> BoxFuture<'b, Result<IAstNode, CustomError>>; ) -> BoxFuture<'b, Result<IAstNode, CustomError>>
where
Self: 'parse;
} }
impl<'intermediate, 'parse> IntoIAstNode<'intermediate, 'parse> impl IntoIAstNode for organic::types::DocumentElement<'_> {
for organic::types::DocumentElement<'parse> fn into_ast_node<'parse, 'b>(
{ &'b self,
fn new<'b>( registry: &'b mut Registry<'parse>,
&'intermediate self, ) -> BoxFuture<'b, Result<IAstNode, CustomError>>
registry: &'b mut Registry<'intermediate, 'parse>, where
) -> BoxFuture<'b, Result<IAstNode, CustomError>> { Self: 'parse,
{
async move { async move {
match self { match self {
organic::types::DocumentElement::Heading(inner) => { organic::types::DocumentElement::Heading(inner) => {
@ -140,13 +143,14 @@ impl<'intermediate, 'parse> IntoIAstNode<'intermediate, 'parse>
} }
} }
impl<'intermediate, 'parse> IntoIAstNode<'intermediate, 'parse> impl IntoIAstNode for organic::types::Element<'_> {
for organic::types::Element<'parse> fn into_ast_node<'parse, 'b>(
{ &'b self,
fn new<'b>( registry: &'b mut Registry<'parse>,
&'intermediate self, ) -> BoxFuture<'b, Result<IAstNode, CustomError>>
registry: &'b mut Registry<'intermediate, 'parse>, where
) -> BoxFuture<'b, Result<IAstNode, CustomError>> { Self: 'parse,
{
async move { async move {
match self { match self {
organic::types::Element::Paragraph(inner) => { organic::types::Element::Paragraph(inner) => {
@ -227,11 +231,14 @@ impl<'intermediate, 'parse> IntoIAstNode<'intermediate, 'parse>
} }
} }
impl<'intermediate, 'parse> IntoIAstNode<'intermediate, 'parse> for organic::types::Object<'parse> { impl IntoIAstNode for organic::types::Object<'_> {
fn new<'b>( fn into_ast_node<'parse, 'b>(
&'intermediate self, &'b self,
registry: &'b mut Registry<'intermediate, 'parse>, registry: &'b mut Registry<'parse>,
) -> BoxFuture<'b, Result<IAstNode, CustomError>> { ) -> BoxFuture<'b, Result<IAstNode, CustomError>>
where
Self: 'parse,
{
async move { async move {
match self { match self {
organic::types::Object::Bold(inner) => { organic::types::Object::Bold(inner) => {

View File

@ -6,9 +6,9 @@ use super::registry::Registry;
pub(crate) struct IBabelCall {} pub(crate) struct IBabelCall {}
impl IBabelCall { impl IBabelCall {
pub(crate) async fn new<'intermediate, 'parse>( pub(crate) async fn new<'b, 'parse>(
registry: &mut Registry<'intermediate, 'parse>, registry: &'b mut Registry<'parse>,
original: &organic::types::BabelCall<'parse>, original: &'b organic::types::BabelCall<'parse>,
) -> Result<IBabelCall, CustomError> { ) -> Result<IBabelCall, CustomError> {
Ok(IBabelCall {}) Ok(IBabelCall {})
} }

View File

@ -6,9 +6,9 @@ use super::registry::Registry;
pub(crate) struct IBold {} pub(crate) struct IBold {}
impl IBold { impl IBold {
pub(crate) async fn new<'intermediate, 'parse>( pub(crate) async fn new<'b, 'parse>(
registry: &mut Registry<'intermediate, 'parse>, registry: &'b mut Registry<'parse>,
original: &organic::types::Bold<'parse>, original: &'b organic::types::Bold<'parse>,
) -> Result<IBold, CustomError> { ) -> Result<IBold, CustomError> {
Ok(IBold {}) Ok(IBold {})
} }

View File

@ -6,9 +6,9 @@ use super::registry::Registry;
pub(crate) struct ICenterBlock {} pub(crate) struct ICenterBlock {}
impl ICenterBlock { impl ICenterBlock {
pub(crate) async fn new<'intermediate, 'parse>( pub(crate) async fn new<'b, 'parse>(
registry: &mut Registry<'intermediate, 'parse>, registry: &'b mut Registry<'parse>,
original: &organic::types::CenterBlock<'parse>, original: &'b organic::types::CenterBlock<'parse>,
) -> Result<ICenterBlock, CustomError> { ) -> Result<ICenterBlock, CustomError> {
Ok(ICenterBlock {}) Ok(ICenterBlock {})
} }

View File

@ -6,9 +6,9 @@ use super::registry::Registry;
pub(crate) struct ICitation {} pub(crate) struct ICitation {}
impl ICitation { impl ICitation {
pub(crate) async fn new<'intermediate, 'parse>( pub(crate) async fn new<'b, 'parse>(
registry: &mut Registry<'intermediate, 'parse>, registry: &'b mut Registry<'parse>,
original: &organic::types::Citation<'parse>, original: &'b organic::types::Citation<'parse>,
) -> Result<ICitation, CustomError> { ) -> Result<ICitation, CustomError> {
Ok(ICitation {}) Ok(ICitation {})
} }

View File

@ -6,9 +6,9 @@ use super::registry::Registry;
pub(crate) struct ICitationReference {} pub(crate) struct ICitationReference {}
impl ICitationReference { impl ICitationReference {
pub(crate) async fn new<'intermediate, 'parse>( pub(crate) async fn new<'b, 'parse>(
registry: &mut Registry<'intermediate, 'parse>, registry: &'b mut Registry<'parse>,
original: &organic::types::CitationReference<'parse>, original: &'b organic::types::CitationReference<'parse>,
) -> Result<ICitationReference, CustomError> { ) -> Result<ICitationReference, CustomError> {
Ok(ICitationReference {}) Ok(ICitationReference {})
} }

View File

@ -6,9 +6,9 @@ use super::registry::Registry;
pub(crate) struct IClock {} pub(crate) struct IClock {}
impl IClock { impl IClock {
pub(crate) async fn new<'intermediate, 'parse>( pub(crate) async fn new<'b, 'parse>(
registry: &mut Registry<'intermediate, 'parse>, registry: &'b mut Registry<'parse>,
original: &organic::types::Clock<'parse>, original: &'b organic::types::Clock<'parse>,
) -> Result<IClock, CustomError> { ) -> Result<IClock, CustomError> {
Ok(IClock {}) Ok(IClock {})
} }

View File

@ -6,9 +6,9 @@ use super::registry::Registry;
pub(crate) struct ICode {} pub(crate) struct ICode {}
impl ICode { impl ICode {
pub(crate) async fn new<'intermediate, 'parse>( pub(crate) async fn new<'b, 'parse>(
registry: &mut Registry<'intermediate, 'parse>, registry: &'b mut Registry<'parse>,
original: &organic::types::Code<'parse>, original: &'b organic::types::Code<'parse>,
) -> Result<ICode, CustomError> { ) -> Result<ICode, CustomError> {
Ok(ICode {}) Ok(ICode {})
} }

View File

@ -7,9 +7,9 @@ use super::registry::Registry;
pub(crate) struct IComment {} pub(crate) struct IComment {}
impl IComment { impl IComment {
pub(crate) async fn new<'intermediate, 'parse>( pub(crate) async fn new<'b, 'parse>(
registry: &mut Registry<'intermediate, 'parse>, registry: &'b mut Registry<'parse>,
comment: &organic::types::Comment<'parse>, comment: &'b organic::types::Comment<'parse>,
) -> Result<IComment, CustomError> { ) -> Result<IComment, CustomError> {
Ok(IComment {}) Ok(IComment {})
} }

View File

@ -6,9 +6,9 @@ use super::registry::Registry;
pub(crate) struct ICommentBlock {} pub(crate) struct ICommentBlock {}
impl ICommentBlock { impl ICommentBlock {
pub(crate) async fn new<'intermediate, 'parse>( pub(crate) async fn new<'b, 'parse>(
registry: &mut Registry<'intermediate, 'parse>, registry: &'b mut Registry<'parse>,
original: &organic::types::CommentBlock<'parse>, original: &'b organic::types::CommentBlock<'parse>,
) -> Result<ICommentBlock, CustomError> { ) -> Result<ICommentBlock, CustomError> {
Ok(ICommentBlock {}) Ok(ICommentBlock {})
} }

View File

@ -6,9 +6,9 @@ use super::registry::Registry;
pub(crate) struct IDiarySexp {} pub(crate) struct IDiarySexp {}
impl IDiarySexp { impl IDiarySexp {
pub(crate) async fn new<'intermediate, 'parse>( pub(crate) async fn new<'b, 'parse>(
registry: &mut Registry<'intermediate, 'parse>, registry: &'b mut Registry<'parse>,
original: &organic::types::DiarySexp<'parse>, original: &'b organic::types::DiarySexp<'parse>,
) -> Result<IDiarySexp, CustomError> { ) -> Result<IDiarySexp, CustomError> {
Ok(IDiarySexp {}) Ok(IDiarySexp {})
} }

View File

@ -12,9 +12,9 @@ pub(crate) enum IDocumentElement {
} }
impl IDocumentElement { impl IDocumentElement {
pub(crate) fn new<'intermediate, 'parse, 'b>( pub(crate) fn new<'parse, 'b>(
registry: &'b mut Registry<'intermediate, 'parse>, registry: &'b mut Registry<'parse>,
original: &'intermediate organic::types::DocumentElement<'parse>, original: &'b organic::types::DocumentElement<'parse>,
) -> BoxFuture<'b, Result<IDocumentElement, CustomError>> { ) -> BoxFuture<'b, Result<IDocumentElement, CustomError>> {
async move { async move {
match original { match original {

View File

@ -6,9 +6,9 @@ use super::registry::Registry;
pub(crate) struct IDrawer {} pub(crate) struct IDrawer {}
impl IDrawer { impl IDrawer {
pub(crate) async fn new<'intermediate, 'parse>( pub(crate) async fn new<'b, 'parse>(
registry: &mut Registry<'intermediate, 'parse>, registry: &'b mut Registry<'parse>,
original: &organic::types::Drawer<'parse>, original: &'b organic::types::Drawer<'parse>,
) -> Result<IDrawer, CustomError> { ) -> Result<IDrawer, CustomError> {
Ok(IDrawer {}) Ok(IDrawer {})
} }

View File

@ -6,9 +6,9 @@ use super::registry::Registry;
pub(crate) struct IDynamicBlock {} pub(crate) struct IDynamicBlock {}
impl IDynamicBlock { impl IDynamicBlock {
pub(crate) async fn new<'intermediate, 'parse>( pub(crate) async fn new<'b, 'parse>(
registry: &mut Registry<'intermediate, 'parse>, registry: &'b mut Registry<'parse>,
original: &organic::types::DynamicBlock<'parse>, original: &'b organic::types::DynamicBlock<'parse>,
) -> Result<IDynamicBlock, CustomError> { ) -> Result<IDynamicBlock, CustomError> {
Ok(IDynamicBlock {}) Ok(IDynamicBlock {})
} }

View File

@ -56,9 +56,9 @@ pub(crate) enum IElement {
} }
impl IElement { impl IElement {
pub(crate) fn new<'intermediate, 'parse, 'b>( pub(crate) fn new<'parse, 'b>(
registry: &'b mut Registry<'intermediate, 'parse>, registry: &'b mut Registry<'parse>,
elem: &'intermediate organic::types::Element<'parse>, elem: &'b organic::types::Element<'parse>,
) -> BoxFuture<'b, Result<IElement, CustomError>> { ) -> BoxFuture<'b, Result<IElement, CustomError>> {
async move { async move {
match elem { match elem {

View File

@ -8,9 +8,9 @@ pub(crate) struct IEntity {
} }
impl IEntity { impl IEntity {
pub(crate) async fn new<'intermediate, 'parse>( pub(crate) async fn new<'b, 'parse>(
registry: &mut Registry<'intermediate, 'parse>, registry: &'b mut Registry<'parse>,
original: &organic::types::Entity<'parse>, original: &'b organic::types::Entity<'parse>,
) -> Result<IEntity, CustomError> { ) -> Result<IEntity, CustomError> {
Ok(IEntity { Ok(IEntity {
html: original.html.to_owned(), html: original.html.to_owned(),

View File

@ -6,9 +6,9 @@ use super::registry::Registry;
pub(crate) struct IExampleBlock {} pub(crate) struct IExampleBlock {}
impl IExampleBlock { impl IExampleBlock {
pub(crate) async fn new<'intermediate, 'parse>( pub(crate) async fn new<'b, 'parse>(
registry: &mut Registry<'intermediate, 'parse>, registry: &'b mut Registry<'parse>,
original: &organic::types::ExampleBlock<'parse>, original: &'b organic::types::ExampleBlock<'parse>,
) -> Result<IExampleBlock, CustomError> { ) -> Result<IExampleBlock, CustomError> {
Ok(IExampleBlock {}) Ok(IExampleBlock {})
} }

View File

@ -6,9 +6,9 @@ use super::registry::Registry;
pub(crate) struct IExportBlock {} pub(crate) struct IExportBlock {}
impl IExportBlock { impl IExportBlock {
pub(crate) async fn new<'intermediate, 'parse>( pub(crate) async fn new<'b, 'parse>(
registry: &mut Registry<'intermediate, 'parse>, registry: &'b mut Registry<'parse>,
original: &organic::types::ExportBlock<'parse>, original: &'b organic::types::ExportBlock<'parse>,
) -> Result<IExportBlock, CustomError> { ) -> Result<IExportBlock, CustomError> {
Ok(IExportBlock {}) Ok(IExportBlock {})
} }

View File

@ -6,9 +6,9 @@ use super::registry::Registry;
pub(crate) struct IExportSnippet {} pub(crate) struct IExportSnippet {}
impl IExportSnippet { impl IExportSnippet {
pub(crate) async fn new<'intermediate, 'parse>( pub(crate) async fn new<'b, 'parse>(
registry: &mut Registry<'intermediate, 'parse>, registry: &'b mut Registry<'parse>,
original: &organic::types::ExportSnippet<'parse>, original: &'b organic::types::ExportSnippet<'parse>,
) -> Result<IExportSnippet, CustomError> { ) -> Result<IExportSnippet, CustomError> {
Ok(IExportSnippet {}) Ok(IExportSnippet {})
} }

View File

@ -6,9 +6,9 @@ use super::registry::Registry;
pub(crate) struct IFixedWidthArea {} pub(crate) struct IFixedWidthArea {}
impl IFixedWidthArea { impl IFixedWidthArea {
pub(crate) async fn new<'intermediate, 'parse>( pub(crate) async fn new<'b, 'parse>(
registry: &mut Registry<'intermediate, 'parse>, registry: &'b mut Registry<'parse>,
original: &organic::types::FixedWidthArea<'parse>, original: &'b organic::types::FixedWidthArea<'parse>,
) -> Result<IFixedWidthArea, CustomError> { ) -> Result<IFixedWidthArea, CustomError> {
Ok(IFixedWidthArea {}) Ok(IFixedWidthArea {})
} }

View File

@ -1,7 +1,6 @@
use crate::error::CustomError; use crate::error::CustomError;
use super::ast_node::IAstNode; use super::ast_node::IAstNode;
use super::registry::FootnoteDefinitionContents;
use super::registry::Registry; use super::registry::Registry;
use super::IElement; use super::IElement;
use super::IObject; use super::IObject;
@ -10,11 +9,13 @@ use super::IObject;
pub(crate) struct IFootnoteDefinition {} pub(crate) struct IFootnoteDefinition {}
impl IFootnoteDefinition { impl IFootnoteDefinition {
pub(crate) async fn new<'intermediate, 'parse>( pub(crate) async fn new<'b, 'parse>(
registry: &mut Registry<'intermediate, 'parse>, registry: &'b mut Registry<'parse>,
original: &'intermediate organic::types::FootnoteDefinition<'parse>, original: &'b organic::types::FootnoteDefinition<'parse>,
) -> Result<IFootnoteDefinition, CustomError> { ) -> Result<IFootnoteDefinition, CustomError> {
registry.register_footnote_definition(original.label, &original.children); registry
.register_footnote_definition(original.label, &original.children)
.await?;
Ok(IFootnoteDefinition {}) Ok(IFootnoteDefinition {})
} }
} }
@ -26,33 +27,11 @@ pub(crate) struct IRealFootnoteDefinition {
} }
impl IRealFootnoteDefinition { impl IRealFootnoteDefinition {
pub(crate) async fn new<'intermediate, 'parse>( pub(crate) async fn new<'b, 'parse>(
registry: &mut Registry<'intermediate, 'parse>, registry: &'b mut Registry<'parse>,
footnote_id: usize, footnote_id: usize,
original: &FootnoteDefinitionContents<'intermediate, 'parse>, contents: Vec<IAstNode>,
) -> Result<IRealFootnoteDefinition, CustomError> { ) -> Result<IRealFootnoteDefinition, CustomError> {
let contents = match original {
FootnoteDefinitionContents::FromReference(inner) => {
let contents = {
let mut ret = Vec::new();
for obj in inner.iter() {
ret.push(IAstNode::Object(IObject::new(registry, obj).await?));
}
ret
};
contents
}
FootnoteDefinitionContents::FromDefinition(inner) => {
let contents = {
let mut ret = Vec::new();
for obj in inner.iter() {
ret.push(IAstNode::Element(IElement::new(registry, obj).await?));
}
ret
};
contents
}
};
Ok(IRealFootnoteDefinition { Ok(IRealFootnoteDefinition {
footnote_id, footnote_id,
contents, contents,

View File

@ -9,11 +9,13 @@ pub(crate) struct IFootnoteReference {
} }
impl IFootnoteReference { impl IFootnoteReference {
pub(crate) async fn new<'intermediate, 'parse>( pub(crate) async fn new<'b, 'parse>(
registry: &mut Registry<'intermediate, 'parse>, registry: &'b mut Registry<'parse>,
original: &'intermediate organic::types::FootnoteReference<'parse>, original: &'b organic::types::FootnoteReference<'parse>,
) -> Result<IFootnoteReference, CustomError> { ) -> Result<IFootnoteReference, CustomError> {
let footnote_id = registry.get_footnote_reference_id(original.label, &original.definition); let footnote_id = registry
.get_footnote_reference_id(original.label, &original.definition)
.await?;
Ok(IFootnoteReference { Ok(IFootnoteReference {
footnote_id, footnote_id,
duplicate_offset: 0, // TODO duplicate_offset: 0, // TODO

View File

@ -12,9 +12,9 @@ pub(crate) struct IHeading {
} }
impl IHeading { impl IHeading {
pub(crate) async fn new<'intermediate, 'parse>( pub(crate) async fn new<'b, 'parse>(
registry: &mut Registry<'intermediate, 'parse>, registry: &'b mut Registry<'parse>,
original: &'intermediate organic::types::Heading<'parse>, original: &'b organic::types::Heading<'parse>,
) -> Result<IHeading, CustomError> { ) -> Result<IHeading, CustomError> {
let title = { let title = {
let mut ret = Vec::new(); let mut ret = Vec::new();

View File

@ -6,9 +6,9 @@ use super::registry::Registry;
pub(crate) struct IHorizontalRule {} pub(crate) struct IHorizontalRule {}
impl IHorizontalRule { impl IHorizontalRule {
pub(crate) async fn new<'intermediate, 'parse>( pub(crate) async fn new<'b, 'parse>(
registry: &mut Registry<'intermediate, 'parse>, registry: &'b mut Registry<'parse>,
original: &organic::types::HorizontalRule<'parse>, original: &'b organic::types::HorizontalRule<'parse>,
) -> Result<IHorizontalRule, CustomError> { ) -> Result<IHorizontalRule, CustomError> {
Ok(IHorizontalRule {}) Ok(IHorizontalRule {})
} }

View File

@ -6,9 +6,9 @@ use super::registry::Registry;
pub(crate) struct IInlineBabelCall {} pub(crate) struct IInlineBabelCall {}
impl IInlineBabelCall { impl IInlineBabelCall {
pub(crate) async fn new<'intermediate, 'parse>( pub(crate) async fn new<'b, 'parse>(
registry: &mut Registry<'intermediate, 'parse>, registry: &'b mut Registry<'parse>,
original: &organic::types::InlineBabelCall<'parse>, original: &'b organic::types::InlineBabelCall<'parse>,
) -> Result<IInlineBabelCall, CustomError> { ) -> Result<IInlineBabelCall, CustomError> {
Ok(IInlineBabelCall {}) Ok(IInlineBabelCall {})
} }

View File

@ -8,9 +8,9 @@ pub(crate) struct IInlineSourceBlock {
} }
impl IInlineSourceBlock { impl IInlineSourceBlock {
pub(crate) async fn new<'intermediate, 'parse>( pub(crate) async fn new<'b, 'parse>(
registry: &mut Registry<'intermediate, 'parse>, registry: &'b mut Registry<'parse>,
original: &organic::types::InlineSourceBlock<'parse>, original: &'b organic::types::InlineSourceBlock<'parse>,
) -> Result<IInlineSourceBlock, CustomError> { ) -> Result<IInlineSourceBlock, CustomError> {
Ok(IInlineSourceBlock { Ok(IInlineSourceBlock {
value: original.value.to_owned(), value: original.value.to_owned(),

View File

@ -6,9 +6,9 @@ use super::registry::Registry;
pub(crate) struct IItalic {} pub(crate) struct IItalic {}
impl IItalic { impl IItalic {
pub(crate) async fn new<'intermediate, 'parse>( pub(crate) async fn new<'b, 'parse>(
registry: &mut Registry<'intermediate, 'parse>, registry: &'b mut Registry<'parse>,
original: &organic::types::Italic<'parse>, original: &'b organic::types::Italic<'parse>,
) -> Result<IItalic, CustomError> { ) -> Result<IItalic, CustomError> {
Ok(IItalic {}) Ok(IItalic {})
} }

View File

@ -7,9 +7,9 @@ use super::registry::Registry;
pub(crate) struct IKeyword {} pub(crate) struct IKeyword {}
impl IKeyword { impl IKeyword {
pub(crate) async fn new<'intermediate, 'parse>( pub(crate) async fn new<'b, 'parse>(
registry: &mut Registry<'intermediate, 'parse>, registry: &'b mut Registry<'parse>,
keyword: &organic::types::Keyword<'parse>, keyword: &'b organic::types::Keyword<'parse>,
) -> Result<IKeyword, CustomError> { ) -> Result<IKeyword, CustomError> {
Ok(IKeyword {}) Ok(IKeyword {})
} }

View File

@ -6,9 +6,9 @@ use super::registry::Registry;
pub(crate) struct ILatexEnvironment {} pub(crate) struct ILatexEnvironment {}
impl ILatexEnvironment { impl ILatexEnvironment {
pub(crate) async fn new<'intermediate, 'parse>( pub(crate) async fn new<'b, 'parse>(
registry: &mut Registry<'intermediate, 'parse>, registry: &'b mut Registry<'parse>,
original: &organic::types::LatexEnvironment<'parse>, original: &'b organic::types::LatexEnvironment<'parse>,
) -> Result<ILatexEnvironment, CustomError> { ) -> Result<ILatexEnvironment, CustomError> {
Ok(ILatexEnvironment {}) Ok(ILatexEnvironment {})
} }

View File

@ -6,9 +6,9 @@ use super::registry::Registry;
pub(crate) struct ILatexFragment {} pub(crate) struct ILatexFragment {}
impl ILatexFragment { impl ILatexFragment {
pub(crate) async fn new<'intermediate, 'parse>( pub(crate) async fn new<'b, 'parse>(
registry: &mut Registry<'intermediate, 'parse>, registry: &'b mut Registry<'parse>,
original: &organic::types::LatexFragment<'parse>, original: &'b organic::types::LatexFragment<'parse>,
) -> Result<ILatexFragment, CustomError> { ) -> Result<ILatexFragment, CustomError> {
Ok(ILatexFragment {}) Ok(ILatexFragment {})
} }

View File

@ -6,9 +6,9 @@ use super::registry::Registry;
pub(crate) struct ILineBreak {} pub(crate) struct ILineBreak {}
impl ILineBreak { impl ILineBreak {
pub(crate) async fn new<'intermediate, 'parse>( pub(crate) async fn new<'b, 'parse>(
registry: &mut Registry<'intermediate, 'parse>, registry: &'b mut Registry<'parse>,
original: &organic::types::LineBreak<'parse>, original: &'b organic::types::LineBreak<'parse>,
) -> Result<ILineBreak, CustomError> { ) -> Result<ILineBreak, CustomError> {
Ok(ILineBreak {}) Ok(ILineBreak {})
} }

View File

@ -62,9 +62,9 @@ pub(crate) enum IObject {
} }
impl IObject { impl IObject {
pub(crate) fn new<'intermediate, 'parse, 'b>( pub(crate) fn new<'parse, 'b>(
registry: &'b mut Registry<'intermediate, 'parse>, registry: &'b mut Registry<'parse>,
obj: &'intermediate organic::types::Object<'parse>, obj: &'b organic::types::Object<'parse>,
) -> BoxFuture<'b, Result<IObject, CustomError>> { ) -> BoxFuture<'b, Result<IObject, CustomError>> {
async move { async move {
match obj { match obj {

View File

@ -6,9 +6,9 @@ use super::registry::Registry;
pub(crate) struct IOrgMacro {} pub(crate) struct IOrgMacro {}
impl IOrgMacro { impl IOrgMacro {
pub(crate) async fn new<'intermediate, 'parse>( pub(crate) async fn new<'b, 'parse>(
registry: &mut Registry<'intermediate, 'parse>, registry: &'b mut Registry<'parse>,
original: &organic::types::OrgMacro<'parse>, original: &'b organic::types::OrgMacro<'parse>,
) -> Result<IOrgMacro, CustomError> { ) -> Result<IOrgMacro, CustomError> {
Ok(IOrgMacro {}) Ok(IOrgMacro {})
} }

View File

@ -21,10 +21,10 @@ pub(crate) struct BlogPostPage {
} }
impl BlogPostPage { impl BlogPostPage {
pub(crate) async fn new<'intermediate, 'parse, P: Into<PathBuf>>( pub(crate) async fn new<'b, 'parse, P: Into<PathBuf>>(
path: P, path: P,
registry: &mut Registry<'intermediate, 'parse>, registry: &'b mut Registry<'parse>,
document: &'intermediate organic::types::Document<'parse>, document: &'b organic::types::Document<'parse>,
) -> Result<BlogPostPage, CustomError> { ) -> Result<BlogPostPage, CustomError> {
let path = path.into(); let path = path.into();
let mut children = Vec::new(); let mut children = Vec::new();

View File

@ -9,9 +9,9 @@ pub(crate) struct IParagraph {
} }
impl IParagraph { impl IParagraph {
pub(crate) async fn new<'intermediate, 'parse>( pub(crate) async fn new<'b, 'parse>(
registry: &mut Registry<'intermediate, 'parse>, registry: &'b mut Registry<'parse>,
original: &'intermediate organic::types::Paragraph<'parse>, original: &'b organic::types::Paragraph<'parse>,
) -> Result<IParagraph, CustomError> { ) -> Result<IParagraph, CustomError> {
let children = { let children = {
let mut ret = Vec::new(); let mut ret = Vec::new();

View File

@ -6,9 +6,9 @@ use super::registry::Registry;
pub(crate) struct IPlainLink {} pub(crate) struct IPlainLink {}
impl IPlainLink { impl IPlainLink {
pub(crate) async fn new<'intermediate, 'parse>( pub(crate) async fn new<'b, 'parse>(
registry: &mut Registry<'intermediate, 'parse>, registry: &'b mut Registry<'parse>,
original: &organic::types::PlainLink<'parse>, original: &'b organic::types::PlainLink<'parse>,
) -> Result<IPlainLink, CustomError> { ) -> Result<IPlainLink, CustomError> {
Ok(IPlainLink {}) Ok(IPlainLink {})
} }

View File

@ -10,9 +10,9 @@ pub(crate) struct IPlainList {
} }
impl IPlainList { impl IPlainList {
pub(crate) async fn new<'intermediate, 'parse>( pub(crate) async fn new<'b, 'parse>(
registry: &mut Registry<'intermediate, 'parse>, registry: &'b mut Registry<'parse>,
original: &'intermediate organic::types::PlainList<'parse>, original: &'b organic::types::PlainList<'parse>,
) -> Result<IPlainList, CustomError> { ) -> Result<IPlainList, CustomError> {
let children = { let children = {
let mut ret = Vec::new(); let mut ret = Vec::new();

View File

@ -11,9 +11,9 @@ pub(crate) struct IPlainListItem {
} }
impl IPlainListItem { impl IPlainListItem {
pub(crate) async fn new<'intermediate, 'parse>( pub(crate) async fn new<'b, 'parse>(
registry: &mut Registry<'intermediate, 'parse>, registry: &'b mut Registry<'parse>,
original: &'intermediate organic::types::PlainListItem<'parse>, original: &'b organic::types::PlainListItem<'parse>,
) -> Result<IPlainListItem, CustomError> { ) -> Result<IPlainListItem, CustomError> {
let tag = { let tag = {
let mut ret = Vec::new(); let mut ret = Vec::new();

View File

@ -9,9 +9,9 @@ pub(crate) struct IPlainText {
} }
impl IPlainText { impl IPlainText {
pub(crate) async fn new<'intermediate, 'parse>( pub(crate) async fn new<'b, 'parse>(
registry: &mut Registry<'intermediate, 'parse>, registry: &'b mut Registry<'parse>,
plain_text: &organic::types::PlainText<'parse>, plain_text: &'b organic::types::PlainText<'parse>,
) -> Result<IPlainText, CustomError> { ) -> Result<IPlainText, CustomError> {
Ok(IPlainText { Ok(IPlainText {
source: coalesce_whitespace(plain_text.source).into_owned(), source: coalesce_whitespace(plain_text.source).into_owned(),

View File

@ -6,9 +6,9 @@ use super::registry::Registry;
pub(crate) struct IPlanning {} pub(crate) struct IPlanning {}
impl IPlanning { impl IPlanning {
pub(crate) async fn new<'intermediate, 'parse>( pub(crate) async fn new<'b, 'parse>(
registry: &mut Registry<'intermediate, 'parse>, registry: &'b mut Registry<'parse>,
original: &organic::types::Planning<'parse>, original: &'b organic::types::Planning<'parse>,
) -> Result<IPlanning, CustomError> { ) -> Result<IPlanning, CustomError> {
Ok(IPlanning {}) Ok(IPlanning {})
} }

View File

@ -6,9 +6,9 @@ use super::registry::Registry;
pub(crate) struct IPropertyDrawer {} pub(crate) struct IPropertyDrawer {}
impl IPropertyDrawer { impl IPropertyDrawer {
pub(crate) async fn new<'intermediate, 'parse>( pub(crate) async fn new<'b, 'parse>(
registry: &mut Registry<'intermediate, 'parse>, registry: &'b mut Registry<'parse>,
original: &organic::types::PropertyDrawer<'parse>, original: &'b organic::types::PropertyDrawer<'parse>,
) -> Result<IPropertyDrawer, CustomError> { ) -> Result<IPropertyDrawer, CustomError> {
Ok(IPropertyDrawer {}) Ok(IPropertyDrawer {})
} }

View File

@ -9,9 +9,9 @@ pub(crate) struct IQuoteBlock {
} }
impl IQuoteBlock { impl IQuoteBlock {
pub(crate) async fn new<'intermediate, 'parse>( pub(crate) async fn new<'b, 'parse>(
registry: &mut Registry<'intermediate, 'parse>, registry: &'b mut Registry<'parse>,
original: &'intermediate organic::types::QuoteBlock<'parse>, original: &'b organic::types::QuoteBlock<'parse>,
) -> Result<IQuoteBlock, CustomError> { ) -> Result<IQuoteBlock, CustomError> {
let children = { let children = {
let mut ret = Vec::new(); let mut ret = Vec::new();

View File

@ -6,9 +6,9 @@ use super::registry::Registry;
pub(crate) struct IRadioLink {} pub(crate) struct IRadioLink {}
impl IRadioLink { impl IRadioLink {
pub(crate) async fn new<'intermediate, 'parse>( pub(crate) async fn new<'b, 'parse>(
registry: &mut Registry<'intermediate, 'parse>, registry: &'b mut Registry<'parse>,
original: &organic::types::RadioLink<'parse>, original: &'b organic::types::RadioLink<'parse>,
) -> Result<IRadioLink, CustomError> { ) -> Result<IRadioLink, CustomError> {
Ok(IRadioLink {}) Ok(IRadioLink {})
} }

View File

@ -6,9 +6,9 @@ use super::registry::Registry;
pub(crate) struct IRadioTarget {} pub(crate) struct IRadioTarget {}
impl IRadioTarget { impl IRadioTarget {
pub(crate) async fn new<'intermediate, 'parse>( pub(crate) async fn new<'b, 'parse>(
registry: &mut Registry<'intermediate, 'parse>, registry: &'b mut Registry<'parse>,
original: &organic::types::RadioTarget<'parse>, original: &'b organic::types::RadioTarget<'parse>,
) -> Result<IRadioTarget, CustomError> { ) -> Result<IRadioTarget, CustomError> {
Ok(IRadioTarget {}) Ok(IRadioTarget {})
} }

View File

@ -1,5 +1,7 @@
use std::collections::HashMap; use std::collections::HashMap;
use super::ast_node::IntoIAstNode;
use crate::error::CustomError;
use organic::types::Element; use organic::types::Element;
use organic::types::Object; use organic::types::Object;
@ -7,14 +9,14 @@ use super::ast_node::IAstNode;
type IdCounter = u16; type IdCounter = u16;
pub(crate) struct Registry<'intermediate, 'parse> { pub(crate) struct Registry<'parse> {
id_counter: IdCounter, id_counter: IdCounter,
targets: HashMap<&'parse str, String>, targets: HashMap<&'parse str, String>,
footnote_ids: Vec<(Option<&'parse str>, Vec<IAstNode>)>, footnote_ids: Vec<(Option<&'parse str>, Vec<IAstNode>)>,
} }
impl<'intermediate, 'parse> Registry<'intermediate, 'parse> { impl<'parse> Registry<'parse> {
pub(crate) fn new() -> Registry<'intermediate, 'parse> { pub(crate) fn new() -> Registry<'parse> {
Registry { Registry {
id_counter: 0, id_counter: 0,
targets: HashMap::new(), targets: HashMap::new(),
@ -32,16 +34,16 @@ impl<'intermediate, 'parse> Registry<'intermediate, 'parse> {
/// Get a 0-indexed ID for a footnote. /// Get a 0-indexed ID for a footnote.
/// ///
/// This needs to be incremented to be 1-indexed for render. /// This needs to be incremented to be 1-indexed for render.
pub(crate) fn get_footnote_reference_id<'b>( pub(crate) async fn get_footnote_reference_id<'b>(
&'b mut self, &'b mut self,
label: Option<&'parse str>, label: Option<&'parse str>,
definition: &'intermediate Vec<Object<'parse>>, definition: &'b Vec<Object<'parse>>,
) -> usize { ) -> Result<usize, CustomError> {
if let None = label { if let None = label {
// If it has no label then it must always get a new ID. // If it has no label then it must always get a new ID.
self.footnote_ids let contents = convert_reference_contents(self, definition).await?;
.push((None, FootnoteDefinitionContents::FromReference(definition))); self.footnote_ids.push((None, contents));
return self.footnote_ids.len() - 1; return Ok(self.footnote_ids.len() - 1);
} }
if let Some(existing_id) = self if let Some(existing_id) = self
@ -50,38 +52,65 @@ impl<'intermediate, 'parse> Registry<'intermediate, 'parse> {
.position(|(id, _definition)| *id == label) .position(|(id, _definition)| *id == label)
{ {
if !definition.is_empty() { if !definition.is_empty() {
let contents = convert_reference_contents(self, definition).await?;
let entry = self let entry = self
.footnote_ids .footnote_ids
.get_mut(existing_id) .get_mut(existing_id)
.expect("If-statement proves this to be Some."); .expect("If-statement proves this to be Some.");
entry.1 = FootnoteDefinitionContents::FromReference(definition); entry.1 = contents;
} }
existing_id Ok(existing_id)
} else { } else {
self.footnote_ids let contents = convert_reference_contents(self, definition).await?;
.push((label, FootnoteDefinitionContents::FromReference(definition))); self.footnote_ids.push((label, contents));
self.footnote_ids.len() - 1 Ok(self.footnote_ids.len() - 1)
} }
} }
/// Update the definition to a footnote but do not mark it as referenced. /// Update the definition to a footnote but do not mark it as referenced.
pub(crate) fn register_footnote_definition<'b>( pub(crate) async fn register_footnote_definition<'b>(
&'b mut self, &'b mut self,
label: &'parse str, label: &'parse str,
definition: &'intermediate Vec<Element<'parse>>, definition: &'b Vec<Element<'parse>>,
) { ) -> Result<(), CustomError> {
if let Some((existing_id, existing_definition)) = self let contents = convert_definition_contents(self, definition).await?;
if let Some((_existing_id, existing_definition)) = self
.footnote_ids .footnote_ids
.iter_mut() .iter_mut()
.find(|(id, _definition)| *id == Some(label)) .find(|(id, _definition)| *id == Some(label))
{ {
*existing_definition = FootnoteDefinitionContents::FromDefinition(definition); *existing_definition = contents;
} }
Ok(())
} }
} }
#[derive(Debug)] async fn convert_reference_contents<'b, 'parse>(
pub(crate) enum FootnoteDefinitionContents<'intermediate, 'parse> { registry: &'b mut Registry<'parse>,
FromReference(&'intermediate Vec<Object<'parse>>), contents: &'b Vec<Object<'parse>>,
FromDefinition(&'intermediate Vec<Element<'parse>>), ) -> Result<Vec<IAstNode>, CustomError> {
let contents = {
let mut ret = Vec::new();
for obj in contents.iter() {
ret.push(obj.into_ast_node(registry).await?);
}
ret
};
Ok(contents)
}
async fn convert_definition_contents<'b, 'parse>(
registry: &'b mut Registry<'parse>,
contents: &'b Vec<Element<'parse>>,
) -> Result<Vec<IAstNode>, CustomError> {
let contents = {
let mut ret = Vec::new();
for obj in contents.iter() {
ret.push(obj.into_ast_node(registry).await?);
}
ret
};
Ok(contents)
} }

View File

@ -10,9 +10,9 @@ pub(crate) struct IRegularLink {
} }
impl IRegularLink { impl IRegularLink {
pub(crate) async fn new<'intermediate, 'parse>( pub(crate) async fn new<'b, 'parse>(
registry: &mut Registry<'intermediate, 'parse>, registry: &'b mut Registry<'parse>,
original: &'intermediate organic::types::RegularLink<'parse>, original: &'b organic::types::RegularLink<'parse>,
) -> Result<IRegularLink, CustomError> { ) -> Result<IRegularLink, CustomError> {
let children = { let children = {
let mut ret = Vec::new(); let mut ret = Vec::new();

View File

@ -9,9 +9,9 @@ pub(crate) struct ISection {
} }
impl ISection { impl ISection {
pub(crate) async fn new<'intermediate, 'parse>( pub(crate) async fn new<'b, 'parse>(
registry: &mut Registry<'intermediate, 'parse>, registry: &'b mut Registry<'parse>,
section: &'intermediate organic::types::Section<'parse>, section: &'b organic::types::Section<'parse>,
) -> Result<ISection, CustomError> { ) -> Result<ISection, CustomError> {
let children = { let children = {
let mut ret = Vec::new(); let mut ret = Vec::new();

View File

@ -6,9 +6,9 @@ use super::registry::Registry;
pub(crate) struct ISpecialBlock {} pub(crate) struct ISpecialBlock {}
impl ISpecialBlock { impl ISpecialBlock {
pub(crate) async fn new<'intermediate, 'parse>( pub(crate) async fn new<'b, 'parse>(
registry: &mut Registry<'intermediate, 'parse>, registry: &'b mut Registry<'parse>,
original: &organic::types::SpecialBlock<'parse>, original: &'b organic::types::SpecialBlock<'parse>,
) -> Result<ISpecialBlock, CustomError> { ) -> Result<ISpecialBlock, CustomError> {
Ok(ISpecialBlock {}) Ok(ISpecialBlock {})
} }

View File

@ -8,9 +8,9 @@ pub(crate) struct ISrcBlock {
} }
impl ISrcBlock { impl ISrcBlock {
pub(crate) async fn new<'intermediate, 'parse>( pub(crate) async fn new<'b, 'parse>(
registry: &mut Registry<'intermediate, 'parse>, registry: &'b mut Registry<'parse>,
original: &organic::types::SrcBlock<'parse>, original: &'b organic::types::SrcBlock<'parse>,
) -> Result<ISrcBlock, CustomError> { ) -> Result<ISrcBlock, CustomError> {
let lines = original let lines = original
.contents .contents

View File

@ -6,9 +6,9 @@ use super::registry::Registry;
pub(crate) struct IStatisticsCookie {} pub(crate) struct IStatisticsCookie {}
impl IStatisticsCookie { impl IStatisticsCookie {
pub(crate) async fn new<'intermediate, 'parse>( pub(crate) async fn new<'b, 'parse>(
registry: &mut Registry<'intermediate, 'parse>, registry: &'b mut Registry<'parse>,
original: &organic::types::StatisticsCookie<'parse>, original: &'b organic::types::StatisticsCookie<'parse>,
) -> Result<IStatisticsCookie, CustomError> { ) -> Result<IStatisticsCookie, CustomError> {
Ok(IStatisticsCookie {}) Ok(IStatisticsCookie {})
} }

View File

@ -6,9 +6,9 @@ use super::registry::Registry;
pub(crate) struct IStrikeThrough {} pub(crate) struct IStrikeThrough {}
impl IStrikeThrough { impl IStrikeThrough {
pub(crate) async fn new<'intermediate, 'parse>( pub(crate) async fn new<'b, 'parse>(
registry: &mut Registry<'intermediate, 'parse>, registry: &'b mut Registry<'parse>,
original: &organic::types::StrikeThrough<'parse>, original: &'b organic::types::StrikeThrough<'parse>,
) -> Result<IStrikeThrough, CustomError> { ) -> Result<IStrikeThrough, CustomError> {
Ok(IStrikeThrough {}) Ok(IStrikeThrough {})
} }

View File

@ -6,9 +6,9 @@ use super::registry::Registry;
pub(crate) struct ISubscript {} pub(crate) struct ISubscript {}
impl ISubscript { impl ISubscript {
pub(crate) async fn new<'intermediate, 'parse>( pub(crate) async fn new<'b, 'parse>(
registry: &mut Registry<'intermediate, 'parse>, registry: &'b mut Registry<'parse>,
original: &organic::types::Subscript<'parse>, original: &'b organic::types::Subscript<'parse>,
) -> Result<ISubscript, CustomError> { ) -> Result<ISubscript, CustomError> {
Ok(ISubscript {}) Ok(ISubscript {})
} }

View File

@ -6,9 +6,9 @@ use super::registry::Registry;
pub(crate) struct ISuperscript {} pub(crate) struct ISuperscript {}
impl ISuperscript { impl ISuperscript {
pub(crate) async fn new<'intermediate, 'parse>( pub(crate) async fn new<'b, 'parse>(
registry: &mut Registry<'intermediate, 'parse>, registry: &'b mut Registry<'parse>,
original: &organic::types::Superscript<'parse>, original: &'b organic::types::Superscript<'parse>,
) -> Result<ISuperscript, CustomError> { ) -> Result<ISuperscript, CustomError> {
Ok(ISuperscript {}) Ok(ISuperscript {})
} }

View File

@ -6,9 +6,9 @@ use super::registry::Registry;
pub(crate) struct ITable {} pub(crate) struct ITable {}
impl ITable { impl ITable {
pub(crate) async fn new<'intermediate, 'parse>( pub(crate) async fn new<'b, 'parse>(
registry: &mut Registry<'intermediate, 'parse>, registry: &'b mut Registry<'parse>,
original: &organic::types::Table<'parse>, original: &'b organic::types::Table<'parse>,
) -> Result<ITable, CustomError> { ) -> Result<ITable, CustomError> {
Ok(ITable {}) Ok(ITable {})
} }

View File

@ -10,9 +10,9 @@ pub(crate) struct ITarget {
} }
impl ITarget { impl ITarget {
pub(crate) async fn new<'intermediate, 'parse>( pub(crate) async fn new<'b, 'parse>(
registry: &mut Registry<'intermediate, 'parse>, registry: &'b mut Registry<'parse>,
target: &organic::types::Target<'parse>, target: &'b organic::types::Target<'parse>,
) -> Result<ITarget, CustomError> { ) -> Result<ITarget, CustomError> {
let id = registry.get_target(target.value); let id = registry.get_target(target.value);
Ok(ITarget { Ok(ITarget {

View File

@ -6,9 +6,9 @@ use super::registry::Registry;
pub(crate) struct ITimestamp {} pub(crate) struct ITimestamp {}
impl ITimestamp { impl ITimestamp {
pub(crate) async fn new<'intermediate, 'parse>( pub(crate) async fn new<'b, 'parse>(
registry: &mut Registry<'intermediate, 'parse>, registry: &'b mut Registry<'parse>,
original: &organic::types::Timestamp<'parse>, original: &'b organic::types::Timestamp<'parse>,
) -> Result<ITimestamp, CustomError> { ) -> Result<ITimestamp, CustomError> {
Ok(ITimestamp {}) Ok(ITimestamp {})
} }

View File

@ -6,9 +6,9 @@ use super::registry::Registry;
pub(crate) struct IUnderline {} pub(crate) struct IUnderline {}
impl IUnderline { impl IUnderline {
pub(crate) async fn new<'intermediate, 'parse>( pub(crate) async fn new<'b, 'parse>(
registry: &mut Registry<'intermediate, 'parse>, registry: &'b mut Registry<'parse>,
original: &organic::types::Underline<'parse>, original: &'b organic::types::Underline<'parse>,
) -> Result<IUnderline, CustomError> { ) -> Result<IUnderline, CustomError> {
Ok(IUnderline {}) Ok(IUnderline {})
} }

View File

@ -6,9 +6,9 @@ use super::registry::Registry;
pub(crate) struct IVerbatim {} pub(crate) struct IVerbatim {}
impl IVerbatim { impl IVerbatim {
pub(crate) async fn new<'intermediate, 'parse>( pub(crate) async fn new<'b, 'parse>(
registry: &mut Registry<'intermediate, 'parse>, registry: &'b mut Registry<'parse>,
original: &organic::types::Verbatim<'parse>, original: &'b organic::types::Verbatim<'parse>,
) -> Result<IVerbatim, CustomError> { ) -> Result<IVerbatim, CustomError> {
Ok(IVerbatim {}) Ok(IVerbatim {})
} }

View File

@ -6,9 +6,9 @@ use super::registry::Registry;
pub(crate) struct IVerseBlock {} pub(crate) struct IVerseBlock {}
impl IVerseBlock { impl IVerseBlock {
pub(crate) async fn new<'intermediate, 'parse>( pub(crate) async fn new<'b, 'parse>(
registry: &mut Registry<'intermediate, 'parse>, registry: &'b mut Registry<'parse>,
original: &organic::types::VerseBlock<'parse>, original: &'b organic::types::VerseBlock<'parse>,
) -> Result<IVerseBlock, CustomError> { ) -> Result<IVerseBlock, CustomError> {
Ok(IVerseBlock {}) Ok(IVerseBlock {})
} }