Implement a wrapper type for AST nodes.

This is to make it impossible to have a collision for attribute names that are real attributes vs attributes I've added for structure (like children and ast_node).
This commit is contained in:
Tom Alexander
2023-12-29 11:56:28 -05:00
parent 77e0dbb42e
commit 9f4f8e79ce
3 changed files with 47 additions and 3 deletions

View File

@@ -1,3 +1,5 @@
use std::borrow::Cow;
use serde::Serialize;
use super::angle_link::WasmAngleLink;
@@ -58,6 +60,34 @@ 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<'s, str>,
#[serde(rename = "standard-properties")]
pub(crate) standard_properties: &'b 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)]
#[serde(untagged)]