Implement a new to_wasm macro that uses the WasmAstNodeWrapper.

This commit is contained in:
Tom Alexander
2023-12-29 14:06:10 -05:00
parent a0a4f0eb90
commit cad2be43bf
3 changed files with 86 additions and 55 deletions

View File

@@ -1,3 +1,5 @@
use std::borrow::Cow;
use serde::Serialize;
use super::angle_link::WasmAngleLink;
@@ -58,39 +60,24 @@ use super::timestamp::WasmTimestamp;
use super::underline::WasmUnderline;
use super::verbatim::WasmVerbatim;
use super::verse_block::WasmVerseBlock;
use super::WasmStandardProperties;
// #[derive(Debug, Serialize)]
// pub(crate) struct WasmAstWrapper<'b, 's, 'p, I> {
// #[serde(rename = "ast-node")]
// pub(crate) ast_node: Cow<'static, str>,
// #[serde(rename = "standard-properties")]
// pub(crate) standard_properties: WasmStandardProperties,
// #[serde(rename = "properties")]
// pub(crate) inner: I,
// pub(crate) children: &'b Vec<WasmAstNode<'s, 'p>>,
// }
// impl<'b, 's, 'p, I> WasmAstWrapper<'b, 's, 'p, I> {
// pub(crate) fn new(
// ast_node: Cow<'s, str>,
// standard_properties: &'b WasmStandardProperties,
// inner: I,
// children: &'b Vec<WasmAstNode<'s, 'p>>,
// ) -> WasmAstWrapper<'b, 's, 'p, I> {
// WasmAstWrapper {
// ast_node,
// standard_properties,
// inner,
// children,
// }
// }
// }
#[derive(Debug, Serialize)]
pub struct WasmAstNodeWrapper<I> {
pub(crate) ast_node: String,
#[serde(rename = "standard-properties")]
pub(crate) standard_properties: WasmStandardProperties,
#[serde(rename = "children")]
pub(crate) children: Vec<WasmAstNode>,
#[serde(rename = "properties")]
pub(crate) properties: I,
}
#[derive(Debug, Serialize)]
#[serde(untagged)]
pub enum WasmAstNode {
// Document Nodes
Document(WasmDocument),
Document(WasmAstNodeWrapper<WasmDocument>),
Headline(WasmHeadline),
Section(WasmSection),
// Elements