diff --git a/src/compare/mod.rs b/src/compare/mod.rs index 5b1ab67..e5f8e98 100644 --- a/src/compare/mod.rs +++ b/src/compare/mod.rs @@ -16,8 +16,10 @@ pub(crate) use compare_field::EmacsField; pub(crate) use elisp_fact::ElispFact; pub use sexp::sexp; pub(crate) use sexp::unquote; +pub(crate) use sexp::TextWithProperties; pub use sexp::Token; pub(crate) use util::get_emacs_standard_properties; pub(crate) use util::get_property; pub(crate) use util::get_property_quoted_string; +pub(crate) use util::maybe_token_to_usize; pub(crate) use util::EmacsStandardProperties; diff --git a/src/compare/util.rs b/src/compare/util.rs index b22fe84..f0a0b03 100644 --- a/src/compare/util.rs +++ b/src/compare/util.rs @@ -203,7 +203,7 @@ pub(crate) fn get_emacs_standard_properties( }) } -fn maybe_token_to_usize( +pub(crate) fn maybe_token_to_usize( token: Option<&Token<'_>>, ) -> Result, Box> { Ok(token diff --git a/src/lib.rs b/src/lib.rs index 3a791a2..4924228 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -3,6 +3,7 @@ #![feature(path_file_prefix)] #![feature(is_sorted)] #![feature(test)] +#![feature(iter_intersperse)] // TODO: #![warn(missing_docs)] #![allow(clippy::bool_assert_comparison)] // Sometimes you want the long form because its easier to see at a glance. diff --git a/src/wasm/additional_property.rs b/src/wasm/additional_property.rs index 9680c6a..b754f14 100644 --- a/src/wasm/additional_property.rs +++ b/src/wasm/additional_property.rs @@ -1,5 +1,7 @@ +use std::borrow::Cow; use std::collections::HashMap; +use serde::Deserialize; use serde::Serialize; use super::macros::to_wasm; @@ -8,32 +10,35 @@ use super::WasmAstNode; use crate::types::AffiliatedKeywordValue; use crate::types::AffiliatedKeywords; -#[derive(Debug, Serialize)] +#[derive(Debug, Serialize, Deserialize)] #[serde(untagged)] -pub enum AdditionalPropertyValue<'s, 'p> { - SingleString(&'s str), - ListOfStrings(Vec<&'s str>), +pub enum AdditionalPropertyValue { + SingleString(String), + ListOfStrings(Vec), OptionalPair { - optval: Option<&'s str>, - val: &'s str, + optval: Option, + val: String, + }, + ObjectTree { + #[serde(rename = "object-tree")] + object_tree: Vec<(Option>, Vec)>, }, - ObjectTree(Vec<(Option>>, Vec>)>), } -#[derive(Debug, Serialize, Default)] -pub struct AdditionalProperties<'s, 'p> { +#[derive(Debug, Serialize, Deserialize, Default)] +pub struct AdditionalProperties { #[serde(flatten)] - pub(crate) properties: HashMap>, + pub(crate) properties: HashMap, } -impl<'s, 'p> AdditionalProperties<'s, 'p> { +impl AdditionalProperties { pub(crate) fn get_elisp_names<'c>(&'c self) -> impl Iterator + 'c { self.properties.keys().map(move |key| format!(":{}", key)) } } to_wasm!( - AdditionalProperties<'s, 'p>, + AdditionalProperties, AffiliatedKeywords<'s>, original, wasm_context, @@ -42,15 +47,17 @@ to_wasm!( for (name, val) in original.keywords.iter() { let converted_val = match val { AffiliatedKeywordValue::SingleString(val) => { - AdditionalPropertyValue::SingleString(val) + AdditionalPropertyValue::SingleString((*val).to_owned()) } AffiliatedKeywordValue::ListOfStrings(val) => { - AdditionalPropertyValue::ListOfStrings(val.clone()) + AdditionalPropertyValue::ListOfStrings( + val.iter().map(|s| (*s).to_owned()).collect(), + ) } AffiliatedKeywordValue::OptionalPair { optval, val } => { AdditionalPropertyValue::OptionalPair { - optval: optval.clone(), - val: val, + optval: optval.map(|s| (*s).to_owned()), + val: (*val).to_owned(), } } AffiliatedKeywordValue::ObjectTree(val) => { @@ -64,7 +71,7 @@ to_wasm!( .map(|child| { child .to_wasm(wasm_context.clone()) - .map(Into::>::into) + .map(Into::::into) }) .collect::, _>>()?, ) @@ -76,14 +83,14 @@ to_wasm!( .map(|child| { child .to_wasm(wasm_context.clone()) - .map(Into::>::into) + .map(Into::::into) }) .collect::, _>>()?; ret.push((converted_optval, converted_value)); } - AdditionalPropertyValue::ObjectTree(ret) + AdditionalPropertyValue::ObjectTree { object_tree: ret } } }; additional_properties diff --git a/src/wasm/angle_link.rs b/src/wasm/angle_link.rs index 4cd9b65..bb100eb 100644 --- a/src/wasm/angle_link.rs +++ b/src/wasm/angle_link.rs @@ -1,36 +1,33 @@ +use serde::Deserialize; use serde::Serialize; +use super::ast_node::WasmAstNode; use super::macros::to_wasm; -use super::standard_properties::WasmStandardProperties; use super::to_wasm::ToWasm; +use super::AdditionalProperties; +use crate::compare::ElispFact; use crate::types::AngleLink; use crate::wasm::to_wasm::ToWasmStandardProperties; -use crate::wasm::WasmAstNode; -#[derive(Debug, Serialize)] -#[serde(tag = "ast_node")] -#[serde(rename = "org-data")] -pub struct WasmAngleLink<'s, 'p> { - standard_properties: WasmStandardProperties, - children: Vec>, +#[derive(Debug, Serialize, Deserialize)] +pub struct WasmAngleLink { + #[serde(flatten)] + pub(crate) additional_properties: AdditionalProperties, } to_wasm!( - WasmAngleLink<'s, 'p>, + WasmAngleLink, AngleLink<'s>, original, wasm_context, - standard_properties, + { WasmAstNode::AngleLink(original) }, + { "TODO".into() }, { - Ok(WasmAngleLink { - standard_properties, - children: Vec::new(), - }) + Ok(( + Vec::new(), + WasmAngleLink { + additional_properties: AdditionalProperties::default(), + }, + )) } ); - -impl<'s, 'p> Into> for WasmAngleLink<'s, 'p> { - fn into(self) -> WasmAstNode<'s, 'p> { - WasmAstNode::AngleLink(self) - } -} diff --git a/src/wasm/ast_node.rs b/src/wasm/ast_node.rs index 8545b42..76b7f35 100644 --- a/src/wasm/ast_node.rs +++ b/src/wasm/ast_node.rs @@ -1,3 +1,4 @@ +use serde::Deserialize; use serde::Serialize; use super::angle_link::WasmAngleLink; @@ -58,71 +59,84 @@ use super::timestamp::WasmTimestamp; use super::underline::WasmUnderline; use super::verbatim::WasmVerbatim; use super::verse_block::WasmVerseBlock; +use super::WasmStandardProperties; -#[derive(Debug, Serialize)] -#[serde(untagged)] -pub enum WasmAstNode<'s, 'p> { - // Document Nodes - Document(WasmDocument<'s, 'p>), - Headline(WasmHeadline<'s, 'p>), - Section(WasmSection<'s, 'p>), - // Elements - Paragraph(WasmParagraph<'s, 'p>), - PlainList(WasmPlainList<'s, 'p>), - PlainListItem(WasmPlainListItem<'s, 'p>), - CenterBlock(WasmCenterBlock<'s, 'p>), - QuoteBlock(WasmQuoteBlock<'s, 'p>), - SpecialBlock(WasmSpecialBlock<'s, 'p>), - DynamicBlock(WasmDynamicBlock<'s, 'p>), - FootnoteDefinition(WasmFootnoteDefinition<'s, 'p>), - Comment(WasmComment<'s, 'p>), - Drawer(WasmDrawer<'s, 'p>), - PropertyDrawer(WasmPropertyDrawer<'s, 'p>), - NodeProperty(WasmNodeProperty<'s, 'p>), - Table(WasmTable<'s, 'p>), - TableRow(WasmTableRow<'s, 'p>), - VerseBlock(WasmVerseBlock<'s, 'p>), - CommentBlock(WasmCommentBlock<'s, 'p>), - ExampleBlock(WasmExampleBlock<'s, 'p>), - ExportBlock(WasmExportBlock<'s, 'p>), - SrcBlock(WasmSrcBlock<'s, 'p>), - Clock(WasmClock<'s, 'p>), - DiarySexp(WasmDiarySexp<'s, 'p>), - Planning(WasmPlanning<'s, 'p>), - FixedWidthArea(WasmFixedWidthArea<'s, 'p>), - HorizontalRule(WasmHorizontalRule<'s, 'p>), - Keyword(WasmKeyword<'s, 'p>), - BabelCall(WasmBabelCall<'s, 'p>), - LatexEnvironment(WasmLatexEnvironment<'s, 'p>), - // Objects - Bold(WasmBold<'s, 'p>), - Italic(WasmItalic<'s, 'p>), - Underline(WasmUnderline<'s, 'p>), - StrikeThrough(WasmStrikeThrough<'s, 'p>), - Code(WasmCode<'s, 'p>), - Verbatim(WasmVerbatim<'s, 'p>), - PlainText(WasmPlainText<'s, 'p>), - RegularLink(WasmRegularLink<'s, 'p>), - RadioLink(WasmRadioLink<'s, 'p>), - RadioTarget(WasmRadioTarget<'s, 'p>), - PlainLink(WasmPlainLink<'s, 'p>), - AngleLink(WasmAngleLink<'s, 'p>), - OrgMacro(WasmOrgMacro<'s, 'p>), - Entity(WasmEntity<'s, 'p>), - LatexFragment(WasmLatexFragment<'s, 'p>), - ExportSnippet(WasmExportSnippet<'s, 'p>), - FootnoteReference(WasmFootnoteReference<'s, 'p>), - Citation(WasmCitation<'s, 'p>), - CitationReference(WasmCitationReference<'s, 'p>), - InlineBabelCall(WasmInlineBabelCall<'s, 'p>), - InlineSourceBlock(WasmInlineSourceBlock<'s, 'p>), - LineBreak(WasmLineBreak<'s, 'p>), - Target(WasmTarget<'s, 'p>), - StatisticsCookie(WasmStatisticsCookie<'s, 'p>), - Subscript(WasmSubscript<'s, 'p>), - Superscript(WasmSuperscript<'s, 'p>), - TableCell(WasmTableCell<'s, 'p>), - Timestamp(WasmTimestamp<'s, 'p>), +#[derive(Debug, Serialize, Deserialize)] +pub struct WasmAstNodeWrapper { + #[serde(rename = "ast-node")] + pub(crate) ast_node: String, + #[serde(rename = "standard-properties")] + pub(crate) standard_properties: WasmStandardProperties, + #[serde(rename = "children")] + pub(crate) children: Vec, + #[serde(rename = "properties")] + pub(crate) properties: I, } -impl<'s, 'p> WasmAstNode<'s, 'p> {} +#[derive(Debug, Serialize, Deserialize)] +#[serde(untagged)] +pub enum WasmAstNode { + // Document Nodes + Document(WasmAstNodeWrapper), + Headline(WasmAstNodeWrapper), + Section(WasmAstNodeWrapper), + // Elements + Paragraph(WasmAstNodeWrapper), + PlainList(WasmAstNodeWrapper), + PlainListItem(WasmAstNodeWrapper), + CenterBlock(WasmAstNodeWrapper), + QuoteBlock(WasmAstNodeWrapper), + SpecialBlock(WasmAstNodeWrapper), + DynamicBlock(WasmAstNodeWrapper), + FootnoteDefinition(WasmAstNodeWrapper), + Comment(WasmAstNodeWrapper), + Drawer(WasmAstNodeWrapper), + PropertyDrawer(WasmAstNodeWrapper), + NodeProperty(WasmAstNodeWrapper), + Table(WasmAstNodeWrapper), + TableRow(WasmAstNodeWrapper), + VerseBlock(WasmAstNodeWrapper), + CommentBlock(WasmAstNodeWrapper), + ExampleBlock(WasmAstNodeWrapper), + ExportBlock(WasmAstNodeWrapper), + SrcBlock(WasmAstNodeWrapper), + Clock(WasmAstNodeWrapper), + DiarySexp(WasmAstNodeWrapper), + Planning(WasmAstNodeWrapper), + FixedWidthArea(WasmAstNodeWrapper), + HorizontalRule(WasmAstNodeWrapper), + Keyword(WasmAstNodeWrapper), + BabelCall(WasmAstNodeWrapper), + LatexEnvironment(WasmAstNodeWrapper), + // Objects + Bold(WasmAstNodeWrapper), + Italic(WasmAstNodeWrapper), + Underline(WasmAstNodeWrapper), + StrikeThrough(WasmAstNodeWrapper), + Code(WasmAstNodeWrapper), + Verbatim(WasmAstNodeWrapper), + PlainText(WasmAstNodeWrapper), + RegularLink(WasmAstNodeWrapper), + RadioLink(WasmAstNodeWrapper), + RadioTarget(WasmAstNodeWrapper), + PlainLink(WasmAstNodeWrapper), + AngleLink(WasmAstNodeWrapper), + OrgMacro(WasmAstNodeWrapper), + Entity(WasmAstNodeWrapper), + LatexFragment(WasmAstNodeWrapper), + ExportSnippet(WasmAstNodeWrapper), + FootnoteReference(WasmAstNodeWrapper), + Citation(WasmAstNodeWrapper), + CitationReference(WasmAstNodeWrapper), + InlineBabelCall(WasmAstNodeWrapper), + InlineSourceBlock(WasmAstNodeWrapper), + LineBreak(WasmAstNodeWrapper), + Target(WasmAstNodeWrapper), + StatisticsCookie(WasmAstNodeWrapper), + Subscript(WasmAstNodeWrapper), + Superscript(WasmAstNodeWrapper), + TableCell(WasmAstNodeWrapper), + Timestamp(WasmAstNodeWrapper), +} + +impl WasmAstNode {} diff --git a/src/wasm/babel_call.rs b/src/wasm/babel_call.rs index e88cea7..56746f7 100644 --- a/src/wasm/babel_call.rs +++ b/src/wasm/babel_call.rs @@ -1,36 +1,33 @@ +use serde::Deserialize; use serde::Serialize; +use super::ast_node::WasmAstNode; use super::macros::to_wasm; -use super::standard_properties::WasmStandardProperties; use super::to_wasm::ToWasm; +use super::AdditionalProperties; +use crate::compare::ElispFact; use crate::types::BabelCall; use crate::wasm::to_wasm::ToWasmStandardProperties; -use crate::wasm::WasmAstNode; -#[derive(Debug, Serialize)] -#[serde(tag = "ast_node")] -#[serde(rename = "org-data")] -pub struct WasmBabelCall<'s, 'p> { - standard_properties: WasmStandardProperties, - children: Vec>, +#[derive(Debug, Serialize, Deserialize)] +pub struct WasmBabelCall { + #[serde(flatten)] + pub(crate) additional_properties: AdditionalProperties, } to_wasm!( - WasmBabelCall<'s, 'p>, + WasmBabelCall, BabelCall<'s>, original, wasm_context, - standard_properties, + { WasmAstNode::BabelCall(original) }, + { "TODO".into() }, { - Ok(WasmBabelCall { - standard_properties, - children: Vec::new(), - }) + Ok(( + Vec::new(), + WasmBabelCall { + additional_properties: AdditionalProperties::default(), + }, + )) } ); - -impl<'s, 'p> Into> for WasmBabelCall<'s, 'p> { - fn into(self) -> WasmAstNode<'s, 'p> { - WasmAstNode::BabelCall(self) - } -} diff --git a/src/wasm/bold.rs b/src/wasm/bold.rs index fdb3be6..9ca857b 100644 --- a/src/wasm/bold.rs +++ b/src/wasm/bold.rs @@ -1,36 +1,43 @@ +use serde::Deserialize; use serde::Serialize; +use super::ast_node::WasmAstNode; use super::macros::to_wasm; -use super::standard_properties::WasmStandardProperties; use super::to_wasm::ToWasm; +use super::AdditionalProperties; +use crate::compare::ElispFact; use crate::types::Bold; use crate::wasm::to_wasm::ToWasmStandardProperties; -use crate::wasm::WasmAstNode; -#[derive(Debug, Serialize)] -#[serde(tag = "ast_node")] -#[serde(rename = "org-data")] -pub struct WasmBold<'s, 'p> { - standard_properties: WasmStandardProperties, - children: Vec>, +#[derive(Debug, Serialize, Deserialize)] +pub struct WasmBold { + #[serde(flatten)] + pub(crate) additional_properties: AdditionalProperties, } to_wasm!( - WasmBold<'s, 'p>, + WasmBold, Bold<'s>, original, wasm_context, - standard_properties, + { WasmAstNode::Bold(original) }, + { "TODO".into() }, { - Ok(WasmBold { - standard_properties, - children: Vec::new(), - }) + let children = original + .children + .iter() + .map(|child| { + child + .to_wasm(wasm_context.clone()) + .map(Into::::into) + }) + .collect::, _>>()?; + + Ok(( + children, + WasmBold { + additional_properties: AdditionalProperties::default(), + }, + )) } ); - -impl<'s, 'p> Into> for WasmBold<'s, 'p> { - fn into(self) -> WasmAstNode<'s, 'p> { - WasmAstNode::Bold(self) - } -} diff --git a/src/wasm/center_block.rs b/src/wasm/center_block.rs index 3f9c80f..9895e80 100644 --- a/src/wasm/center_block.rs +++ b/src/wasm/center_block.rs @@ -1,36 +1,43 @@ +use serde::Deserialize; use serde::Serialize; +use super::ast_node::WasmAstNode; use super::macros::to_wasm; -use super::standard_properties::WasmStandardProperties; use super::to_wasm::ToWasm; +use super::AdditionalProperties; +use crate::compare::ElispFact; use crate::types::CenterBlock; use crate::wasm::to_wasm::ToWasmStandardProperties; -use crate::wasm::WasmAstNode; -#[derive(Debug, Serialize)] -#[serde(tag = "ast_node")] -#[serde(rename = "org-data")] -pub struct WasmCenterBlock<'s, 'p> { - standard_properties: WasmStandardProperties, - children: Vec>, +#[derive(Debug, Serialize, Deserialize)] +pub struct WasmCenterBlock { + #[serde(flatten)] + pub(crate) additional_properties: AdditionalProperties, } to_wasm!( - WasmCenterBlock<'s, 'p>, + WasmCenterBlock, CenterBlock<'s>, original, wasm_context, - standard_properties, + { WasmAstNode::CenterBlock(original) }, + { "TODO".into() }, { - Ok(WasmCenterBlock { - standard_properties, - children: Vec::new(), - }) + let children = original + .children + .iter() + .map(|child| { + child + .to_wasm(wasm_context.clone()) + .map(Into::::into) + }) + .collect::, _>>()?; + + Ok(( + children, + WasmCenterBlock { + additional_properties: AdditionalProperties::default(), + }, + )) } ); - -impl<'s, 'p> Into> for WasmCenterBlock<'s, 'p> { - fn into(self) -> WasmAstNode<'s, 'p> { - WasmAstNode::CenterBlock(self) - } -} diff --git a/src/wasm/citation.rs b/src/wasm/citation.rs index 1622950..a92b73c 100644 --- a/src/wasm/citation.rs +++ b/src/wasm/citation.rs @@ -1,36 +1,43 @@ +use serde::Deserialize; use serde::Serialize; +use super::ast_node::WasmAstNode; use super::macros::to_wasm; -use super::standard_properties::WasmStandardProperties; use super::to_wasm::ToWasm; +use super::AdditionalProperties; +use crate::compare::ElispFact; use crate::types::Citation; use crate::wasm::to_wasm::ToWasmStandardProperties; -use crate::wasm::WasmAstNode; -#[derive(Debug, Serialize)] -#[serde(tag = "ast_node")] -#[serde(rename = "org-data")] -pub struct WasmCitation<'s, 'p> { - standard_properties: WasmStandardProperties, - children: Vec>, +#[derive(Debug, Serialize, Deserialize)] +pub struct WasmCitation { + #[serde(flatten)] + pub(crate) additional_properties: AdditionalProperties, } to_wasm!( - WasmCitation<'s, 'p>, + WasmCitation, Citation<'s>, original, wasm_context, - standard_properties, + { WasmAstNode::Citation(original) }, + { "TODO".into() }, { - Ok(WasmCitation { - standard_properties, - children: Vec::new(), - }) + let children = original + .children + .iter() + .map(|child| { + child + .to_wasm(wasm_context.clone()) + .map(Into::::into) + }) + .collect::, _>>()?; + + Ok(( + children, + WasmCitation { + additional_properties: AdditionalProperties::default(), + }, + )) } ); - -impl<'s, 'p> Into> for WasmCitation<'s, 'p> { - fn into(self) -> WasmAstNode<'s, 'p> { - WasmAstNode::Citation(self) - } -} diff --git a/src/wasm/citation_reference.rs b/src/wasm/citation_reference.rs index 0950e55..bb9e18f 100644 --- a/src/wasm/citation_reference.rs +++ b/src/wasm/citation_reference.rs @@ -1,36 +1,33 @@ +use serde::Deserialize; use serde::Serialize; +use super::ast_node::WasmAstNode; use super::macros::to_wasm; -use super::standard_properties::WasmStandardProperties; use super::to_wasm::ToWasm; +use super::AdditionalProperties; +use crate::compare::ElispFact; use crate::types::CitationReference; use crate::wasm::to_wasm::ToWasmStandardProperties; -use crate::wasm::WasmAstNode; -#[derive(Debug, Serialize)] -#[serde(tag = "ast_node")] -#[serde(rename = "org-data")] -pub struct WasmCitationReference<'s, 'p> { - standard_properties: WasmStandardProperties, - children: Vec>, +#[derive(Debug, Serialize, Deserialize)] +pub struct WasmCitationReference { + #[serde(flatten)] + pub(crate) additional_properties: AdditionalProperties, } to_wasm!( - WasmCitationReference<'s, 'p>, + WasmCitationReference, CitationReference<'s>, original, wasm_context, - standard_properties, + { WasmAstNode::CitationReference(original) }, + { "TODO".into() }, { - Ok(WasmCitationReference { - standard_properties, - children: Vec::new(), - }) + Ok(( + Vec::new(), + WasmCitationReference { + additional_properties: AdditionalProperties::default(), + }, + )) } ); - -impl<'s, 'p> Into> for WasmCitationReference<'s, 'p> { - fn into(self) -> WasmAstNode<'s, 'p> { - WasmAstNode::CitationReference(self) - } -} diff --git a/src/wasm/clock.rs b/src/wasm/clock.rs index d0cbae9..acc2e78 100644 --- a/src/wasm/clock.rs +++ b/src/wasm/clock.rs @@ -1,36 +1,33 @@ +use serde::Deserialize; use serde::Serialize; +use super::ast_node::WasmAstNode; use super::macros::to_wasm; -use super::standard_properties::WasmStandardProperties; use super::to_wasm::ToWasm; +use super::AdditionalProperties; +use crate::compare::ElispFact; use crate::types::Clock; use crate::wasm::to_wasm::ToWasmStandardProperties; -use crate::wasm::WasmAstNode; -#[derive(Debug, Serialize)] -#[serde(tag = "ast_node")] -#[serde(rename = "org-data")] -pub struct WasmClock<'s, 'p> { - standard_properties: WasmStandardProperties, - children: Vec>, +#[derive(Debug, Serialize, Deserialize)] +pub struct WasmClock { + #[serde(flatten)] + pub(crate) additional_properties: AdditionalProperties, } to_wasm!( - WasmClock<'s, 'p>, + WasmClock, Clock<'s>, original, wasm_context, - standard_properties, + { WasmAstNode::Clock(original) }, + { "TODO".into() }, { - Ok(WasmClock { - standard_properties, - children: Vec::new(), - }) + Ok(( + Vec::new(), + WasmClock { + additional_properties: AdditionalProperties::default(), + }, + )) } ); - -impl<'s, 'p> Into> for WasmClock<'s, 'p> { - fn into(self) -> WasmAstNode<'s, 'p> { - WasmAstNode::Clock(self) - } -} diff --git a/src/wasm/code.rs b/src/wasm/code.rs index be0ee6b..e191116 100644 --- a/src/wasm/code.rs +++ b/src/wasm/code.rs @@ -1,36 +1,33 @@ +use serde::Deserialize; use serde::Serialize; +use super::ast_node::WasmAstNode; use super::macros::to_wasm; -use super::standard_properties::WasmStandardProperties; use super::to_wasm::ToWasm; +use super::AdditionalProperties; +use crate::compare::ElispFact; use crate::types::Code; use crate::wasm::to_wasm::ToWasmStandardProperties; -use crate::wasm::WasmAstNode; -#[derive(Debug, Serialize)] -#[serde(tag = "ast_node")] -#[serde(rename = "org-data")] -pub struct WasmCode<'s, 'p> { - standard_properties: WasmStandardProperties, - children: Vec>, +#[derive(Debug, Serialize, Deserialize)] +pub struct WasmCode { + #[serde(flatten)] + pub(crate) additional_properties: AdditionalProperties, } to_wasm!( - WasmCode<'s, 'p>, + WasmCode, Code<'s>, original, wasm_context, - standard_properties, + { WasmAstNode::Code(original) }, + { "TODO".into() }, { - Ok(WasmCode { - standard_properties, - children: Vec::new(), - }) + Ok(( + Vec::new(), + WasmCode { + additional_properties: AdditionalProperties::default(), + }, + )) } ); - -impl<'s, 'p> Into> for WasmCode<'s, 'p> { - fn into(self) -> WasmAstNode<'s, 'p> { - WasmAstNode::Code(self) - } -} diff --git a/src/wasm/comment.rs b/src/wasm/comment.rs index 029f6b1..c73f138 100644 --- a/src/wasm/comment.rs +++ b/src/wasm/comment.rs @@ -1,36 +1,33 @@ +use serde::Deserialize; use serde::Serialize; +use super::ast_node::WasmAstNode; use super::macros::to_wasm; -use super::standard_properties::WasmStandardProperties; use super::to_wasm::ToWasm; +use super::AdditionalProperties; +use crate::compare::ElispFact; use crate::types::Comment; use crate::wasm::to_wasm::ToWasmStandardProperties; -use crate::wasm::WasmAstNode; -#[derive(Debug, Serialize)] -#[serde(tag = "ast_node")] -#[serde(rename = "org-data")] -pub struct WasmComment<'s, 'p> { - standard_properties: WasmStandardProperties, - children: Vec>, +#[derive(Debug, Serialize, Deserialize)] +pub struct WasmComment { + #[serde(flatten)] + pub(crate) additional_properties: AdditionalProperties, } to_wasm!( - WasmComment<'s, 'p>, + WasmComment, Comment<'s>, original, wasm_context, - standard_properties, + { WasmAstNode::Comment(original) }, + { "TODO".into() }, { - Ok(WasmComment { - standard_properties, - children: Vec::new(), - }) + Ok(( + Vec::new(), + WasmComment { + additional_properties: AdditionalProperties::default(), + }, + )) } ); - -impl<'s, 'p> Into> for WasmComment<'s, 'p> { - fn into(self) -> WasmAstNode<'s, 'p> { - WasmAstNode::Comment(self) - } -} diff --git a/src/wasm/comment_block.rs b/src/wasm/comment_block.rs index 7a51e71..a04c593 100644 --- a/src/wasm/comment_block.rs +++ b/src/wasm/comment_block.rs @@ -1,36 +1,33 @@ +use serde::Deserialize; use serde::Serialize; +use super::ast_node::WasmAstNode; use super::macros::to_wasm; -use super::standard_properties::WasmStandardProperties; use super::to_wasm::ToWasm; +use super::AdditionalProperties; +use crate::compare::ElispFact; use crate::types::CommentBlock; use crate::wasm::to_wasm::ToWasmStandardProperties; -use crate::wasm::WasmAstNode; -#[derive(Debug, Serialize)] -#[serde(tag = "ast_node")] -#[serde(rename = "org-data")] -pub struct WasmCommentBlock<'s, 'p> { - standard_properties: WasmStandardProperties, - children: Vec>, +#[derive(Debug, Serialize, Deserialize)] +pub struct WasmCommentBlock { + #[serde(flatten)] + pub(crate) additional_properties: AdditionalProperties, } to_wasm!( - WasmCommentBlock<'s, 'p>, + WasmCommentBlock, CommentBlock<'s>, original, wasm_context, - standard_properties, + { WasmAstNode::CommentBlock(original) }, + { "TODO".into() }, { - Ok(WasmCommentBlock { - standard_properties, - children: Vec::new(), - }) + Ok(( + Vec::new(), + WasmCommentBlock { + additional_properties: AdditionalProperties::default(), + }, + )) } ); - -impl<'s, 'p> Into> for WasmCommentBlock<'s, 'p> { - fn into(self) -> WasmAstNode<'s, 'p> { - WasmAstNode::CommentBlock(self) - } -} diff --git a/src/wasm/diary_sexp.rs b/src/wasm/diary_sexp.rs index f96e5ab..7029077 100644 --- a/src/wasm/diary_sexp.rs +++ b/src/wasm/diary_sexp.rs @@ -1,36 +1,33 @@ +use serde::Deserialize; use serde::Serialize; +use super::ast_node::WasmAstNode; use super::macros::to_wasm; -use super::standard_properties::WasmStandardProperties; use super::to_wasm::ToWasm; +use super::AdditionalProperties; +use crate::compare::ElispFact; use crate::types::DiarySexp; use crate::wasm::to_wasm::ToWasmStandardProperties; -use crate::wasm::WasmAstNode; -#[derive(Debug, Serialize)] -#[serde(tag = "ast_node")] -#[serde(rename = "org-data")] -pub struct WasmDiarySexp<'s, 'p> { - standard_properties: WasmStandardProperties, - children: Vec>, +#[derive(Debug, Serialize, Deserialize)] +pub struct WasmDiarySexp { + #[serde(flatten)] + pub(crate) additional_properties: AdditionalProperties, } to_wasm!( - WasmDiarySexp<'s, 'p>, + WasmDiarySexp, DiarySexp<'s>, original, wasm_context, - standard_properties, + { WasmAstNode::DiarySexp(original) }, + { "TODO".into() }, { - Ok(WasmDiarySexp { - standard_properties, - children: Vec::new(), - }) + Ok(( + Vec::new(), + WasmDiarySexp { + additional_properties: AdditionalProperties::default(), + }, + )) } ); - -impl<'s, 'p> Into> for WasmDiarySexp<'s, 'p> { - fn into(self) -> WasmAstNode<'s, 'p> { - WasmAstNode::DiarySexp(self) - } -} diff --git a/src/wasm/document.rs b/src/wasm/document.rs index df49157..dc75c0e 100644 --- a/src/wasm/document.rs +++ b/src/wasm/document.rs @@ -1,36 +1,33 @@ use std::path::PathBuf; +use serde::Deserialize; use serde::Serialize; use super::additional_property::AdditionalProperties; use super::additional_property::AdditionalPropertyValue; use super::ast_node::WasmAstNode; use super::macros::to_wasm; -use super::standard_properties::WasmStandardProperties; use super::to_wasm::ToWasm; -#[cfg(feature = "wasm_test")] use crate::compare::ElispFact; use crate::types::Document; use crate::wasm::to_wasm::ToWasmStandardProperties; -#[derive(Debug, Serialize)] -#[serde(tag = "ast_node")] -#[serde(rename = "org-data")] -pub struct WasmDocument<'s, 'p> { - pub(crate) standard_properties: WasmStandardProperties, +#[derive(Debug, Serialize, Deserialize)] +pub struct WasmDocument { #[serde(flatten)] - pub(crate) additional_properties: AdditionalProperties<'s, 'p>, - pub(crate) children: Vec>, - pub(crate) category: Option<&'p str>, + pub(crate) additional_properties: AdditionalProperties, + #[serde(rename = "CATEGORY")] + pub(crate) category: Option, pub(crate) path: Option, } to_wasm!( - WasmDocument<'s, 'p>, + WasmDocument, Document<'s>, original, wasm_context, - standard_properties, + { WasmAstNode::Document(original) }, + { "org-data".into() }, { let category = original.category.as_ref().map(String::as_str); let path = original.path.clone(); @@ -39,7 +36,7 @@ to_wasm!( for (name, val) in original.get_additional_properties().map(|node_property| { ( node_property.property_name.to_uppercase(), - AdditionalPropertyValue::SingleString(node_property.value.unwrap_or("")), + AdditionalPropertyValue::SingleString(node_property.value.unwrap_or("").to_owned()), ) }) { additional_properties.properties.insert(name, val); @@ -51,34 +48,22 @@ to_wasm!( .map(|child| { child .to_wasm(wasm_context.clone()) - .map(Into::>::into) + .map(Into::::into) }) .chain(original.children.iter().map(|child| { child .to_wasm(wasm_context.clone()) - .map(Into::>::into) + .map(Into::::into) })) .collect::, _>>()?; - Ok(WasmDocument { - standard_properties, - additional_properties, + Ok(( children, - category, - path, - }) + WasmDocument { + additional_properties, + category: category.map(str::to_owned), + path, + }, + )) } ); - -impl<'s, 'p> Into> for WasmDocument<'s, 'p> { - fn into(self) -> WasmAstNode<'s, 'p> { - WasmAstNode::Document(self) - } -} - -#[cfg(feature = "wasm_test")] -impl<'s, 'p> ElispFact<'s> for WasmDocument<'s, 'p> { - fn get_elisp_name<'b>(&'b self) -> std::borrow::Cow<'s, str> { - "org-data".into() - } -} diff --git a/src/wasm/drawer.rs b/src/wasm/drawer.rs index 2375a2b..b76292d 100644 --- a/src/wasm/drawer.rs +++ b/src/wasm/drawer.rs @@ -1,36 +1,43 @@ +use serde::Deserialize; use serde::Serialize; +use super::ast_node::WasmAstNode; use super::macros::to_wasm; -use super::standard_properties::WasmStandardProperties; use super::to_wasm::ToWasm; +use super::AdditionalProperties; +use crate::compare::ElispFact; use crate::types::Drawer; use crate::wasm::to_wasm::ToWasmStandardProperties; -use crate::wasm::WasmAstNode; -#[derive(Debug, Serialize)] -#[serde(tag = "ast_node")] -#[serde(rename = "org-data")] -pub struct WasmDrawer<'s, 'p> { - standard_properties: WasmStandardProperties, - children: Vec>, +#[derive(Debug, Serialize, Deserialize)] +pub struct WasmDrawer { + #[serde(flatten)] + pub(crate) additional_properties: AdditionalProperties, } to_wasm!( - WasmDrawer<'s, 'p>, + WasmDrawer, Drawer<'s>, original, wasm_context, - standard_properties, + { WasmAstNode::Drawer(original) }, + { "TODO".into() }, { - Ok(WasmDrawer { - standard_properties, - children: Vec::new(), - }) + let children = original + .children + .iter() + .map(|child| { + child + .to_wasm(wasm_context.clone()) + .map(Into::::into) + }) + .collect::, _>>()?; + + Ok(( + children, + WasmDrawer { + additional_properties: AdditionalProperties::default(), + }, + )) } ); - -impl<'s, 'p> Into> for WasmDrawer<'s, 'p> { - fn into(self) -> WasmAstNode<'s, 'p> { - WasmAstNode::Drawer(self) - } -} diff --git a/src/wasm/dynamic_block.rs b/src/wasm/dynamic_block.rs index 9508a51..3b4f1ac 100644 --- a/src/wasm/dynamic_block.rs +++ b/src/wasm/dynamic_block.rs @@ -1,36 +1,43 @@ +use serde::Deserialize; use serde::Serialize; +use super::ast_node::WasmAstNode; use super::macros::to_wasm; -use super::standard_properties::WasmStandardProperties; use super::to_wasm::ToWasm; +use super::AdditionalProperties; +use crate::compare::ElispFact; use crate::types::DynamicBlock; use crate::wasm::to_wasm::ToWasmStandardProperties; -use crate::wasm::WasmAstNode; -#[derive(Debug, Serialize)] -#[serde(tag = "ast_node")] -#[serde(rename = "org-data")] -pub struct WasmDynamicBlock<'s, 'p> { - standard_properties: WasmStandardProperties, - children: Vec>, +#[derive(Debug, Serialize, Deserialize)] +pub struct WasmDynamicBlock { + #[serde(flatten)] + pub(crate) additional_properties: AdditionalProperties, } to_wasm!( - WasmDynamicBlock<'s, 'p>, + WasmDynamicBlock, DynamicBlock<'s>, original, wasm_context, - standard_properties, + { WasmAstNode::DynamicBlock(original) }, + { "TODO".into() }, { - Ok(WasmDynamicBlock { - standard_properties, - children: Vec::new(), - }) + let children = original + .children + .iter() + .map(|child| { + child + .to_wasm(wasm_context.clone()) + .map(Into::::into) + }) + .collect::, _>>()?; + + Ok(( + children, + WasmDynamicBlock { + additional_properties: AdditionalProperties::default(), + }, + )) } ); - -impl<'s, 'p> Into> for WasmDynamicBlock<'s, 'p> { - fn into(self) -> WasmAstNode<'s, 'p> { - WasmAstNode::DynamicBlock(self) - } -} diff --git a/src/wasm/entity.rs b/src/wasm/entity.rs index 3a5b318..112e0e4 100644 --- a/src/wasm/entity.rs +++ b/src/wasm/entity.rs @@ -1,36 +1,33 @@ +use serde::Deserialize; use serde::Serialize; +use super::ast_node::WasmAstNode; use super::macros::to_wasm; -use super::standard_properties::WasmStandardProperties; use super::to_wasm::ToWasm; +use super::AdditionalProperties; +use crate::compare::ElispFact; use crate::types::Entity; use crate::wasm::to_wasm::ToWasmStandardProperties; -use crate::wasm::WasmAstNode; -#[derive(Debug, Serialize)] -#[serde(tag = "ast_node")] -#[serde(rename = "org-data")] -pub struct WasmEntity<'s, 'p> { - standard_properties: WasmStandardProperties, - children: Vec>, +#[derive(Debug, Serialize, Deserialize)] +pub struct WasmEntity { + #[serde(flatten)] + pub(crate) additional_properties: AdditionalProperties, } to_wasm!( - WasmEntity<'s, 'p>, + WasmEntity, Entity<'s>, original, wasm_context, - standard_properties, + { WasmAstNode::Entity(original) }, + { "TODO".into() }, { - Ok(WasmEntity { - standard_properties, - children: Vec::new(), - }) + Ok(( + Vec::new(), + WasmEntity { + additional_properties: AdditionalProperties::default(), + }, + )) } ); - -impl<'s, 'p> Into> for WasmEntity<'s, 'p> { - fn into(self) -> WasmAstNode<'s, 'p> { - WasmAstNode::Entity(self) - } -} diff --git a/src/wasm/example_block.rs b/src/wasm/example_block.rs index 7537c56..7c3fb9c 100644 --- a/src/wasm/example_block.rs +++ b/src/wasm/example_block.rs @@ -1,36 +1,33 @@ +use serde::Deserialize; use serde::Serialize; +use super::ast_node::WasmAstNode; use super::macros::to_wasm; -use super::standard_properties::WasmStandardProperties; use super::to_wasm::ToWasm; +use super::AdditionalProperties; +use crate::compare::ElispFact; use crate::types::ExampleBlock; use crate::wasm::to_wasm::ToWasmStandardProperties; -use crate::wasm::WasmAstNode; -#[derive(Debug, Serialize)] -#[serde(tag = "ast_node")] -#[serde(rename = "org-data")] -pub struct WasmExampleBlock<'s, 'p> { - standard_properties: WasmStandardProperties, - children: Vec>, +#[derive(Debug, Serialize, Deserialize)] +pub struct WasmExampleBlock { + #[serde(flatten)] + pub(crate) additional_properties: AdditionalProperties, } to_wasm!( - WasmExampleBlock<'s, 'p>, + WasmExampleBlock, ExampleBlock<'s>, original, wasm_context, - standard_properties, + { WasmAstNode::ExampleBlock(original) }, + { "TODO".into() }, { - Ok(WasmExampleBlock { - standard_properties, - children: Vec::new(), - }) + Ok(( + Vec::new(), + WasmExampleBlock { + additional_properties: AdditionalProperties::default(), + }, + )) } ); - -impl<'s, 'p> Into> for WasmExampleBlock<'s, 'p> { - fn into(self) -> WasmAstNode<'s, 'p> { - WasmAstNode::ExampleBlock(self) - } -} diff --git a/src/wasm/export_block.rs b/src/wasm/export_block.rs index 5eb3f20..3fe8828 100644 --- a/src/wasm/export_block.rs +++ b/src/wasm/export_block.rs @@ -1,36 +1,33 @@ +use serde::Deserialize; use serde::Serialize; +use super::ast_node::WasmAstNode; use super::macros::to_wasm; -use super::standard_properties::WasmStandardProperties; use super::to_wasm::ToWasm; +use super::AdditionalProperties; +use crate::compare::ElispFact; use crate::types::ExportBlock; use crate::wasm::to_wasm::ToWasmStandardProperties; -use crate::wasm::WasmAstNode; -#[derive(Debug, Serialize)] -#[serde(tag = "ast_node")] -#[serde(rename = "org-data")] -pub struct WasmExportBlock<'s, 'p> { - standard_properties: WasmStandardProperties, - children: Vec>, +#[derive(Debug, Serialize, Deserialize)] +pub struct WasmExportBlock { + #[serde(flatten)] + pub(crate) additional_properties: AdditionalProperties, } to_wasm!( - WasmExportBlock<'s, 'p>, + WasmExportBlock, ExportBlock<'s>, original, wasm_context, - standard_properties, + { WasmAstNode::ExportBlock(original) }, + { "TODO".into() }, { - Ok(WasmExportBlock { - standard_properties, - children: Vec::new(), - }) + Ok(( + Vec::new(), + WasmExportBlock { + additional_properties: AdditionalProperties::default(), + }, + )) } ); - -impl<'s, 'p> Into> for WasmExportBlock<'s, 'p> { - fn into(self) -> WasmAstNode<'s, 'p> { - WasmAstNode::ExportBlock(self) - } -} diff --git a/src/wasm/export_snippet.rs b/src/wasm/export_snippet.rs index 4890edb..ef03374 100644 --- a/src/wasm/export_snippet.rs +++ b/src/wasm/export_snippet.rs @@ -1,36 +1,33 @@ +use serde::Deserialize; use serde::Serialize; +use super::ast_node::WasmAstNode; use super::macros::to_wasm; -use super::standard_properties::WasmStandardProperties; use super::to_wasm::ToWasm; +use super::AdditionalProperties; +use crate::compare::ElispFact; use crate::types::ExportSnippet; use crate::wasm::to_wasm::ToWasmStandardProperties; -use crate::wasm::WasmAstNode; -#[derive(Debug, Serialize)] -#[serde(tag = "ast_node")] -#[serde(rename = "org-data")] -pub struct WasmExportSnippet<'s, 'p> { - standard_properties: WasmStandardProperties, - children: Vec>, +#[derive(Debug, Serialize, Deserialize)] +pub struct WasmExportSnippet { + #[serde(flatten)] + pub(crate) additional_properties: AdditionalProperties, } to_wasm!( - WasmExportSnippet<'s, 'p>, + WasmExportSnippet, ExportSnippet<'s>, original, wasm_context, - standard_properties, + { WasmAstNode::ExportSnippet(original) }, + { "TODO".into() }, { - Ok(WasmExportSnippet { - standard_properties, - children: Vec::new(), - }) + Ok(( + Vec::new(), + WasmExportSnippet { + additional_properties: AdditionalProperties::default(), + }, + )) } ); - -impl<'s, 'p> Into> for WasmExportSnippet<'s, 'p> { - fn into(self) -> WasmAstNode<'s, 'p> { - WasmAstNode::ExportSnippet(self) - } -} diff --git a/src/wasm/fixed_width_area.rs b/src/wasm/fixed_width_area.rs index b21178f..8c29e8f 100644 --- a/src/wasm/fixed_width_area.rs +++ b/src/wasm/fixed_width_area.rs @@ -1,36 +1,33 @@ +use serde::Deserialize; use serde::Serialize; +use super::ast_node::WasmAstNode; use super::macros::to_wasm; -use super::standard_properties::WasmStandardProperties; use super::to_wasm::ToWasm; +use super::AdditionalProperties; +use crate::compare::ElispFact; use crate::types::FixedWidthArea; use crate::wasm::to_wasm::ToWasmStandardProperties; -use crate::wasm::WasmAstNode; -#[derive(Debug, Serialize)] -#[serde(tag = "ast_node")] -#[serde(rename = "org-data")] -pub struct WasmFixedWidthArea<'s, 'p> { - standard_properties: WasmStandardProperties, - children: Vec>, +#[derive(Debug, Serialize, Deserialize)] +pub struct WasmFixedWidthArea { + #[serde(flatten)] + pub(crate) additional_properties: AdditionalProperties, } to_wasm!( - WasmFixedWidthArea<'s, 'p>, + WasmFixedWidthArea, FixedWidthArea<'s>, original, wasm_context, - standard_properties, + { WasmAstNode::FixedWidthArea(original) }, + { "TODO".into() }, { - Ok(WasmFixedWidthArea { - standard_properties, - children: Vec::new(), - }) + Ok(( + Vec::new(), + WasmFixedWidthArea { + additional_properties: AdditionalProperties::default(), + }, + )) } ); - -impl<'s, 'p> Into> for WasmFixedWidthArea<'s, 'p> { - fn into(self) -> WasmAstNode<'s, 'p> { - WasmAstNode::FixedWidthArea(self) - } -} diff --git a/src/wasm/footnote_definition.rs b/src/wasm/footnote_definition.rs index b48cd5a..8b54427 100644 --- a/src/wasm/footnote_definition.rs +++ b/src/wasm/footnote_definition.rs @@ -1,36 +1,43 @@ +use serde::Deserialize; use serde::Serialize; +use super::ast_node::WasmAstNode; use super::macros::to_wasm; -use super::standard_properties::WasmStandardProperties; use super::to_wasm::ToWasm; +use super::AdditionalProperties; +use crate::compare::ElispFact; use crate::types::FootnoteDefinition; use crate::wasm::to_wasm::ToWasmStandardProperties; -use crate::wasm::WasmAstNode; -#[derive(Debug, Serialize)] -#[serde(tag = "ast_node")] -#[serde(rename = "org-data")] -pub struct WasmFootnoteDefinition<'s, 'p> { - standard_properties: WasmStandardProperties, - children: Vec>, +#[derive(Debug, Serialize, Deserialize)] +pub struct WasmFootnoteDefinition { + #[serde(flatten)] + pub(crate) additional_properties: AdditionalProperties, } to_wasm!( - WasmFootnoteDefinition<'s, 'p>, + WasmFootnoteDefinition, FootnoteDefinition<'s>, original, wasm_context, - standard_properties, + { WasmAstNode::FootnoteDefinition(original) }, + { "TODO".into() }, { - Ok(WasmFootnoteDefinition { - standard_properties, - children: Vec::new(), - }) + let children = original + .children + .iter() + .map(|child| { + child + .to_wasm(wasm_context.clone()) + .map(Into::::into) + }) + .collect::, _>>()?; + + Ok(( + children, + WasmFootnoteDefinition { + additional_properties: AdditionalProperties::default(), + }, + )) } ); - -impl<'s, 'p> Into> for WasmFootnoteDefinition<'s, 'p> { - fn into(self) -> WasmAstNode<'s, 'p> { - WasmAstNode::FootnoteDefinition(self) - } -} diff --git a/src/wasm/footnote_reference.rs b/src/wasm/footnote_reference.rs index 5442f46..6b023ae 100644 --- a/src/wasm/footnote_reference.rs +++ b/src/wasm/footnote_reference.rs @@ -1,36 +1,33 @@ +use serde::Deserialize; use serde::Serialize; +use super::ast_node::WasmAstNode; use super::macros::to_wasm; -use super::standard_properties::WasmStandardProperties; use super::to_wasm::ToWasm; +use super::AdditionalProperties; +use crate::compare::ElispFact; use crate::types::FootnoteReference; use crate::wasm::to_wasm::ToWasmStandardProperties; -use crate::wasm::WasmAstNode; -#[derive(Debug, Serialize)] -#[serde(tag = "ast_node")] -#[serde(rename = "org-data")] -pub struct WasmFootnoteReference<'s, 'p> { - standard_properties: WasmStandardProperties, - children: Vec>, +#[derive(Debug, Serialize, Deserialize)] +pub struct WasmFootnoteReference { + #[serde(flatten)] + pub(crate) additional_properties: AdditionalProperties, } to_wasm!( - WasmFootnoteReference<'s, 'p>, + WasmFootnoteReference, FootnoteReference<'s>, original, wasm_context, - standard_properties, + { WasmAstNode::FootnoteReference(original) }, + { "TODO".into() }, { - Ok(WasmFootnoteReference { - standard_properties, - children: Vec::new(), - }) + Ok(( + Vec::new(), + WasmFootnoteReference { + additional_properties: AdditionalProperties::default(), + }, + )) } ); - -impl<'s, 'p> Into> for WasmFootnoteReference<'s, 'p> { - fn into(self) -> WasmAstNode<'s, 'p> { - WasmAstNode::FootnoteReference(self) - } -} diff --git a/src/wasm/headline.rs b/src/wasm/headline.rs index 56da464..bd803f4 100644 --- a/src/wasm/headline.rs +++ b/src/wasm/headline.rs @@ -1,36 +1,43 @@ +use serde::Deserialize; use serde::Serialize; use super::ast_node::WasmAstNode; use super::macros::to_wasm; -use super::standard_properties::WasmStandardProperties; use super::to_wasm::ToWasm; +use super::AdditionalProperties; +use crate::compare::ElispFact; use crate::types::Heading; use crate::wasm::to_wasm::ToWasmStandardProperties; -#[derive(Debug, Serialize)] -#[serde(tag = "ast_node")] -#[serde(rename = "headline")] -pub struct WasmHeadline<'s, 'p> { - standard_properties: WasmStandardProperties, - children: Vec>, +#[derive(Debug, Serialize, Deserialize)] +pub struct WasmHeadline { + #[serde(flatten)] + pub(crate) additional_properties: AdditionalProperties, } to_wasm!( - WasmHeadline<'s, 'p>, + WasmHeadline, Heading<'s>, original, wasm_context, - standard_properties, + { WasmAstNode::Headline(original) }, + { "TODO".into() }, { - Ok(WasmHeadline { - standard_properties, - children: Vec::new(), - }) + let children = original + .children + .iter() + .map(|child| { + child + .to_wasm(wasm_context.clone()) + .map(Into::::into) + }) + .collect::, _>>()?; + + Ok(( + children, + WasmHeadline { + additional_properties: AdditionalProperties::default(), + }, + )) } ); - -impl<'s, 'p> Into> for WasmHeadline<'s, 'p> { - fn into(self) -> WasmAstNode<'s, 'p> { - WasmAstNode::Headline(self) - } -} diff --git a/src/wasm/horizontal_rule.rs b/src/wasm/horizontal_rule.rs index 9ea6a1d..0103cf6 100644 --- a/src/wasm/horizontal_rule.rs +++ b/src/wasm/horizontal_rule.rs @@ -1,36 +1,33 @@ +use serde::Deserialize; use serde::Serialize; +use super::ast_node::WasmAstNode; use super::macros::to_wasm; -use super::standard_properties::WasmStandardProperties; use super::to_wasm::ToWasm; +use super::AdditionalProperties; +use crate::compare::ElispFact; use crate::types::HorizontalRule; use crate::wasm::to_wasm::ToWasmStandardProperties; -use crate::wasm::WasmAstNode; -#[derive(Debug, Serialize)] -#[serde(tag = "ast_node")] -#[serde(rename = "org-data")] -pub struct WasmHorizontalRule<'s, 'p> { - standard_properties: WasmStandardProperties, - children: Vec>, +#[derive(Debug, Serialize, Deserialize)] +pub struct WasmHorizontalRule { + #[serde(flatten)] + pub(crate) additional_properties: AdditionalProperties, } to_wasm!( - WasmHorizontalRule<'s, 'p>, + WasmHorizontalRule, HorizontalRule<'s>, original, wasm_context, - standard_properties, + { WasmAstNode::HorizontalRule(original) }, + { "TODO".into() }, { - Ok(WasmHorizontalRule { - standard_properties, - children: Vec::new(), - }) + Ok(( + Vec::new(), + WasmHorizontalRule { + additional_properties: AdditionalProperties::default(), + }, + )) } ); - -impl<'s, 'p> Into> for WasmHorizontalRule<'s, 'p> { - fn into(self) -> WasmAstNode<'s, 'p> { - WasmAstNode::HorizontalRule(self) - } -} diff --git a/src/wasm/inline_babel_call.rs b/src/wasm/inline_babel_call.rs index 61544ba..036efdb 100644 --- a/src/wasm/inline_babel_call.rs +++ b/src/wasm/inline_babel_call.rs @@ -1,36 +1,33 @@ +use serde::Deserialize; use serde::Serialize; +use super::ast_node::WasmAstNode; use super::macros::to_wasm; -use super::standard_properties::WasmStandardProperties; use super::to_wasm::ToWasm; +use super::AdditionalProperties; +use crate::compare::ElispFact; use crate::types::InlineBabelCall; use crate::wasm::to_wasm::ToWasmStandardProperties; -use crate::wasm::WasmAstNode; -#[derive(Debug, Serialize)] -#[serde(tag = "ast_node")] -#[serde(rename = "org-data")] -pub struct WasmInlineBabelCall<'s, 'p> { - standard_properties: WasmStandardProperties, - children: Vec>, +#[derive(Debug, Serialize, Deserialize)] +pub struct WasmInlineBabelCall { + #[serde(flatten)] + pub(crate) additional_properties: AdditionalProperties, } to_wasm!( - WasmInlineBabelCall<'s, 'p>, + WasmInlineBabelCall, InlineBabelCall<'s>, original, wasm_context, - standard_properties, + { WasmAstNode::InlineBabelCall(original) }, + { "TODO".into() }, { - Ok(WasmInlineBabelCall { - standard_properties, - children: Vec::new(), - }) + Ok(( + Vec::new(), + WasmInlineBabelCall { + additional_properties: AdditionalProperties::default(), + }, + )) } ); - -impl<'s, 'p> Into> for WasmInlineBabelCall<'s, 'p> { - fn into(self) -> WasmAstNode<'s, 'p> { - WasmAstNode::InlineBabelCall(self) - } -} diff --git a/src/wasm/inline_source_block.rs b/src/wasm/inline_source_block.rs index f6741f4..b560ceb 100644 --- a/src/wasm/inline_source_block.rs +++ b/src/wasm/inline_source_block.rs @@ -1,36 +1,33 @@ +use serde::Deserialize; use serde::Serialize; +use super::ast_node::WasmAstNode; use super::macros::to_wasm; -use super::standard_properties::WasmStandardProperties; use super::to_wasm::ToWasm; +use super::AdditionalProperties; +use crate::compare::ElispFact; use crate::types::InlineSourceBlock; use crate::wasm::to_wasm::ToWasmStandardProperties; -use crate::wasm::WasmAstNode; -#[derive(Debug, Serialize)] -#[serde(tag = "ast_node")] -#[serde(rename = "org-data")] -pub struct WasmInlineSourceBlock<'s, 'p> { - standard_properties: WasmStandardProperties, - children: Vec>, +#[derive(Debug, Serialize, Deserialize)] +pub struct WasmInlineSourceBlock { + #[serde(flatten)] + pub(crate) additional_properties: AdditionalProperties, } to_wasm!( - WasmInlineSourceBlock<'s, 'p>, + WasmInlineSourceBlock, InlineSourceBlock<'s>, original, wasm_context, - standard_properties, + { WasmAstNode::InlineSourceBlock(original) }, + { "TODO".into() }, { - Ok(WasmInlineSourceBlock { - standard_properties, - children: Vec::new(), - }) + Ok(( + Vec::new(), + WasmInlineSourceBlock { + additional_properties: AdditionalProperties::default(), + }, + )) } ); - -impl<'s, 'p> Into> for WasmInlineSourceBlock<'s, 'p> { - fn into(self) -> WasmAstNode<'s, 'p> { - WasmAstNode::InlineSourceBlock(self) - } -} diff --git a/src/wasm/italic.rs b/src/wasm/italic.rs index ad59550..e38854e 100644 --- a/src/wasm/italic.rs +++ b/src/wasm/italic.rs @@ -1,36 +1,43 @@ +use serde::Deserialize; use serde::Serialize; +use super::ast_node::WasmAstNode; use super::macros::to_wasm; -use super::standard_properties::WasmStandardProperties; use super::to_wasm::ToWasm; +use super::AdditionalProperties; +use crate::compare::ElispFact; use crate::types::Italic; use crate::wasm::to_wasm::ToWasmStandardProperties; -use crate::wasm::WasmAstNode; -#[derive(Debug, Serialize)] -#[serde(tag = "ast_node")] -#[serde(rename = "org-data")] -pub struct WasmItalic<'s, 'p> { - standard_properties: WasmStandardProperties, - children: Vec>, +#[derive(Debug, Serialize, Deserialize)] +pub struct WasmItalic { + #[serde(flatten)] + pub(crate) additional_properties: AdditionalProperties, } to_wasm!( - WasmItalic<'s, 'p>, + WasmItalic, Italic<'s>, original, wasm_context, - standard_properties, + { WasmAstNode::Italic(original) }, + { "TODO".into() }, { - Ok(WasmItalic { - standard_properties, - children: Vec::new(), - }) + let children = original + .children + .iter() + .map(|child| { + child + .to_wasm(wasm_context.clone()) + .map(Into::::into) + }) + .collect::, _>>()?; + + Ok(( + children, + WasmItalic { + additional_properties: AdditionalProperties::default(), + }, + )) } ); - -impl<'s, 'p> Into> for WasmItalic<'s, 'p> { - fn into(self) -> WasmAstNode<'s, 'p> { - WasmAstNode::Italic(self) - } -} diff --git a/src/wasm/keyword.rs b/src/wasm/keyword.rs index fc8431e..289bbc4 100644 --- a/src/wasm/keyword.rs +++ b/src/wasm/keyword.rs @@ -1,36 +1,33 @@ +use serde::Deserialize; use serde::Serialize; +use super::ast_node::WasmAstNode; use super::macros::to_wasm; -use super::standard_properties::WasmStandardProperties; use super::to_wasm::ToWasm; +use super::AdditionalProperties; +use crate::compare::ElispFact; use crate::types::Keyword; use crate::wasm::to_wasm::ToWasmStandardProperties; -use crate::wasm::WasmAstNode; -#[derive(Debug, Serialize)] -#[serde(tag = "ast_node")] -#[serde(rename = "org-data")] -pub struct WasmKeyword<'s, 'p> { - standard_properties: WasmStandardProperties, - children: Vec>, +#[derive(Debug, Serialize, Deserialize)] +pub struct WasmKeyword { + #[serde(flatten)] + pub(crate) additional_properties: AdditionalProperties, } to_wasm!( - WasmKeyword<'s, 'p>, + WasmKeyword, Keyword<'s>, original, wasm_context, - standard_properties, + { WasmAstNode::Keyword(original) }, + { "TODO".into() }, { - Ok(WasmKeyword { - standard_properties, - children: Vec::new(), - }) + Ok(( + Vec::new(), + WasmKeyword { + additional_properties: AdditionalProperties::default(), + }, + )) } ); - -impl<'s, 'p> Into> for WasmKeyword<'s, 'p> { - fn into(self) -> WasmAstNode<'s, 'p> { - WasmAstNode::Keyword(self) - } -} diff --git a/src/wasm/latex_environment.rs b/src/wasm/latex_environment.rs index 9209726..8c002dd 100644 --- a/src/wasm/latex_environment.rs +++ b/src/wasm/latex_environment.rs @@ -1,36 +1,33 @@ +use serde::Deserialize; use serde::Serialize; +use super::ast_node::WasmAstNode; use super::macros::to_wasm; -use super::standard_properties::WasmStandardProperties; use super::to_wasm::ToWasm; +use super::AdditionalProperties; +use crate::compare::ElispFact; use crate::types::LatexEnvironment; use crate::wasm::to_wasm::ToWasmStandardProperties; -use crate::wasm::WasmAstNode; -#[derive(Debug, Serialize)] -#[serde(tag = "ast_node")] -#[serde(rename = "org-data")] -pub struct WasmLatexEnvironment<'s, 'p> { - standard_properties: WasmStandardProperties, - children: Vec>, +#[derive(Debug, Serialize, Deserialize)] +pub struct WasmLatexEnvironment { + #[serde(flatten)] + pub(crate) additional_properties: AdditionalProperties, } to_wasm!( - WasmLatexEnvironment<'s, 'p>, + WasmLatexEnvironment, LatexEnvironment<'s>, original, wasm_context, - standard_properties, + { WasmAstNode::LatexEnvironment(original) }, + { "TODO".into() }, { - Ok(WasmLatexEnvironment { - standard_properties, - children: Vec::new(), - }) + Ok(( + Vec::new(), + WasmLatexEnvironment { + additional_properties: AdditionalProperties::default(), + }, + )) } ); - -impl<'s, 'p> Into> for WasmLatexEnvironment<'s, 'p> { - fn into(self) -> WasmAstNode<'s, 'p> { - WasmAstNode::LatexEnvironment(self) - } -} diff --git a/src/wasm/latex_fragment.rs b/src/wasm/latex_fragment.rs index 77c717e..47d3f99 100644 --- a/src/wasm/latex_fragment.rs +++ b/src/wasm/latex_fragment.rs @@ -1,36 +1,33 @@ +use serde::Deserialize; use serde::Serialize; +use super::ast_node::WasmAstNode; use super::macros::to_wasm; -use super::standard_properties::WasmStandardProperties; use super::to_wasm::ToWasm; +use super::AdditionalProperties; +use crate::compare::ElispFact; use crate::types::LatexFragment; use crate::wasm::to_wasm::ToWasmStandardProperties; -use crate::wasm::WasmAstNode; -#[derive(Debug, Serialize)] -#[serde(tag = "ast_node")] -#[serde(rename = "org-data")] -pub struct WasmLatexFragment<'s, 'p> { - standard_properties: WasmStandardProperties, - children: Vec>, +#[derive(Debug, Serialize, Deserialize)] +pub struct WasmLatexFragment { + #[serde(flatten)] + pub(crate) additional_properties: AdditionalProperties, } to_wasm!( - WasmLatexFragment<'s, 'p>, + WasmLatexFragment, LatexFragment<'s>, original, wasm_context, - standard_properties, + { WasmAstNode::LatexFragment(original) }, + { "TODO".into() }, { - Ok(WasmLatexFragment { - standard_properties, - children: Vec::new(), - }) + Ok(( + Vec::new(), + WasmLatexFragment { + additional_properties: AdditionalProperties::default(), + }, + )) } ); - -impl<'s, 'p> Into> for WasmLatexFragment<'s, 'p> { - fn into(self) -> WasmAstNode<'s, 'p> { - WasmAstNode::LatexFragment(self) - } -} diff --git a/src/wasm/line_break.rs b/src/wasm/line_break.rs index 2af6cd4..4d158c7 100644 --- a/src/wasm/line_break.rs +++ b/src/wasm/line_break.rs @@ -1,36 +1,33 @@ +use serde::Deserialize; use serde::Serialize; +use super::ast_node::WasmAstNode; use super::macros::to_wasm; -use super::standard_properties::WasmStandardProperties; use super::to_wasm::ToWasm; +use super::AdditionalProperties; +use crate::compare::ElispFact; use crate::types::LineBreak; use crate::wasm::to_wasm::ToWasmStandardProperties; -use crate::wasm::WasmAstNode; -#[derive(Debug, Serialize)] -#[serde(tag = "ast_node")] -#[serde(rename = "org-data")] -pub struct WasmLineBreak<'s, 'p> { - standard_properties: WasmStandardProperties, - children: Vec>, +#[derive(Debug, Serialize, Deserialize)] +pub struct WasmLineBreak { + #[serde(flatten)] + pub(crate) additional_properties: AdditionalProperties, } to_wasm!( - WasmLineBreak<'s, 'p>, + WasmLineBreak, LineBreak<'s>, original, wasm_context, - standard_properties, + { WasmAstNode::LineBreak(original) }, + { "TODO".into() }, { - Ok(WasmLineBreak { - standard_properties, - children: Vec::new(), - }) + Ok(( + Vec::new(), + WasmLineBreak { + additional_properties: AdditionalProperties::default(), + }, + )) } ); - -impl<'s, 'p> Into> for WasmLineBreak<'s, 'p> { - fn into(self) -> WasmAstNode<'s, 'p> { - WasmAstNode::LineBreak(self) - } -} diff --git a/src/wasm/macros.rs b/src/wasm/macros.rs index 89ce843..daf1360 100644 --- a/src/wasm/macros.rs +++ b/src/wasm/macros.rs @@ -3,11 +3,11 @@ /// This exists to make changing the type signature easier. macro_rules! to_wasm { ($ostruct:ty, $istruct:ty, $original:ident, $wasm_context:ident, $fnbody:tt) => { - impl<'s, 'p> ToWasm<'p> for $istruct { + impl<'s> ToWasm for $istruct { type Output = $ostruct; fn to_wasm( - &'p self, + &self, $wasm_context: crate::wasm::to_wasm::ToWasmContext<'_>, ) -> Result { let $original = self; @@ -15,18 +15,43 @@ macro_rules! to_wasm { } } }; - ($ostruct:ty, $istruct:ty, $original:ident, $wasm_context:ident, $standard_properties:ident, $fnbody:tt) => { - impl<'s, 'p> ToWasm<'p> for $istruct { - type Output = $ostruct; + ($ostruct:ty, $istruct:ty, $original:ident, $wasm_context:ident, $toastnodebody:tt, $elispnamebody:tt, $fnbody:tt) => { + impl<'s> ToWasm for $istruct { + type Output = crate::wasm::ast_node::WasmAstNodeWrapper<$ostruct>; fn to_wasm( - &'p self, + &self, $wasm_context: crate::wasm::to_wasm::ToWasmContext<'_>, ) -> Result { let $original = self; - let $standard_properties = + let standard_properties = self.to_wasm_standard_properties($wasm_context.clone())?; - $fnbody + + $fnbody.map( + |(children, inner)| crate::wasm::ast_node::WasmAstNodeWrapper { + ast_node: inner.get_elisp_name().into_owned(), + standard_properties, + children, + properties: inner, + }, + ) + } + } + + impl Into for crate::wasm::ast_node::WasmAstNodeWrapper<$ostruct> { + fn into(self) -> WasmAstNode { + let $original = self; + let ret = $toastnodebody; + ret + } + } + + #[cfg(feature = "wasm_test")] + impl<'s> crate::compare::ElispFact<'s> for $ostruct { + fn get_elisp_name<'b>(&'b self) -> std::borrow::Cow<'s, str> { + let $original = self; + let ret = $elispnamebody; + ret } } }; diff --git a/src/wasm/mod.rs b/src/wasm/mod.rs index 5eb1b9b..fa504dd 100644 --- a/src/wasm/mod.rs +++ b/src/wasm/mod.rs @@ -67,6 +67,7 @@ pub use additional_property::AdditionalProperties; pub use additional_property::AdditionalPropertyValue; pub(crate) use angle_link::WasmAngleLink; pub use ast_node::WasmAstNode; +pub use ast_node::WasmAstNodeWrapper; pub(crate) use babel_call::WasmBabelCall; pub(crate) use bold::WasmBold; pub(crate) use center_block::WasmCenterBlock; diff --git a/src/wasm/node_property.rs b/src/wasm/node_property.rs index 710409c..2fa3595 100644 --- a/src/wasm/node_property.rs +++ b/src/wasm/node_property.rs @@ -1,30 +1,33 @@ +use serde::Deserialize; use serde::Serialize; +use super::ast_node::WasmAstNode; use super::macros::to_wasm; -use super::standard_properties::WasmStandardProperties; use super::to_wasm::ToWasm; +use super::AdditionalProperties; +use crate::compare::ElispFact; use crate::types::NodeProperty; use crate::wasm::to_wasm::ToWasmStandardProperties; -use crate::wasm::WasmAstNode; -#[derive(Debug, Serialize)] -#[serde(tag = "ast_node")] -#[serde(rename = "org-data")] -pub struct WasmNodeProperty<'s, 'p> { - standard_properties: WasmStandardProperties, - children: Vec>, +#[derive(Debug, Serialize, Deserialize)] +pub struct WasmNodeProperty { + #[serde(flatten)] + pub(crate) additional_properties: AdditionalProperties, } to_wasm!( - WasmNodeProperty<'s, 'p>, + WasmNodeProperty, NodeProperty<'s>, original, wasm_context, - standard_properties, + { WasmAstNode::NodeProperty(original) }, + { "TODO".into() }, { - Ok(WasmNodeProperty { - standard_properties, - children: Vec::new(), - }) + Ok(( + Vec::new(), + WasmNodeProperty { + additional_properties: AdditionalProperties::default(), + }, + )) } ); diff --git a/src/wasm/org_macro.rs b/src/wasm/org_macro.rs index de38405..46fbc38 100644 --- a/src/wasm/org_macro.rs +++ b/src/wasm/org_macro.rs @@ -1,36 +1,33 @@ +use serde::Deserialize; use serde::Serialize; +use super::ast_node::WasmAstNode; use super::macros::to_wasm; -use super::standard_properties::WasmStandardProperties; use super::to_wasm::ToWasm; +use super::AdditionalProperties; +use crate::compare::ElispFact; use crate::types::OrgMacro; use crate::wasm::to_wasm::ToWasmStandardProperties; -use crate::wasm::WasmAstNode; -#[derive(Debug, Serialize)] -#[serde(tag = "ast_node")] -#[serde(rename = "org-data")] -pub struct WasmOrgMacro<'s, 'p> { - standard_properties: WasmStandardProperties, - children: Vec>, +#[derive(Debug, Serialize, Deserialize)] +pub struct WasmOrgMacro { + #[serde(flatten)] + pub(crate) additional_properties: AdditionalProperties, } to_wasm!( - WasmOrgMacro<'s, 'p>, + WasmOrgMacro, OrgMacro<'s>, original, wasm_context, - standard_properties, + { WasmAstNode::OrgMacro(original) }, + { "TODO".into() }, { - Ok(WasmOrgMacro { - standard_properties, - children: Vec::new(), - }) + Ok(( + Vec::new(), + WasmOrgMacro { + additional_properties: AdditionalProperties::default(), + }, + )) } ); - -impl<'s, 'p> Into> for WasmOrgMacro<'s, 'p> { - fn into(self) -> WasmAstNode<'s, 'p> { - WasmAstNode::OrgMacro(self) - } -} diff --git a/src/wasm/paragraph.rs b/src/wasm/paragraph.rs index 057c050..5d253d5 100644 --- a/src/wasm/paragraph.rs +++ b/src/wasm/paragraph.rs @@ -1,32 +1,28 @@ +use serde::Deserialize; use serde::Serialize; +use super::ast_node::WasmAstNode; use super::macros::to_wasm; -use super::standard_properties::WasmStandardProperties; use super::to_wasm::ToWasm; use super::AdditionalProperties; -#[cfg(feature = "wasm_test")] use crate::compare::ElispFact; use crate::types::GetAffiliatedKeywords; use crate::types::Paragraph; use crate::wasm::to_wasm::ToWasmStandardProperties; -use crate::wasm::WasmAstNode; -#[derive(Debug, Serialize)] -#[serde(tag = "ast_node")] -#[serde(rename = "paragraph")] -pub struct WasmParagraph<'s, 'p> { - pub(crate) standard_properties: WasmStandardProperties, +#[derive(Debug, Serialize, Deserialize)] +pub struct WasmParagraph { #[serde(flatten)] - pub(crate) additional_properties: AdditionalProperties<'s, 'p>, - pub(crate) children: Vec>, + pub(crate) additional_properties: AdditionalProperties, } to_wasm!( - WasmParagraph<'s, 'p>, + WasmParagraph, Paragraph<'s>, original, wasm_context, - standard_properties, + { WasmAstNode::Paragraph(original) }, + { "paragraph".into() }, { let additional_properties = original .get_affiliated_keywords() @@ -38,27 +34,15 @@ to_wasm!( .map(|child| { child .to_wasm(wasm_context.clone()) - .map(Into::>::into) + .map(Into::::into) }) .collect::, _>>()?; - Ok(WasmParagraph { - standard_properties, - additional_properties, + Ok(( children, - }) + WasmParagraph { + additional_properties, + }, + )) } ); - -impl<'s, 'p> Into> for WasmParagraph<'s, 'p> { - fn into(self) -> WasmAstNode<'s, 'p> { - WasmAstNode::Paragraph(self) - } -} - -#[cfg(feature = "wasm_test")] -impl<'s, 'p> ElispFact<'s> for WasmParagraph<'s, 'p> { - fn get_elisp_name<'b>(&'b self) -> std::borrow::Cow<'s, str> { - "paragraph".into() - } -} diff --git a/src/wasm/parse_result.rs b/src/wasm/parse_result.rs index 9d88fb2..33ab251 100644 --- a/src/wasm/parse_result.rs +++ b/src/wasm/parse_result.rs @@ -1,12 +1,14 @@ +use serde::Deserialize; use serde::Serialize; +use super::ast_node::WasmAstNodeWrapper; use super::document::WasmDocument; -#[derive(Debug, Serialize)] +#[derive(Debug, Serialize, Deserialize)] #[serde(tag = "status", content = "content")] -pub enum ParseResult<'s, 'p> { +pub enum ParseResult { #[serde(rename = "success")] - Success(WasmDocument<'s, 'p>), + Success(WasmAstNodeWrapper), #[serde(rename = "error")] Error(String), diff --git a/src/wasm/plain_link.rs b/src/wasm/plain_link.rs index 69568a3..fbb76f7 100644 --- a/src/wasm/plain_link.rs +++ b/src/wasm/plain_link.rs @@ -1,36 +1,33 @@ +use serde::Deserialize; use serde::Serialize; +use super::ast_node::WasmAstNode; use super::macros::to_wasm; -use super::standard_properties::WasmStandardProperties; use super::to_wasm::ToWasm; +use super::AdditionalProperties; +use crate::compare::ElispFact; use crate::types::PlainLink; use crate::wasm::to_wasm::ToWasmStandardProperties; -use crate::wasm::WasmAstNode; -#[derive(Debug, Serialize)] -#[serde(tag = "ast_node")] -#[serde(rename = "org-data")] -pub struct WasmPlainLink<'s, 'p> { - standard_properties: WasmStandardProperties, - children: Vec>, +#[derive(Debug, Serialize, Deserialize)] +pub struct WasmPlainLink { + #[serde(flatten)] + pub(crate) additional_properties: AdditionalProperties, } to_wasm!( - WasmPlainLink<'s, 'p>, + WasmPlainLink, PlainLink<'s>, original, wasm_context, - standard_properties, + { WasmAstNode::PlainLink(original) }, + { "TODO".into() }, { - Ok(WasmPlainLink { - standard_properties, - children: Vec::new(), - }) + Ok(( + Vec::new(), + WasmPlainLink { + additional_properties: AdditionalProperties::default(), + }, + )) } ); - -impl<'s, 'p> Into> for WasmPlainLink<'s, 'p> { - fn into(self) -> WasmAstNode<'s, 'p> { - WasmAstNode::PlainLink(self) - } -} diff --git a/src/wasm/plain_list.rs b/src/wasm/plain_list.rs index df8ada2..a560951 100644 --- a/src/wasm/plain_list.rs +++ b/src/wasm/plain_list.rs @@ -1,36 +1,43 @@ +use serde::Deserialize; use serde::Serialize; +use super::ast_node::WasmAstNode; use super::macros::to_wasm; -use super::standard_properties::WasmStandardProperties; use super::to_wasm::ToWasm; +use super::AdditionalProperties; +use crate::compare::ElispFact; use crate::types::PlainList; use crate::wasm::to_wasm::ToWasmStandardProperties; -use crate::wasm::WasmAstNode; -#[derive(Debug, Serialize)] -#[serde(tag = "ast_node")] -#[serde(rename = "org-data")] -pub struct WasmPlainList<'s, 'p> { - standard_properties: WasmStandardProperties, - children: Vec>, +#[derive(Debug, Serialize, Deserialize)] +pub struct WasmPlainList { + #[serde(flatten)] + pub(crate) additional_properties: AdditionalProperties, } to_wasm!( - WasmPlainList<'s, 'p>, + WasmPlainList, PlainList<'s>, original, wasm_context, - standard_properties, + { WasmAstNode::PlainList(original) }, + { "TODO".into() }, { - Ok(WasmPlainList { - standard_properties, - children: Vec::new(), - }) + let children = original + .children + .iter() + .map(|child| { + child + .to_wasm(wasm_context.clone()) + .map(Into::::into) + }) + .collect::, _>>()?; + + Ok(( + children, + WasmPlainList { + additional_properties: AdditionalProperties::default(), + }, + )) } ); - -impl<'s, 'p> Into> for WasmPlainList<'s, 'p> { - fn into(self) -> WasmAstNode<'s, 'p> { - WasmAstNode::PlainList(self) - } -} diff --git a/src/wasm/plain_list_item.rs b/src/wasm/plain_list_item.rs index af237ea..2bf6174 100644 --- a/src/wasm/plain_list_item.rs +++ b/src/wasm/plain_list_item.rs @@ -1,30 +1,43 @@ +use serde::Deserialize; use serde::Serialize; +use super::ast_node::WasmAstNode; use super::macros::to_wasm; -use super::standard_properties::WasmStandardProperties; use super::to_wasm::ToWasm; +use super::AdditionalProperties; +use crate::compare::ElispFact; use crate::types::PlainListItem; use crate::wasm::to_wasm::ToWasmStandardProperties; -use crate::wasm::WasmAstNode; -#[derive(Debug, Serialize)] -#[serde(tag = "ast_node")] -#[serde(rename = "org-data")] -pub struct WasmPlainListItem<'s, 'p> { - standard_properties: WasmStandardProperties, - children: Vec>, +#[derive(Debug, Serialize, Deserialize)] +pub struct WasmPlainListItem { + #[serde(flatten)] + pub(crate) additional_properties: AdditionalProperties, } to_wasm!( - WasmPlainListItem<'s, 'p>, + WasmPlainListItem, PlainListItem<'s>, original, wasm_context, - standard_properties, + { WasmAstNode::PlainListItem(original) }, + { "TODO".into() }, { - Ok(WasmPlainListItem { - standard_properties, - children: Vec::new(), - }) + let children = original + .children + .iter() + .map(|child| { + child + .to_wasm(wasm_context.clone()) + .map(Into::::into) + }) + .collect::, _>>()?; + + Ok(( + children, + WasmPlainListItem { + additional_properties: AdditionalProperties::default(), + }, + )) } ); diff --git a/src/wasm/plain_text.rs b/src/wasm/plain_text.rs index e8839c8..974cb16 100644 --- a/src/wasm/plain_text.rs +++ b/src/wasm/plain_text.rs @@ -1,36 +1,33 @@ +use serde::Deserialize; use serde::Serialize; +use super::ast_node::WasmAstNode; use super::macros::to_wasm; -use super::standard_properties::WasmStandardProperties; use super::to_wasm::ToWasm; +use super::AdditionalProperties; +use crate::compare::ElispFact; use crate::types::PlainText; use crate::wasm::to_wasm::ToWasmStandardProperties; -use crate::wasm::WasmAstNode; -#[derive(Debug, Serialize)] -#[serde(tag = "ast_node")] -#[serde(rename = "org-data")] -pub struct WasmPlainText<'s, 'p> { - standard_properties: WasmStandardProperties, - children: Vec>, +#[derive(Debug, Serialize, Deserialize)] +pub struct WasmPlainText { + #[serde(flatten)] + pub(crate) additional_properties: AdditionalProperties, } to_wasm!( - WasmPlainText<'s, 'p>, + WasmPlainText, PlainText<'s>, original, wasm_context, - standard_properties, + { WasmAstNode::PlainText(original) }, + { "plain-text".into() }, { - Ok(WasmPlainText { - standard_properties, - children: Vec::new(), - }) + Ok(( + Vec::new(), + WasmPlainText { + additional_properties: AdditionalProperties::default(), + }, + )) } ); - -impl<'s, 'p> Into> for WasmPlainText<'s, 'p> { - fn into(self) -> WasmAstNode<'s, 'p> { - WasmAstNode::PlainText(self) - } -} diff --git a/src/wasm/planning.rs b/src/wasm/planning.rs index c921717..36e8537 100644 --- a/src/wasm/planning.rs +++ b/src/wasm/planning.rs @@ -1,36 +1,33 @@ +use serde::Deserialize; use serde::Serialize; +use super::ast_node::WasmAstNode; use super::macros::to_wasm; -use super::standard_properties::WasmStandardProperties; use super::to_wasm::ToWasm; +use super::AdditionalProperties; +use crate::compare::ElispFact; use crate::types::Planning; use crate::wasm::to_wasm::ToWasmStandardProperties; -use crate::wasm::WasmAstNode; -#[derive(Debug, Serialize)] -#[serde(tag = "ast_node")] -#[serde(rename = "org-data")] -pub struct WasmPlanning<'s, 'p> { - standard_properties: WasmStandardProperties, - children: Vec>, +#[derive(Debug, Serialize, Deserialize)] +pub struct WasmPlanning { + #[serde(flatten)] + pub(crate) additional_properties: AdditionalProperties, } to_wasm!( - WasmPlanning<'s, 'p>, + WasmPlanning, Planning<'s>, original, wasm_context, - standard_properties, + { WasmAstNode::Planning(original) }, + { "TODO".into() }, { - Ok(WasmPlanning { - standard_properties, - children: Vec::new(), - }) + Ok(( + Vec::new(), + WasmPlanning { + additional_properties: AdditionalProperties::default(), + }, + )) } ); - -impl<'s, 'p> Into> for WasmPlanning<'s, 'p> { - fn into(self) -> WasmAstNode<'s, 'p> { - WasmAstNode::Planning(self) - } -} diff --git a/src/wasm/property_drawer.rs b/src/wasm/property_drawer.rs index a02e06d..fd67b30 100644 --- a/src/wasm/property_drawer.rs +++ b/src/wasm/property_drawer.rs @@ -1,36 +1,43 @@ +use serde::Deserialize; use serde::Serialize; +use super::ast_node::WasmAstNode; use super::macros::to_wasm; -use super::standard_properties::WasmStandardProperties; use super::to_wasm::ToWasm; +use super::AdditionalProperties; +use crate::compare::ElispFact; use crate::types::PropertyDrawer; use crate::wasm::to_wasm::ToWasmStandardProperties; -use crate::wasm::WasmAstNode; -#[derive(Debug, Serialize)] -#[serde(tag = "ast_node")] -#[serde(rename = "org-data")] -pub struct WasmPropertyDrawer<'s, 'p> { - standard_properties: WasmStandardProperties, - children: Vec>, +#[derive(Debug, Serialize, Deserialize)] +pub struct WasmPropertyDrawer { + #[serde(flatten)] + pub(crate) additional_properties: AdditionalProperties, } to_wasm!( - WasmPropertyDrawer<'s, 'p>, + WasmPropertyDrawer, PropertyDrawer<'s>, original, wasm_context, - standard_properties, + { WasmAstNode::PropertyDrawer(original) }, + { "TODO".into() }, { - Ok(WasmPropertyDrawer { - standard_properties, - children: Vec::new(), - }) + let children = original + .children + .iter() + .map(|child| { + child + .to_wasm(wasm_context.clone()) + .map(Into::::into) + }) + .collect::, _>>()?; + + Ok(( + children, + WasmPropertyDrawer { + additional_properties: AdditionalProperties::default(), + }, + )) } ); - -impl<'s, 'p> Into> for WasmPropertyDrawer<'s, 'p> { - fn into(self) -> WasmAstNode<'s, 'p> { - WasmAstNode::PropertyDrawer(self) - } -} diff --git a/src/wasm/quote_block.rs b/src/wasm/quote_block.rs index e1f89ed..39a9071 100644 --- a/src/wasm/quote_block.rs +++ b/src/wasm/quote_block.rs @@ -1,36 +1,43 @@ +use serde::Deserialize; use serde::Serialize; +use super::ast_node::WasmAstNode; use super::macros::to_wasm; -use super::standard_properties::WasmStandardProperties; use super::to_wasm::ToWasm; +use super::AdditionalProperties; +use crate::compare::ElispFact; use crate::types::QuoteBlock; use crate::wasm::to_wasm::ToWasmStandardProperties; -use crate::wasm::WasmAstNode; -#[derive(Debug, Serialize)] -#[serde(tag = "ast_node")] -#[serde(rename = "org-data")] -pub struct WasmQuoteBlock<'s, 'p> { - standard_properties: WasmStandardProperties, - children: Vec>, +#[derive(Debug, Serialize, Deserialize)] +pub struct WasmQuoteBlock { + #[serde(flatten)] + pub(crate) additional_properties: AdditionalProperties, } to_wasm!( - WasmQuoteBlock<'s, 'p>, + WasmQuoteBlock, QuoteBlock<'s>, original, wasm_context, - standard_properties, + { WasmAstNode::QuoteBlock(original) }, + { "TODO".into() }, { - Ok(WasmQuoteBlock { - standard_properties, - children: Vec::new(), - }) + let children = original + .children + .iter() + .map(|child| { + child + .to_wasm(wasm_context.clone()) + .map(Into::::into) + }) + .collect::, _>>()?; + + Ok(( + children, + WasmQuoteBlock { + additional_properties: AdditionalProperties::default(), + }, + )) } ); - -impl<'s, 'p> Into> for WasmQuoteBlock<'s, 'p> { - fn into(self) -> WasmAstNode<'s, 'p> { - WasmAstNode::QuoteBlock(self) - } -} diff --git a/src/wasm/radio_link.rs b/src/wasm/radio_link.rs index 58c3395..f217af7 100644 --- a/src/wasm/radio_link.rs +++ b/src/wasm/radio_link.rs @@ -1,36 +1,43 @@ +use serde::Deserialize; use serde::Serialize; +use super::ast_node::WasmAstNode; use super::macros::to_wasm; -use super::standard_properties::WasmStandardProperties; use super::to_wasm::ToWasm; +use super::AdditionalProperties; +use crate::compare::ElispFact; use crate::types::RadioLink; use crate::wasm::to_wasm::ToWasmStandardProperties; -use crate::wasm::WasmAstNode; -#[derive(Debug, Serialize)] -#[serde(tag = "ast_node")] -#[serde(rename = "org-data")] -pub struct WasmRadioLink<'s, 'p> { - standard_properties: WasmStandardProperties, - children: Vec>, +#[derive(Debug, Serialize, Deserialize)] +pub struct WasmRadioLink { + #[serde(flatten)] + pub(crate) additional_properties: AdditionalProperties, } to_wasm!( - WasmRadioLink<'s, 'p>, + WasmRadioLink, RadioLink<'s>, original, wasm_context, - standard_properties, + { WasmAstNode::RadioLink(original) }, + { "TODO".into() }, { - Ok(WasmRadioLink { - standard_properties, - children: Vec::new(), - }) + let children = original + .children + .iter() + .map(|child| { + child + .to_wasm(wasm_context.clone()) + .map(Into::::into) + }) + .collect::, _>>()?; + + Ok(( + children, + WasmRadioLink { + additional_properties: AdditionalProperties::default(), + }, + )) } ); - -impl<'s, 'p> Into> for WasmRadioLink<'s, 'p> { - fn into(self) -> WasmAstNode<'s, 'p> { - WasmAstNode::RadioLink(self) - } -} diff --git a/src/wasm/radio_target.rs b/src/wasm/radio_target.rs index 5498faa..927d876 100644 --- a/src/wasm/radio_target.rs +++ b/src/wasm/radio_target.rs @@ -1,36 +1,43 @@ +use serde::Deserialize; use serde::Serialize; +use super::ast_node::WasmAstNode; use super::macros::to_wasm; -use super::standard_properties::WasmStandardProperties; use super::to_wasm::ToWasm; +use super::AdditionalProperties; +use crate::compare::ElispFact; use crate::types::RadioTarget; use crate::wasm::to_wasm::ToWasmStandardProperties; -use crate::wasm::WasmAstNode; -#[derive(Debug, Serialize)] -#[serde(tag = "ast_node")] -#[serde(rename = "org-data")] -pub struct WasmRadioTarget<'s, 'p> { - standard_properties: WasmStandardProperties, - children: Vec>, +#[derive(Debug, Serialize, Deserialize)] +pub struct WasmRadioTarget { + #[serde(flatten)] + pub(crate) additional_properties: AdditionalProperties, } to_wasm!( - WasmRadioTarget<'s, 'p>, + WasmRadioTarget, RadioTarget<'s>, original, wasm_context, - standard_properties, + { WasmAstNode::RadioTarget(original) }, + { "TODO".into() }, { - Ok(WasmRadioTarget { - standard_properties, - children: Vec::new(), - }) + let children = original + .children + .iter() + .map(|child| { + child + .to_wasm(wasm_context.clone()) + .map(Into::::into) + }) + .collect::, _>>()?; + + Ok(( + children, + WasmRadioTarget { + additional_properties: AdditionalProperties::default(), + }, + )) } ); - -impl<'s, 'p> Into> for WasmRadioTarget<'s, 'p> { - fn into(self) -> WasmAstNode<'s, 'p> { - WasmAstNode::RadioTarget(self) - } -} diff --git a/src/wasm/regular_link.rs b/src/wasm/regular_link.rs index b989a36..5374394 100644 --- a/src/wasm/regular_link.rs +++ b/src/wasm/regular_link.rs @@ -1,36 +1,43 @@ +use serde::Deserialize; use serde::Serialize; +use super::ast_node::WasmAstNode; use super::macros::to_wasm; -use super::standard_properties::WasmStandardProperties; use super::to_wasm::ToWasm; +use super::AdditionalProperties; +use crate::compare::ElispFact; use crate::types::RegularLink; use crate::wasm::to_wasm::ToWasmStandardProperties; -use crate::wasm::WasmAstNode; -#[derive(Debug, Serialize)] -#[serde(tag = "ast_node")] -#[serde(rename = "org-data")] -pub struct WasmRegularLink<'s, 'p> { - standard_properties: WasmStandardProperties, - children: Vec>, +#[derive(Debug, Serialize, Deserialize)] +pub struct WasmRegularLink { + #[serde(flatten)] + pub(crate) additional_properties: AdditionalProperties, } to_wasm!( - WasmRegularLink<'s, 'p>, + WasmRegularLink, RegularLink<'s>, original, wasm_context, - standard_properties, + { WasmAstNode::RegularLink(original) }, + { "TODO".into() }, { - Ok(WasmRegularLink { - standard_properties, - children: Vec::new(), - }) + let children = original + .children + .iter() + .map(|child| { + child + .to_wasm(wasm_context.clone()) + .map(Into::::into) + }) + .collect::, _>>()?; + + Ok(( + children, + WasmRegularLink { + additional_properties: AdditionalProperties::default(), + }, + )) } ); - -impl<'s, 'p> Into> for WasmRegularLink<'s, 'p> { - fn into(self) -> WasmAstNode<'s, 'p> { - WasmAstNode::RegularLink(self) - } -} diff --git a/src/wasm/section.rs b/src/wasm/section.rs index 641528f..f267723 100644 --- a/src/wasm/section.rs +++ b/src/wasm/section.rs @@ -1,31 +1,27 @@ +use serde::Deserialize; use serde::Serialize; use super::ast_node::WasmAstNode; use super::macros::to_wasm; -use super::standard_properties::WasmStandardProperties; use super::to_wasm::ToWasm; use super::AdditionalProperties; -#[cfg(feature = "wasm_test")] use crate::compare::ElispFact; use crate::types::Section; use crate::wasm::to_wasm::ToWasmStandardProperties; -#[derive(Debug, Serialize)] -#[serde(tag = "ast_node")] -#[serde(rename = "section")] -pub struct WasmSection<'s, 'p> { - pub(crate) standard_properties: WasmStandardProperties, +#[derive(Debug, Serialize, Deserialize)] +pub struct WasmSection { #[serde(flatten)] - pub(crate) additional_properties: AdditionalProperties<'s, 'p>, - pub(crate) children: Vec>, + pub(crate) additional_properties: AdditionalProperties, } to_wasm!( - WasmSection<'s, 'p>, + WasmSection, Section<'s>, original, wasm_context, - standard_properties, + { WasmAstNode::Section(original) }, + { "section".into() }, { let children = original .children @@ -33,27 +29,15 @@ to_wasm!( .map(|child| { child .to_wasm(wasm_context.clone()) - .map(Into::>::into) + .map(Into::::into) }) .collect::, _>>()?; - Ok(WasmSection { - standard_properties, - additional_properties: AdditionalProperties::default(), + Ok(( children, - }) + WasmSection { + additional_properties: AdditionalProperties::default(), + }, + )) } ); - -impl<'s, 'p> Into> for WasmSection<'s, 'p> { - fn into(self) -> WasmAstNode<'s, 'p> { - WasmAstNode::Section(self) - } -} - -#[cfg(feature = "wasm_test")] -impl<'s, 'p> ElispFact<'s> for WasmSection<'s, 'p> { - fn get_elisp_name<'b>(&'b self) -> std::borrow::Cow<'s, str> { - "section".into() - } -} diff --git a/src/wasm/special_block.rs b/src/wasm/special_block.rs index 7617268..ea191e3 100644 --- a/src/wasm/special_block.rs +++ b/src/wasm/special_block.rs @@ -1,36 +1,43 @@ +use serde::Deserialize; use serde::Serialize; +use super::ast_node::WasmAstNode; use super::macros::to_wasm; -use super::standard_properties::WasmStandardProperties; use super::to_wasm::ToWasm; +use super::AdditionalProperties; +use crate::compare::ElispFact; use crate::types::SpecialBlock; use crate::wasm::to_wasm::ToWasmStandardProperties; -use crate::wasm::WasmAstNode; -#[derive(Debug, Serialize)] -#[serde(tag = "ast_node")] -#[serde(rename = "org-data")] -pub struct WasmSpecialBlock<'s, 'p> { - standard_properties: WasmStandardProperties, - children: Vec>, +#[derive(Debug, Serialize, Deserialize)] +pub struct WasmSpecialBlock { + #[serde(flatten)] + pub(crate) additional_properties: AdditionalProperties, } to_wasm!( - WasmSpecialBlock<'s, 'p>, + WasmSpecialBlock, SpecialBlock<'s>, original, wasm_context, - standard_properties, + { WasmAstNode::SpecialBlock(original) }, + { "TODO".into() }, { - Ok(WasmSpecialBlock { - standard_properties, - children: Vec::new(), - }) + let children = original + .children + .iter() + .map(|child| { + child + .to_wasm(wasm_context.clone()) + .map(Into::::into) + }) + .collect::, _>>()?; + + Ok(( + children, + WasmSpecialBlock { + additional_properties: AdditionalProperties::default(), + }, + )) } ); - -impl<'s, 'p> Into> for WasmSpecialBlock<'s, 'p> { - fn into(self) -> WasmAstNode<'s, 'p> { - WasmAstNode::SpecialBlock(self) - } -} diff --git a/src/wasm/src_block.rs b/src/wasm/src_block.rs index 67ff1a4..6aac926 100644 --- a/src/wasm/src_block.rs +++ b/src/wasm/src_block.rs @@ -1,36 +1,33 @@ +use serde::Deserialize; use serde::Serialize; +use super::ast_node::WasmAstNode; use super::macros::to_wasm; -use super::standard_properties::WasmStandardProperties; use super::to_wasm::ToWasm; +use super::AdditionalProperties; +use crate::compare::ElispFact; use crate::types::SrcBlock; use crate::wasm::to_wasm::ToWasmStandardProperties; -use crate::wasm::WasmAstNode; -#[derive(Debug, Serialize)] -#[serde(tag = "ast_node")] -#[serde(rename = "org-data")] -pub struct WasmSrcBlock<'s, 'p> { - standard_properties: WasmStandardProperties, - children: Vec>, +#[derive(Debug, Serialize, Deserialize)] +pub struct WasmSrcBlock { + #[serde(flatten)] + pub(crate) additional_properties: AdditionalProperties, } to_wasm!( - WasmSrcBlock<'s, 'p>, + WasmSrcBlock, SrcBlock<'s>, original, wasm_context, - standard_properties, + { WasmAstNode::SrcBlock(original) }, + { "TODO".into() }, { - Ok(WasmSrcBlock { - standard_properties, - children: Vec::new(), - }) + Ok(( + Vec::new(), + WasmSrcBlock { + additional_properties: AdditionalProperties::default(), + }, + )) } ); - -impl<'s, 'p> Into> for WasmSrcBlock<'s, 'p> { - fn into(self) -> WasmAstNode<'s, 'p> { - WasmAstNode::SrcBlock(self) - } -} diff --git a/src/wasm/standard_properties.rs b/src/wasm/standard_properties.rs index ea00c23..de46b16 100644 --- a/src/wasm/standard_properties.rs +++ b/src/wasm/standard_properties.rs @@ -1,3 +1,4 @@ +use serde::Deserialize; use serde::Serialize; use super::to_wasm::ToWasmContext; @@ -5,12 +6,15 @@ use super::to_wasm::ToWasmStandardProperties; use crate::types::PostBlank; use crate::types::StandardProperties; -#[derive(Debug, Serialize)] +#[derive(Debug, Serialize, Deserialize)] pub(crate) struct WasmStandardProperties { pub(crate) begin: usize, pub(crate) end: usize, + #[serde(rename = "contents-begin")] pub(crate) contents_begin: Option, + #[serde(rename = "contents-end")] pub(crate) contents_end: Option, + #[serde(rename = "post-blank")] pub(crate) post_blank: PostBlank, } diff --git a/src/wasm/statistics_cookie.rs b/src/wasm/statistics_cookie.rs index 4cdd774..49aa98a 100644 --- a/src/wasm/statistics_cookie.rs +++ b/src/wasm/statistics_cookie.rs @@ -1,36 +1,33 @@ +use serde::Deserialize; use serde::Serialize; +use super::ast_node::WasmAstNode; use super::macros::to_wasm; -use super::standard_properties::WasmStandardProperties; use super::to_wasm::ToWasm; +use super::AdditionalProperties; +use crate::compare::ElispFact; use crate::types::StatisticsCookie; use crate::wasm::to_wasm::ToWasmStandardProperties; -use crate::wasm::WasmAstNode; -#[derive(Debug, Serialize)] -#[serde(tag = "ast_node")] -#[serde(rename = "org-data")] -pub struct WasmStatisticsCookie<'s, 'p> { - standard_properties: WasmStandardProperties, - children: Vec>, +#[derive(Debug, Serialize, Deserialize)] +pub struct WasmStatisticsCookie { + #[serde(flatten)] + pub(crate) additional_properties: AdditionalProperties, } to_wasm!( - WasmStatisticsCookie<'s, 'p>, + WasmStatisticsCookie, StatisticsCookie<'s>, original, wasm_context, - standard_properties, + { WasmAstNode::StatisticsCookie(original) }, + { "TODO".into() }, { - Ok(WasmStatisticsCookie { - standard_properties, - children: Vec::new(), - }) + Ok(( + Vec::new(), + WasmStatisticsCookie { + additional_properties: AdditionalProperties::default(), + }, + )) } ); - -impl<'s, 'p> Into> for WasmStatisticsCookie<'s, 'p> { - fn into(self) -> WasmAstNode<'s, 'p> { - WasmAstNode::StatisticsCookie(self) - } -} diff --git a/src/wasm/strike_through.rs b/src/wasm/strike_through.rs index 08e97c1..9c272c9 100644 --- a/src/wasm/strike_through.rs +++ b/src/wasm/strike_through.rs @@ -1,36 +1,43 @@ +use serde::Deserialize; use serde::Serialize; +use super::ast_node::WasmAstNode; use super::macros::to_wasm; -use super::standard_properties::WasmStandardProperties; use super::to_wasm::ToWasm; +use super::AdditionalProperties; +use crate::compare::ElispFact; use crate::types::StrikeThrough; use crate::wasm::to_wasm::ToWasmStandardProperties; -use crate::wasm::WasmAstNode; -#[derive(Debug, Serialize)] -#[serde(tag = "ast_node")] -#[serde(rename = "org-data")] -pub struct WasmStrikeThrough<'s, 'p> { - standard_properties: WasmStandardProperties, - children: Vec>, +#[derive(Debug, Serialize, Deserialize)] +pub struct WasmStrikeThrough { + #[serde(flatten)] + pub(crate) additional_properties: AdditionalProperties, } to_wasm!( - WasmStrikeThrough<'s, 'p>, + WasmStrikeThrough, StrikeThrough<'s>, original, wasm_context, - standard_properties, + { WasmAstNode::StrikeThrough(original) }, + { "TODO".into() }, { - Ok(WasmStrikeThrough { - standard_properties, - children: Vec::new(), - }) + let children = original + .children + .iter() + .map(|child| { + child + .to_wasm(wasm_context.clone()) + .map(Into::::into) + }) + .collect::, _>>()?; + + Ok(( + children, + WasmStrikeThrough { + additional_properties: AdditionalProperties::default(), + }, + )) } ); - -impl<'s, 'p> Into> for WasmStrikeThrough<'s, 'p> { - fn into(self) -> WasmAstNode<'s, 'p> { - WasmAstNode::StrikeThrough(self) - } -} diff --git a/src/wasm/subscript.rs b/src/wasm/subscript.rs index 3cd668c..495c099 100644 --- a/src/wasm/subscript.rs +++ b/src/wasm/subscript.rs @@ -1,36 +1,43 @@ +use serde::Deserialize; use serde::Serialize; +use super::ast_node::WasmAstNode; use super::macros::to_wasm; -use super::standard_properties::WasmStandardProperties; use super::to_wasm::ToWasm; +use super::AdditionalProperties; +use crate::compare::ElispFact; use crate::types::Subscript; use crate::wasm::to_wasm::ToWasmStandardProperties; -use crate::wasm::WasmAstNode; -#[derive(Debug, Serialize)] -#[serde(tag = "ast_node")] -#[serde(rename = "org-data")] -pub struct WasmSubscript<'s, 'p> { - standard_properties: WasmStandardProperties, - children: Vec>, +#[derive(Debug, Serialize, Deserialize)] +pub struct WasmSubscript { + #[serde(flatten)] + pub(crate) additional_properties: AdditionalProperties, } to_wasm!( - WasmSubscript<'s, 'p>, + WasmSubscript, Subscript<'s>, original, wasm_context, - standard_properties, + { WasmAstNode::Subscript(original) }, + { "TODO".into() }, { - Ok(WasmSubscript { - standard_properties, - children: Vec::new(), - }) + let children = original + .children + .iter() + .map(|child| { + child + .to_wasm(wasm_context.clone()) + .map(Into::::into) + }) + .collect::, _>>()?; + + Ok(( + children, + WasmSubscript { + additional_properties: AdditionalProperties::default(), + }, + )) } ); - -impl<'s, 'p> Into> for WasmSubscript<'s, 'p> { - fn into(self) -> WasmAstNode<'s, 'p> { - WasmAstNode::Subscript(self) - } -} diff --git a/src/wasm/superscript.rs b/src/wasm/superscript.rs index caf83ff..077025f 100644 --- a/src/wasm/superscript.rs +++ b/src/wasm/superscript.rs @@ -1,36 +1,43 @@ +use serde::Deserialize; use serde::Serialize; +use super::ast_node::WasmAstNode; use super::macros::to_wasm; -use super::standard_properties::WasmStandardProperties; use super::to_wasm::ToWasm; +use super::AdditionalProperties; +use crate::compare::ElispFact; use crate::types::Superscript; use crate::wasm::to_wasm::ToWasmStandardProperties; -use crate::wasm::WasmAstNode; -#[derive(Debug, Serialize)] -#[serde(tag = "ast_node")] -#[serde(rename = "org-data")] -pub struct WasmSuperscript<'s, 'p> { - standard_properties: WasmStandardProperties, - children: Vec>, +#[derive(Debug, Serialize, Deserialize)] +pub struct WasmSuperscript { + #[serde(flatten)] + pub(crate) additional_properties: AdditionalProperties, } to_wasm!( - WasmSuperscript<'s, 'p>, + WasmSuperscript, Superscript<'s>, original, wasm_context, - standard_properties, + { WasmAstNode::Superscript(original) }, + { "TODO".into() }, { - Ok(WasmSuperscript { - standard_properties, - children: Vec::new(), - }) + let children = original + .children + .iter() + .map(|child| { + child + .to_wasm(wasm_context.clone()) + .map(Into::::into) + }) + .collect::, _>>()?; + + Ok(( + children, + WasmSuperscript { + additional_properties: AdditionalProperties::default(), + }, + )) } ); - -impl<'s, 'p> Into> for WasmSuperscript<'s, 'p> { - fn into(self) -> WasmAstNode<'s, 'p> { - WasmAstNode::Superscript(self) - } -} diff --git a/src/wasm/table.rs b/src/wasm/table.rs index 455bc76..8b96484 100644 --- a/src/wasm/table.rs +++ b/src/wasm/table.rs @@ -1,36 +1,43 @@ +use serde::Deserialize; use serde::Serialize; +use super::ast_node::WasmAstNode; use super::macros::to_wasm; -use super::standard_properties::WasmStandardProperties; use super::to_wasm::ToWasm; +use super::AdditionalProperties; +use crate::compare::ElispFact; use crate::types::Table; use crate::wasm::to_wasm::ToWasmStandardProperties; -use crate::wasm::WasmAstNode; -#[derive(Debug, Serialize)] -#[serde(tag = "ast_node")] -#[serde(rename = "org-data")] -pub struct WasmTable<'s, 'p> { - standard_properties: WasmStandardProperties, - children: Vec>, +#[derive(Debug, Serialize, Deserialize)] +pub struct WasmTable { + #[serde(flatten)] + pub(crate) additional_properties: AdditionalProperties, } to_wasm!( - WasmTable<'s, 'p>, + WasmTable, Table<'s>, original, wasm_context, - standard_properties, + { WasmAstNode::Table(original) }, + { "TODO".into() }, { - Ok(WasmTable { - standard_properties, - children: Vec::new(), - }) + let children = original + .children + .iter() + .map(|child| { + child + .to_wasm(wasm_context.clone()) + .map(Into::::into) + }) + .collect::, _>>()?; + + Ok(( + children, + WasmTable { + additional_properties: AdditionalProperties::default(), + }, + )) } ); - -impl<'s, 'p> Into> for WasmTable<'s, 'p> { - fn into(self) -> WasmAstNode<'s, 'p> { - WasmAstNode::Table(self) - } -} diff --git a/src/wasm/table_cell.rs b/src/wasm/table_cell.rs index c26d1b6..7c2978a 100644 --- a/src/wasm/table_cell.rs +++ b/src/wasm/table_cell.rs @@ -1,30 +1,43 @@ +use serde::Deserialize; use serde::Serialize; +use super::ast_node::WasmAstNode; use super::macros::to_wasm; -use super::standard_properties::WasmStandardProperties; use super::to_wasm::ToWasm; +use super::AdditionalProperties; +use crate::compare::ElispFact; use crate::types::TableCell; use crate::wasm::to_wasm::ToWasmStandardProperties; -use crate::wasm::WasmAstNode; -#[derive(Debug, Serialize)] -#[serde(tag = "ast_node")] -#[serde(rename = "org-data")] -pub struct WasmTableCell<'s, 'p> { - standard_properties: WasmStandardProperties, - children: Vec>, +#[derive(Debug, Serialize, Deserialize)] +pub struct WasmTableCell { + #[serde(flatten)] + pub(crate) additional_properties: AdditionalProperties, } to_wasm!( - WasmTableCell<'s, 'p>, + WasmTableCell, TableCell<'s>, original, wasm_context, - standard_properties, + { WasmAstNode::TableCell(original) }, + { "TODO".into() }, { - Ok(WasmTableCell { - standard_properties, - children: Vec::new(), - }) + let children = original + .children + .iter() + .map(|child| { + child + .to_wasm(wasm_context.clone()) + .map(Into::::into) + }) + .collect::, _>>()?; + + Ok(( + children, + WasmTableCell { + additional_properties: AdditionalProperties::default(), + }, + )) } ); diff --git a/src/wasm/table_row.rs b/src/wasm/table_row.rs index d4237d4..e3ee3f1 100644 --- a/src/wasm/table_row.rs +++ b/src/wasm/table_row.rs @@ -1,30 +1,43 @@ +use serde::Deserialize; use serde::Serialize; +use super::ast_node::WasmAstNode; use super::macros::to_wasm; -use super::standard_properties::WasmStandardProperties; use super::to_wasm::ToWasm; +use super::AdditionalProperties; +use crate::compare::ElispFact; use crate::types::TableRow; use crate::wasm::to_wasm::ToWasmStandardProperties; -use crate::wasm::WasmAstNode; -#[derive(Debug, Serialize)] -#[serde(tag = "ast_node")] -#[serde(rename = "org-data")] -pub struct WasmTableRow<'s, 'p> { - standard_properties: WasmStandardProperties, - children: Vec>, +#[derive(Debug, Serialize, Deserialize)] +pub struct WasmTableRow { + #[serde(flatten)] + pub(crate) additional_properties: AdditionalProperties, } to_wasm!( - WasmTableRow<'s, 'p>, + WasmTableRow, TableRow<'s>, original, wasm_context, - standard_properties, + { WasmAstNode::TableRow(original) }, + { "TODO".into() }, { - Ok(WasmTableRow { - standard_properties, - children: Vec::new(), - }) + let children = original + .children + .iter() + .map(|child| { + child + .to_wasm(wasm_context.clone()) + .map(Into::::into) + }) + .collect::, _>>()?; + + Ok(( + children, + WasmTableRow { + additional_properties: AdditionalProperties::default(), + }, + )) } ); diff --git a/src/wasm/target.rs b/src/wasm/target.rs index ff1f533..5b14b4a 100644 --- a/src/wasm/target.rs +++ b/src/wasm/target.rs @@ -1,36 +1,33 @@ +use serde::Deserialize; use serde::Serialize; +use super::ast_node::WasmAstNode; use super::macros::to_wasm; -use super::standard_properties::WasmStandardProperties; use super::to_wasm::ToWasm; +use super::AdditionalProperties; +use crate::compare::ElispFact; use crate::types::Target; use crate::wasm::to_wasm::ToWasmStandardProperties; -use crate::wasm::WasmAstNode; -#[derive(Debug, Serialize)] -#[serde(tag = "ast_node")] -#[serde(rename = "org-data")] -pub struct WasmTarget<'s, 'p> { - standard_properties: WasmStandardProperties, - children: Vec>, +#[derive(Debug, Serialize, Deserialize)] +pub struct WasmTarget { + #[serde(flatten)] + pub(crate) additional_properties: AdditionalProperties, } to_wasm!( - WasmTarget<'s, 'p>, + WasmTarget, Target<'s>, original, wasm_context, - standard_properties, + { WasmAstNode::Target(original) }, + { "TODO".into() }, { - Ok(WasmTarget { - standard_properties, - children: Vec::new(), - }) + Ok(( + Vec::new(), + WasmTarget { + additional_properties: AdditionalProperties::default(), + }, + )) } ); - -impl<'s, 'p> Into> for WasmTarget<'s, 'p> { - fn into(self) -> WasmAstNode<'s, 'p> { - WasmAstNode::Target(self) - } -} diff --git a/src/wasm/timestamp.rs b/src/wasm/timestamp.rs index 38b6ef1..554ad8a 100644 --- a/src/wasm/timestamp.rs +++ b/src/wasm/timestamp.rs @@ -1,36 +1,33 @@ +use serde::Deserialize; use serde::Serialize; +use super::ast_node::WasmAstNode; use super::macros::to_wasm; -use super::standard_properties::WasmStandardProperties; use super::to_wasm::ToWasm; +use super::AdditionalProperties; +use crate::compare::ElispFact; use crate::types::Timestamp; use crate::wasm::to_wasm::ToWasmStandardProperties; -use crate::wasm::WasmAstNode; -#[derive(Debug, Serialize)] -#[serde(tag = "ast_node")] -#[serde(rename = "org-data")] -pub struct WasmTimestamp<'s, 'p> { - standard_properties: WasmStandardProperties, - children: Vec>, +#[derive(Debug, Serialize, Deserialize)] +pub struct WasmTimestamp { + #[serde(flatten)] + pub(crate) additional_properties: AdditionalProperties, } to_wasm!( - WasmTimestamp<'s, 'p>, + WasmTimestamp, Timestamp<'s>, original, wasm_context, - standard_properties, + { WasmAstNode::Timestamp(original) }, + { "TODO".into() }, { - Ok(WasmTimestamp { - standard_properties, - children: Vec::new(), - }) + Ok(( + Vec::new(), + WasmTimestamp { + additional_properties: AdditionalProperties::default(), + }, + )) } ); - -impl<'s, 'p> Into> for WasmTimestamp<'s, 'p> { - fn into(self) -> WasmAstNode<'s, 'p> { - WasmAstNode::Timestamp(self) - } -} diff --git a/src/wasm/to_wasm.rs b/src/wasm/to_wasm.rs index 0db2a2c..7b8211f 100644 --- a/src/wasm/to_wasm.rs +++ b/src/wasm/to_wasm.rs @@ -1,13 +1,14 @@ use super::macros::to_wasm; use super::WasmAstNode; use crate::error::CustomError; +use crate::types::DocumentElement; use crate::types::Element; use crate::types::Object; -pub trait ToWasm<'p> { +pub trait ToWasm { type Output; - fn to_wasm(&'p self, full_document: ToWasmContext<'_>) -> Result; + fn to_wasm(&self, full_document: ToWasmContext<'_>) -> Result; } pub(crate) trait ToWasmStandardProperties { @@ -30,125 +31,94 @@ impl<'s> ToWasmContext<'s> { } } -to_wasm!( - WasmAstNode<'s, 'p>, - Element<'s>, - original, - wasm_context, - standard_properties, - { - match original { - Element::Paragraph(inner) => inner.to_wasm(wasm_context).map(Into::::into), - Element::PlainList(inner) => inner.to_wasm(wasm_context).map(Into::::into), - Element::CenterBlock(inner) => { - inner.to_wasm(wasm_context).map(Into::::into) - } - Element::QuoteBlock(inner) => { - inner.to_wasm(wasm_context).map(Into::::into) - } - Element::SpecialBlock(inner) => { - inner.to_wasm(wasm_context).map(Into::::into) - } - Element::DynamicBlock(inner) => { - inner.to_wasm(wasm_context).map(Into::::into) - } - Element::FootnoteDefinition(inner) => { - inner.to_wasm(wasm_context).map(Into::::into) - } - Element::Comment(inner) => inner.to_wasm(wasm_context).map(Into::::into), - Element::Drawer(inner) => inner.to_wasm(wasm_context).map(Into::::into), - Element::PropertyDrawer(inner) => { - inner.to_wasm(wasm_context).map(Into::::into) - } - Element::Table(inner) => inner.to_wasm(wasm_context).map(Into::::into), - Element::VerseBlock(inner) => { - inner.to_wasm(wasm_context).map(Into::::into) - } - Element::CommentBlock(inner) => { - inner.to_wasm(wasm_context).map(Into::::into) - } - Element::ExampleBlock(inner) => { - inner.to_wasm(wasm_context).map(Into::::into) - } - Element::ExportBlock(inner) => { - inner.to_wasm(wasm_context).map(Into::::into) - } - Element::SrcBlock(inner) => inner.to_wasm(wasm_context).map(Into::::into), - Element::Clock(inner) => inner.to_wasm(wasm_context).map(Into::::into), - Element::DiarySexp(inner) => inner.to_wasm(wasm_context).map(Into::::into), - Element::Planning(inner) => inner.to_wasm(wasm_context).map(Into::::into), - Element::FixedWidthArea(inner) => { - inner.to_wasm(wasm_context).map(Into::::into) - } - Element::HorizontalRule(inner) => { - inner.to_wasm(wasm_context).map(Into::::into) - } - Element::Keyword(inner) => inner.to_wasm(wasm_context).map(Into::::into), - Element::BabelCall(inner) => inner.to_wasm(wasm_context).map(Into::::into), - Element::LatexEnvironment(inner) => { - inner.to_wasm(wasm_context).map(Into::::into) - } +to_wasm!(WasmAstNode, DocumentElement<'s>, original, wasm_context, { + match original { + DocumentElement::Heading(inner) => { + inner.to_wasm(wasm_context).map(Into::::into) + } + DocumentElement::Section(inner) => { + inner.to_wasm(wasm_context).map(Into::::into) } } -); +}); -to_wasm!( - WasmAstNode<'s, 'p>, - Object<'s>, - original, - wasm_context, - standard_properties, - { - match original { - Object::Bold(inner) => inner.to_wasm(wasm_context).map(Into::::into), - Object::Italic(inner) => inner.to_wasm(wasm_context).map(Into::::into), - Object::Underline(inner) => inner.to_wasm(wasm_context).map(Into::::into), - Object::StrikeThrough(inner) => { - inner.to_wasm(wasm_context).map(Into::::into) - } - Object::Code(inner) => inner.to_wasm(wasm_context).map(Into::::into), - Object::Verbatim(inner) => inner.to_wasm(wasm_context).map(Into::::into), - Object::PlainText(inner) => inner.to_wasm(wasm_context).map(Into::::into), - Object::RegularLink(inner) => { - inner.to_wasm(wasm_context).map(Into::::into) - } - Object::RadioLink(inner) => inner.to_wasm(wasm_context).map(Into::::into), - Object::RadioTarget(inner) => { - inner.to_wasm(wasm_context).map(Into::::into) - } - Object::PlainLink(inner) => inner.to_wasm(wasm_context).map(Into::::into), - Object::AngleLink(inner) => inner.to_wasm(wasm_context).map(Into::::into), - Object::OrgMacro(inner) => inner.to_wasm(wasm_context).map(Into::::into), - Object::Entity(inner) => inner.to_wasm(wasm_context).map(Into::::into), - Object::LatexFragment(inner) => { - inner.to_wasm(wasm_context).map(Into::::into) - } - Object::ExportSnippet(inner) => { - inner.to_wasm(wasm_context).map(Into::::into) - } - Object::FootnoteReference(inner) => { - inner.to_wasm(wasm_context).map(Into::::into) - } - Object::Citation(inner) => inner.to_wasm(wasm_context).map(Into::::into), - Object::CitationReference(inner) => { - inner.to_wasm(wasm_context).map(Into::::into) - } - Object::InlineBabelCall(inner) => { - inner.to_wasm(wasm_context).map(Into::::into) - } - Object::InlineSourceBlock(inner) => { - inner.to_wasm(wasm_context).map(Into::::into) - } - Object::LineBreak(inner) => inner.to_wasm(wasm_context).map(Into::::into), - Object::Target(inner) => inner.to_wasm(wasm_context).map(Into::::into), - Object::StatisticsCookie(inner) => { - inner.to_wasm(wasm_context).map(Into::::into) - } - Object::Subscript(inner) => inner.to_wasm(wasm_context).map(Into::::into), - Object::Superscript(inner) => { - inner.to_wasm(wasm_context).map(Into::::into) - } - Object::Timestamp(inner) => inner.to_wasm(wasm_context).map(Into::::into), +to_wasm!(WasmAstNode, Element<'s>, original, wasm_context, { + match original { + Element::Paragraph(inner) => inner.to_wasm(wasm_context).map(Into::::into), + Element::PlainList(inner) => inner.to_wasm(wasm_context).map(Into::::into), + Element::CenterBlock(inner) => inner.to_wasm(wasm_context).map(Into::::into), + Element::QuoteBlock(inner) => inner.to_wasm(wasm_context).map(Into::::into), + Element::SpecialBlock(inner) => inner.to_wasm(wasm_context).map(Into::::into), + Element::DynamicBlock(inner) => inner.to_wasm(wasm_context).map(Into::::into), + Element::FootnoteDefinition(inner) => { + inner.to_wasm(wasm_context).map(Into::::into) + } + Element::Comment(inner) => inner.to_wasm(wasm_context).map(Into::::into), + Element::Drawer(inner) => inner.to_wasm(wasm_context).map(Into::::into), + Element::PropertyDrawer(inner) => { + inner.to_wasm(wasm_context).map(Into::::into) + } + Element::Table(inner) => inner.to_wasm(wasm_context).map(Into::::into), + Element::VerseBlock(inner) => inner.to_wasm(wasm_context).map(Into::::into), + Element::CommentBlock(inner) => inner.to_wasm(wasm_context).map(Into::::into), + Element::ExampleBlock(inner) => inner.to_wasm(wasm_context).map(Into::::into), + Element::ExportBlock(inner) => inner.to_wasm(wasm_context).map(Into::::into), + Element::SrcBlock(inner) => inner.to_wasm(wasm_context).map(Into::::into), + Element::Clock(inner) => inner.to_wasm(wasm_context).map(Into::::into), + Element::DiarySexp(inner) => inner.to_wasm(wasm_context).map(Into::::into), + Element::Planning(inner) => inner.to_wasm(wasm_context).map(Into::::into), + Element::FixedWidthArea(inner) => { + inner.to_wasm(wasm_context).map(Into::::into) + } + Element::HorizontalRule(inner) => { + inner.to_wasm(wasm_context).map(Into::::into) + } + Element::Keyword(inner) => inner.to_wasm(wasm_context).map(Into::::into), + Element::BabelCall(inner) => inner.to_wasm(wasm_context).map(Into::::into), + Element::LatexEnvironment(inner) => { + inner.to_wasm(wasm_context).map(Into::::into) } } -); +}); + +to_wasm!(WasmAstNode, Object<'s>, original, wasm_context, { + match original { + Object::Bold(inner) => inner.to_wasm(wasm_context).map(Into::::into), + Object::Italic(inner) => inner.to_wasm(wasm_context).map(Into::::into), + Object::Underline(inner) => inner.to_wasm(wasm_context).map(Into::::into), + Object::StrikeThrough(inner) => inner.to_wasm(wasm_context).map(Into::::into), + Object::Code(inner) => inner.to_wasm(wasm_context).map(Into::::into), + Object::Verbatim(inner) => inner.to_wasm(wasm_context).map(Into::::into), + Object::PlainText(inner) => inner.to_wasm(wasm_context).map(Into::::into), + Object::RegularLink(inner) => inner.to_wasm(wasm_context).map(Into::::into), + Object::RadioLink(inner) => inner.to_wasm(wasm_context).map(Into::::into), + Object::RadioTarget(inner) => inner.to_wasm(wasm_context).map(Into::::into), + Object::PlainLink(inner) => inner.to_wasm(wasm_context).map(Into::::into), + Object::AngleLink(inner) => inner.to_wasm(wasm_context).map(Into::::into), + Object::OrgMacro(inner) => inner.to_wasm(wasm_context).map(Into::::into), + Object::Entity(inner) => inner.to_wasm(wasm_context).map(Into::::into), + Object::LatexFragment(inner) => inner.to_wasm(wasm_context).map(Into::::into), + Object::ExportSnippet(inner) => inner.to_wasm(wasm_context).map(Into::::into), + Object::FootnoteReference(inner) => { + inner.to_wasm(wasm_context).map(Into::::into) + } + Object::Citation(inner) => inner.to_wasm(wasm_context).map(Into::::into), + Object::CitationReference(inner) => { + inner.to_wasm(wasm_context).map(Into::::into) + } + Object::InlineBabelCall(inner) => { + inner.to_wasm(wasm_context).map(Into::::into) + } + Object::InlineSourceBlock(inner) => { + inner.to_wasm(wasm_context).map(Into::::into) + } + Object::LineBreak(inner) => inner.to_wasm(wasm_context).map(Into::::into), + Object::Target(inner) => inner.to_wasm(wasm_context).map(Into::::into), + Object::StatisticsCookie(inner) => { + inner.to_wasm(wasm_context).map(Into::::into) + } + Object::Subscript(inner) => inner.to_wasm(wasm_context).map(Into::::into), + Object::Superscript(inner) => inner.to_wasm(wasm_context).map(Into::::into), + Object::Timestamp(inner) => inner.to_wasm(wasm_context).map(Into::::into), + } +}); diff --git a/src/wasm/underline.rs b/src/wasm/underline.rs index 11e3830..6cedab3 100644 --- a/src/wasm/underline.rs +++ b/src/wasm/underline.rs @@ -1,36 +1,43 @@ +use serde::Deserialize; use serde::Serialize; +use super::ast_node::WasmAstNode; use super::macros::to_wasm; -use super::standard_properties::WasmStandardProperties; use super::to_wasm::ToWasm; +use super::AdditionalProperties; +use crate::compare::ElispFact; use crate::types::Underline; use crate::wasm::to_wasm::ToWasmStandardProperties; -use crate::wasm::WasmAstNode; -#[derive(Debug, Serialize)] -#[serde(tag = "ast_node")] -#[serde(rename = "org-data")] -pub struct WasmUnderline<'s, 'p> { - standard_properties: WasmStandardProperties, - children: Vec>, +#[derive(Debug, Serialize, Deserialize)] +pub struct WasmUnderline { + #[serde(flatten)] + pub(crate) additional_properties: AdditionalProperties, } to_wasm!( - WasmUnderline<'s, 'p>, + WasmUnderline, Underline<'s>, original, wasm_context, - standard_properties, + { WasmAstNode::Underline(original) }, + { "TODO".into() }, { - Ok(WasmUnderline { - standard_properties, - children: Vec::new(), - }) + let children = original + .children + .iter() + .map(|child| { + child + .to_wasm(wasm_context.clone()) + .map(Into::::into) + }) + .collect::, _>>()?; + + Ok(( + children, + WasmUnderline { + additional_properties: AdditionalProperties::default(), + }, + )) } ); - -impl<'s, 'p> Into> for WasmUnderline<'s, 'p> { - fn into(self) -> WasmAstNode<'s, 'p> { - WasmAstNode::Underline(self) - } -} diff --git a/src/wasm/verbatim.rs b/src/wasm/verbatim.rs index 57ea20d..1655112 100644 --- a/src/wasm/verbatim.rs +++ b/src/wasm/verbatim.rs @@ -1,36 +1,33 @@ +use serde::Deserialize; use serde::Serialize; +use super::ast_node::WasmAstNode; use super::macros::to_wasm; -use super::standard_properties::WasmStandardProperties; use super::to_wasm::ToWasm; +use super::AdditionalProperties; +use crate::compare::ElispFact; use crate::types::Verbatim; use crate::wasm::to_wasm::ToWasmStandardProperties; -use crate::wasm::WasmAstNode; -#[derive(Debug, Serialize)] -#[serde(tag = "ast_node")] -#[serde(rename = "org-data")] -pub struct WasmVerbatim<'s, 'p> { - standard_properties: WasmStandardProperties, - children: Vec>, +#[derive(Debug, Serialize, Deserialize)] +pub struct WasmVerbatim { + #[serde(flatten)] + pub(crate) additional_properties: AdditionalProperties, } to_wasm!( - WasmVerbatim<'s, 'p>, + WasmVerbatim, Verbatim<'s>, original, wasm_context, - standard_properties, + { WasmAstNode::Verbatim(original) }, + { "TODO".into() }, { - Ok(WasmVerbatim { - standard_properties, - children: Vec::new(), - }) + Ok(( + Vec::new(), + WasmVerbatim { + additional_properties: AdditionalProperties::default(), + }, + )) } ); - -impl<'s, 'p> Into> for WasmVerbatim<'s, 'p> { - fn into(self) -> WasmAstNode<'s, 'p> { - WasmAstNode::Verbatim(self) - } -} diff --git a/src/wasm/verse_block.rs b/src/wasm/verse_block.rs index 8693b6c..9520dbf 100644 --- a/src/wasm/verse_block.rs +++ b/src/wasm/verse_block.rs @@ -1,36 +1,43 @@ +use serde::Deserialize; use serde::Serialize; +use super::ast_node::WasmAstNode; use super::macros::to_wasm; -use super::standard_properties::WasmStandardProperties; use super::to_wasm::ToWasm; +use super::AdditionalProperties; +use crate::compare::ElispFact; use crate::types::VerseBlock; use crate::wasm::to_wasm::ToWasmStandardProperties; -use crate::wasm::WasmAstNode; -#[derive(Debug, Serialize)] -#[serde(tag = "ast_node")] -#[serde(rename = "org-data")] -pub struct WasmVerseBlock<'s, 'p> { - standard_properties: WasmStandardProperties, - children: Vec>, +#[derive(Debug, Serialize, Deserialize)] +pub struct WasmVerseBlock { + #[serde(flatten)] + pub(crate) additional_properties: AdditionalProperties, } to_wasm!( - WasmVerseBlock<'s, 'p>, + WasmVerseBlock, VerseBlock<'s>, original, wasm_context, - standard_properties, + { WasmAstNode::VerseBlock(original) }, + { "TODO".into() }, { - Ok(WasmVerseBlock { - standard_properties, - children: Vec::new(), - }) + let children = original + .children + .iter() + .map(|child| { + child + .to_wasm(wasm_context.clone()) + .map(Into::::into) + }) + .collect::, _>>()?; + + Ok(( + children, + WasmVerseBlock { + additional_properties: AdditionalProperties::default(), + }, + )) } ); - -impl<'s, 'p> Into> for WasmVerseBlock<'s, 'p> { - fn into(self) -> WasmAstNode<'s, 'p> { - WasmAstNode::VerseBlock(self) - } -} diff --git a/src/wasm_test/compare.rs b/src/wasm_test/compare.rs index dc5d67b..6169f75 100644 --- a/src/wasm_test/compare.rs +++ b/src/wasm_test/compare.rs @@ -1,1731 +1,651 @@ +use std::borrow::Cow; +use std::collections::HashMap; + use super::diff::WasmDiffResult; use super::diff::WasmDiffStatus; -use super::elisp_compare::WasmElispCompare; -use super::logic::wasm_compare_additional_properties; -use super::logic::wasm_compare_list; -use super::logic::wasm_compare_property_quoted_string; -use super::logic::wasm_compare_standard_properties; -use crate::compare::ElispFact; -use crate::compare::EmacsField; +use crate::compare::maybe_token_to_usize; +use crate::compare::unquote; +use crate::compare::EmacsStandardProperties; +use crate::compare::TextWithProperties; use crate::compare::Token; -use crate::wasm::WasmAngleLink; -use crate::wasm::WasmAstNode; -use crate::wasm::WasmBabelCall; -use crate::wasm::WasmBold; -use crate::wasm::WasmCenterBlock; -use crate::wasm::WasmCitation; -use crate::wasm::WasmCitationReference; -use crate::wasm::WasmClock; -use crate::wasm::WasmCode; -use crate::wasm::WasmComment; -use crate::wasm::WasmCommentBlock; -use crate::wasm::WasmDiarySexp; +use crate::wasm::WasmAstNodeWrapper; use crate::wasm::WasmDocument; -use crate::wasm::WasmDrawer; -use crate::wasm::WasmDynamicBlock; -use crate::wasm::WasmEntity; -use crate::wasm::WasmExampleBlock; -use crate::wasm::WasmExportBlock; -use crate::wasm::WasmExportSnippet; -use crate::wasm::WasmFixedWidthArea; -use crate::wasm::WasmFootnoteDefinition; -use crate::wasm::WasmFootnoteReference; -use crate::wasm::WasmHeadline; -use crate::wasm::WasmHorizontalRule; -use crate::wasm::WasmInlineBabelCall; -use crate::wasm::WasmInlineSourceBlock; -use crate::wasm::WasmItalic; -use crate::wasm::WasmKeyword; -use crate::wasm::WasmLatexEnvironment; -use crate::wasm::WasmLatexFragment; -use crate::wasm::WasmLineBreak; -use crate::wasm::WasmNodeProperty; -use crate::wasm::WasmOrgMacro; -use crate::wasm::WasmParagraph; -use crate::wasm::WasmPlainLink; -use crate::wasm::WasmPlainList; -use crate::wasm::WasmPlainListItem; -use crate::wasm::WasmPlainText; -use crate::wasm::WasmPlanning; -use crate::wasm::WasmPropertyDrawer; -use crate::wasm::WasmQuoteBlock; -use crate::wasm::WasmRadioLink; -use crate::wasm::WasmRadioTarget; -use crate::wasm::WasmRegularLink; -use crate::wasm::WasmSection; -use crate::wasm::WasmSpecialBlock; -use crate::wasm::WasmSrcBlock; -use crate::wasm::WasmStatisticsCookie; -use crate::wasm::WasmStrikeThrough; -use crate::wasm::WasmSubscript; -use crate::wasm::WasmSuperscript; -use crate::wasm::WasmTable; -use crate::wasm::WasmTableCell; -use crate::wasm::WasmTableRow; -use crate::wasm::WasmTarget; -use crate::wasm::WasmTimestamp; -use crate::wasm::WasmUnderline; -use crate::wasm::WasmVerbatim; -use crate::wasm::WasmVerseBlock; -use crate::wasm_test::macros::wasm_compare; -pub fn wasm_compare_document<'b, 's, 'p>( +pub fn wasm_compare_document<'e, 's, 'w>( + source: &'s str, + emacs: &'e Token<'s>, + wasm: &'w WasmAstNodeWrapper, +) -> Result, Box> { + let wasm_json = serde_json::to_string(&wasm)?; + let wasm_json_parsed = serde_json::from_str(&wasm_json)?; + compare_json_value(source, emacs, &wasm_json_parsed) +} + +fn compare_json_value<'b, 's>( source: &'s str, emacs: &'b Token<'s>, - wasm: WasmDocument<'s, 'p>, + wasm: &serde_json::Value, ) -> Result, Box> { - wasm.compare_ast_node(source, emacs) -} - -impl<'s, 'p, WAN: WasmElispCompare<'s, 'p>> WasmElispCompare<'s, 'p> for &WAN { - fn compare_ast_node<'b>( - &self, - source: &'s str, - emacs: &'b Token<'s>, - ) -> Result, Box> { - (*self).compare_ast_node(source, emacs) + // println!("XXXXXXXXXXXXXX compare_json_value XXXXXXXXXXXXXX"); + // println!("{:?}", emacs); + // println!("{:?}", wasm); + // println!("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"); + match (wasm, emacs) { + (serde_json::Value::Object(wasm), Token::List(el)) if wasm.contains_key("ast-node") => { + // We hit a regular ast node. + compare_ast_node(source, el, wasm) + } + (serde_json::Value::String(w), Token::Atom(e)) + if e.starts_with('"') && e.ends_with('"') => + { + // We hit a string compared against a quoted string from elisp (as opposed to an unquoted literal). + compare_quoted_string(source, e, w) + } + (serde_json::Value::Array(w), Token::List(e)) => { + // TODO: This is creating children with no names. + wasm_compare_list(source, e.iter(), w.iter()) + } + (serde_json::Value::Object(wasm), Token::List(e)) + if wasm.contains_key("optval") && wasm.contains_key("val") => + { + compare_optional_pair(source, e, wasm) + } + (serde_json::Value::Object(wasm), Token::List(el)) if wasm.contains_key("object-tree") => { + // We hit an object tree additional property. + compare_object_tree(source, el, wasm) + } + (serde_json::Value::Object(w), Token::TextWithProperties(e)) if is_plain_text(w) => { + compare_plain_text(source, e, w) + } + (serde_json::Value::Null, Token::Atom(_)) => todo!(), + (serde_json::Value::Null, Token::List(_)) => todo!(), + (serde_json::Value::Null, Token::TextWithProperties(_)) => todo!(), + (serde_json::Value::Null, Token::Vector(_)) => todo!(), + (serde_json::Value::Bool(_), Token::Atom(_)) => todo!(), + (serde_json::Value::Bool(_), Token::List(_)) => todo!(), + (serde_json::Value::Bool(_), Token::TextWithProperties(_)) => todo!(), + (serde_json::Value::Bool(_), Token::Vector(_)) => todo!(), + (serde_json::Value::Number(_), Token::Atom(_)) => todo!(), + (serde_json::Value::Number(_), Token::List(_)) => todo!(), + (serde_json::Value::Number(_), Token::TextWithProperties(_)) => todo!(), + (serde_json::Value::Number(_), Token::Vector(_)) => todo!(), + (serde_json::Value::String(_), Token::Atom(_)) => todo!(), + (serde_json::Value::String(_), Token::List(_)) => todo!(), + (serde_json::Value::String(_), Token::TextWithProperties(_)) => todo!(), + (serde_json::Value::String(_), Token::Vector(_)) => todo!(), + (serde_json::Value::Array(_), Token::Atom(_)) => todo!(), + // (serde_json::Value::Array(_), Token::List(_)) => todo!(), + (serde_json::Value::Array(_), Token::TextWithProperties(_)) => todo!(), + (serde_json::Value::Array(_), Token::Vector(_)) => todo!(), + (serde_json::Value::Object(_), Token::Atom(_)) => todo!(), + (serde_json::Value::Object(_), Token::List(_)) => todo!(), + (serde_json::Value::Object(_), Token::TextWithProperties(_)) => todo!(), + (serde_json::Value::Object(_), Token::Vector(_)) => todo!(), } } -impl<'s, 'p> WasmElispCompare<'s, 'p> for WasmAstNode<'s, 'p> { - fn compare_ast_node<'b>( - &self, - source: &'s str, - emacs: &'b Token<'s>, - ) -> Result, Box> { - match self { - WasmAstNode::Document(inner) => inner.compare_ast_node(source, emacs), - WasmAstNode::Headline(inner) => inner.compare_ast_node(source, emacs), - WasmAstNode::Section(inner) => inner.compare_ast_node(source, emacs), - WasmAstNode::Paragraph(inner) => inner.compare_ast_node(source, emacs), - WasmAstNode::PlainList(inner) => inner.compare_ast_node(source, emacs), - WasmAstNode::PlainListItem(inner) => inner.compare_ast_node(source, emacs), - WasmAstNode::CenterBlock(inner) => inner.compare_ast_node(source, emacs), - WasmAstNode::QuoteBlock(inner) => inner.compare_ast_node(source, emacs), - WasmAstNode::SpecialBlock(inner) => inner.compare_ast_node(source, emacs), - WasmAstNode::DynamicBlock(inner) => inner.compare_ast_node(source, emacs), - WasmAstNode::FootnoteDefinition(inner) => inner.compare_ast_node(source, emacs), - WasmAstNode::Comment(inner) => inner.compare_ast_node(source, emacs), - WasmAstNode::Drawer(inner) => inner.compare_ast_node(source, emacs), - WasmAstNode::PropertyDrawer(inner) => inner.compare_ast_node(source, emacs), - WasmAstNode::NodeProperty(inner) => inner.compare_ast_node(source, emacs), - WasmAstNode::Table(inner) => inner.compare_ast_node(source, emacs), - WasmAstNode::TableRow(inner) => inner.compare_ast_node(source, emacs), - WasmAstNode::VerseBlock(inner) => inner.compare_ast_node(source, emacs), - WasmAstNode::CommentBlock(inner) => inner.compare_ast_node(source, emacs), - WasmAstNode::ExampleBlock(inner) => inner.compare_ast_node(source, emacs), - WasmAstNode::ExportBlock(inner) => inner.compare_ast_node(source, emacs), - WasmAstNode::SrcBlock(inner) => inner.compare_ast_node(source, emacs), - WasmAstNode::Clock(inner) => inner.compare_ast_node(source, emacs), - WasmAstNode::DiarySexp(inner) => inner.compare_ast_node(source, emacs), - WasmAstNode::Planning(inner) => inner.compare_ast_node(source, emacs), - WasmAstNode::FixedWidthArea(inner) => inner.compare_ast_node(source, emacs), - WasmAstNode::HorizontalRule(inner) => inner.compare_ast_node(source, emacs), - WasmAstNode::Keyword(inner) => inner.compare_ast_node(source, emacs), - WasmAstNode::BabelCall(inner) => inner.compare_ast_node(source, emacs), - WasmAstNode::LatexEnvironment(inner) => inner.compare_ast_node(source, emacs), - WasmAstNode::Bold(inner) => inner.compare_ast_node(source, emacs), - WasmAstNode::Italic(inner) => inner.compare_ast_node(source, emacs), - WasmAstNode::Underline(inner) => inner.compare_ast_node(source, emacs), - WasmAstNode::StrikeThrough(inner) => inner.compare_ast_node(source, emacs), - WasmAstNode::Code(inner) => inner.compare_ast_node(source, emacs), - WasmAstNode::Verbatim(inner) => inner.compare_ast_node(source, emacs), - WasmAstNode::PlainText(inner) => inner.compare_ast_node(source, emacs), - WasmAstNode::RegularLink(inner) => inner.compare_ast_node(source, emacs), - WasmAstNode::RadioLink(inner) => inner.compare_ast_node(source, emacs), - WasmAstNode::RadioTarget(inner) => inner.compare_ast_node(source, emacs), - WasmAstNode::PlainLink(inner) => inner.compare_ast_node(source, emacs), - WasmAstNode::AngleLink(inner) => inner.compare_ast_node(source, emacs), - WasmAstNode::OrgMacro(inner) => inner.compare_ast_node(source, emacs), - WasmAstNode::Entity(inner) => inner.compare_ast_node(source, emacs), - WasmAstNode::LatexFragment(inner) => inner.compare_ast_node(source, emacs), - WasmAstNode::ExportSnippet(inner) => inner.compare_ast_node(source, emacs), - WasmAstNode::FootnoteReference(inner) => inner.compare_ast_node(source, emacs), - WasmAstNode::Citation(inner) => inner.compare_ast_node(source, emacs), - WasmAstNode::CitationReference(inner) => inner.compare_ast_node(source, emacs), - WasmAstNode::InlineBabelCall(inner) => inner.compare_ast_node(source, emacs), - WasmAstNode::InlineSourceBlock(inner) => inner.compare_ast_node(source, emacs), - WasmAstNode::LineBreak(inner) => inner.compare_ast_node(source, emacs), - WasmAstNode::Target(inner) => inner.compare_ast_node(source, emacs), - WasmAstNode::StatisticsCookie(inner) => inner.compare_ast_node(source, emacs), - WasmAstNode::Subscript(inner) => inner.compare_ast_node(source, emacs), - WasmAstNode::Superscript(inner) => inner.compare_ast_node(source, emacs), - WasmAstNode::TableCell(inner) => inner.compare_ast_node(source, emacs), - WasmAstNode::Timestamp(inner) => inner.compare_ast_node(source, emacs), +fn compare_ast_node<'e, 's, 'w>( + source: &'s str, + emacs: &'e Vec>, + wasm: &'w serde_json::Map, +) -> Result, Box> { + let mut result = WasmDiffResult::default(); + let mut emacs_list_iter = emacs.iter(); + + { + // Compare ast node type. + let emacs_name = emacs_list_iter + .next() + .ok_or("Should have a name as the first child.")? + .as_atom()?; + let wasm_name = wasm + .get("ast-node") + .ok_or("Should have a ast node type.")? + .as_str() + .ok_or("Ast node type should be a string.")?; + result.name = emacs_name.into(); + if emacs_name != wasm_name { + result.status.push(WasmDiffStatus::Bad( + format!( + "AST node name mismatch. Emacs=({emacs}) Wasm=({wasm}).", + emacs = emacs_name, + wasm = wasm_name, + ) + .into(), + )); } } + + if result.is_bad() { + return Ok(result); + } + + let emacs_attributes_map = emacs_list_iter + .next() + .ok_or("Should have an attributes child.")? + .as_map()?; + let wasm_attributes_map = wasm + .get("properties") + .ok_or(r#"Wasm ast node should have a "properties" attribute."#)? + .as_object() + .ok_or(r#"Wasm ast node "properties" attribute should be an object."#)?; + + { + // Compare attribute names. + let emacs_keys: std::collections::BTreeSet = emacs_attributes_map + .keys() + .map(|s| (*s).to_owned()) + .collect(); + let wasm_keys: std::collections::BTreeSet = + std::iter::once(":standard-properties".to_owned()) + .chain(wasm_attributes_map.keys().map(wasm_key_to_emacs_key)) + .collect(); + let emacs_only_attributes: Vec<&String> = emacs_keys.difference(&wasm_keys).collect(); + let wasm_only_attributes: Vec<&String> = wasm_keys.difference(&emacs_keys).collect(); + if !emacs_only_attributes.is_empty() { + result.status.push(WasmDiffStatus::Bad( + format!( + "Wasm node lacked field present in elisp node ({name}).", + name = emacs_only_attributes + .iter() + .map(|s| s.as_str()) + .intersperse(", ") + .collect::(), + ) + .into(), + )); + } + if !wasm_only_attributes.is_empty() { + result.status.push(WasmDiffStatus::Bad( + format!( + "Elisp node lacked field present in wasm node ({name}).", + name = wasm_only_attributes + .iter() + .map(|s| s.as_str()) + .intersperse(", ") + .collect::(), + ) + .into(), + )); + } + } + + if result.is_bad() { + return Ok(result); + } + + { + // Compare attributes. + for attribute_name in wasm_attributes_map.keys() { + let mut layer = WasmDiffResult::default(); + layer.name = Cow::Owned(attribute_name.clone()); + let wasm_attribute_value = wasm_attributes_map + .get(attribute_name) + .ok_or("Key should exist in both wasm and elisp at this point.")?; + let emacs_key = wasm_key_to_emacs_key(attribute_name); + let emacs_attribute_value = *emacs_attributes_map + .get(emacs_key.as_str()) + .ok_or("Key should exist in both wasm and elisp at this point.")?; + layer.extend(compare_json_value( + source, + emacs_attribute_value, + wasm_attribute_value, + )?)?; + result.children.push(layer); + } + } + + { + // Compare standard-properties. + let mut layer = WasmDiffResult::default(); + layer.name = "standard-properties".into(); + let emacs_standard_properties = wasm_get_emacs_standard_properties(&emacs_attributes_map)?; + let wasm_standard_properties = wasm + .get("standard-properties") + .ok_or(r#"Wasm AST nodes should have a "standard-properties" attribute."#)? + .as_object() + .ok_or(r#"Wasm ast node "standard-properties" attribute should be an object."#)?; + for (emacs_value, wasm_name) in [ + (emacs_standard_properties.begin, "begin"), + (emacs_standard_properties.end, "end"), + (emacs_standard_properties.contents_begin, "contents-begin"), + (emacs_standard_properties.contents_end, "contents-end"), + (emacs_standard_properties.post_blank, "post-blank"), + ] { + match (emacs_value, wasm_standard_properties.get(wasm_name)) { + (None, None) => {} + (None, Some(_)) => { + layer.status.push(WasmDiffStatus::Bad( + format!( + "Elisp node lacked field present in wasm node. Name=({name}).", + name = wasm_name, + ) + .into(), + )); + } + (Some(_), None) => { + layer.status.push(WasmDiffStatus::Bad( + format!( + "Wasm node lacked field present in elisp node. Name=({name}).", + name = wasm_name, + ) + .into(), + )); + } + (Some(e), Some(serde_json::Value::Number(w))) + if w.as_u64().map(|w| w as usize) == Some(e) => {} + (Some(e), Some(w)) => { + layer.status.push(WasmDiffStatus::Bad( + format!( + "Property value mismatch. Emacs=({emacs:?}) Wasm=({wasm:?}).", + emacs = e, + wasm = w, + ) + .into(), + )); + } + } + } + result.children.push(layer); + } + + { + // Compare children. + let mut layer = WasmDiffResult::default(); + layer.name = "children".into(); + if let Some(wasm_iter) = wasm + .get("children") + .map(|children| children.as_array()) + .flatten() + .map(|children| children.iter()) + { + layer.extend(wasm_compare_list(source, emacs_list_iter, wasm_iter)?)?; + } else { + layer.extend(wasm_compare_list( + source, + emacs_list_iter, + std::iter::empty::<&serde_json::Value>(), + )?)?; + } + result.children.push(layer); + } + + Ok(result) } -impl<'s, 'p> WasmElispCompare<'s, 'p> for WasmDocument<'s, 'p> { - fn compare_ast_node<'b>( - &self, - source: &'s str, - emacs: &'b Token<'s>, - ) -> Result, Box> { - let result = wasm_compare!( - source, - emacs, - self, - ( - EmacsField::Required(":path"), - |w| w.path.as_ref().and_then(|p| p.to_str()), - wasm_compare_property_quoted_string - ), - ( - EmacsField::Required(":CATEGORY"), - |w| w.category.as_ref(), - wasm_compare_property_quoted_string +fn wasm_key_to_emacs_key(wasm_key: WK) -> String { + format!(":{key}", key = wasm_key) +} + +fn compare_quoted_string<'e, 's, 'w>( + source: &'s str, + emacs: &'e str, + wasm: &'w String, +) -> Result, Box> { + let mut result = WasmDiffResult::default(); + let emacs_text = unquote(emacs)?; + if wasm.as_str() != emacs_text { + result.status.push(WasmDiffStatus::Bad( + format!( + "Text mismatch. Emacs=({emacs:?}) Wasm=({wasm:?}).", + emacs = emacs_text, + wasm = wasm, ) - ); - Ok(result) + .into(), + )); + } + Ok(result) +} + +pub(crate) fn wasm_get_emacs_standard_properties( + attributes_map: &HashMap<&str, &Token<'_>>, +) -> Result> { + let standard_properties = attributes_map.get(":standard-properties"); + Ok(if standard_properties.is_some() { + let mut std_props = standard_properties + .expect("if statement proves its Some") + .as_vector()? + .iter(); + let begin = maybe_token_to_usize(std_props.next())?; + let post_affiliated = maybe_token_to_usize(std_props.next())?; + let contents_begin = maybe_token_to_usize(std_props.next())?; + let contents_end = maybe_token_to_usize(std_props.next())?; + let end = maybe_token_to_usize(std_props.next())?; + let post_blank = maybe_token_to_usize(std_props.next())?; + EmacsStandardProperties { + begin, + post_affiliated, + contents_begin, + contents_end, + end, + post_blank, + } + } else { + let begin = maybe_token_to_usize(attributes_map.get(":begin").copied())?; + let end = maybe_token_to_usize(attributes_map.get(":end").copied())?; + let contents_begin = maybe_token_to_usize(attributes_map.get(":contents-begin").copied())?; + let contents_end = maybe_token_to_usize(attributes_map.get(":contents-end").copied())?; + let post_blank = maybe_token_to_usize(attributes_map.get(":post-blank").copied())?; + let post_affiliated = + maybe_token_to_usize(attributes_map.get(":post-affiliated").copied())?; + EmacsStandardProperties { + begin, + post_affiliated, + contents_begin, + contents_end, + end, + post_blank, + } + }) +} + +fn wasm_compare_list<'e, 's: 'e, 'w, EI, WI>( + source: &'s str, + emacs: EI, + wasm: WI, +) -> Result, Box> +where + EI: Iterator> + ExactSizeIterator, + WI: Iterator + ExactSizeIterator, +{ + let emacs_length = emacs.len(); + let wasm_length = wasm.len(); + if emacs_length != wasm_length { + return Ok(WasmDiffResult { + status: vec![WasmDiffStatus::Bad( + format!( + "Child length mismatch. Emacs=({emacs:?}) Wasm=({wasm:?}).", + emacs = emacs_length, + wasm = wasm_length + ) + .into(), + )], + children: Vec::new(), + name: "".into(), + }); + } + + let mut child_status = Vec::with_capacity(emacs_length); + for (emacs_child, wasm_child) in emacs.zip(wasm) { + child_status.push(compare_json_value(source, emacs_child, wasm_child)?); + } + Ok(WasmDiffResult { + status: Vec::new(), + children: child_status, + name: "".into(), + }) +} + +fn compare_optional_pair<'e, 's, 'w>( + source: &'s str, + emacs: &'e Vec>, + wasm: &'w serde_json::Map, +) -> Result, Box> { + let mut result = WasmDiffResult::default(); + let wasm_optval = wasm + .get("optval") + .ok_or(r#"Wasm optional pair should have an "optval" attribute."#)?; + let wasm_val = wasm + .get("val") + .ok_or(r#"Wasm optional pair should have an "optval" attribute."#)?; + if let serde_json::Value::Null = wasm_optval { + // If the optval is null, then the elisp should have just a single value of a quoted string. + if emacs.len() != 1 { + return Ok(WasmDiffResult { + status: vec![WasmDiffStatus::Bad( + format!( + "Optional pair with null optval should have 1 element. Emacs=({emacs:?}) Wasm=({wasm:?}).", + emacs = emacs, + wasm = wasm + ) + .into(), + )], + children: Vec::new(), + name: "".into(), + }); + } + + let emacs_val = emacs + .first() + .expect("If-statement proves this will be Some."); + result.extend(compare_json_value(source, emacs_val, wasm_val)?)?; + } else { + // If the optval is not null, then the elisp should have 3 values, the optval, a dot, and the val. + if emacs.len() != 3 { + return Ok(WasmDiffResult { + status: vec![WasmDiffStatus::Bad( + format!( + "Optional pair with non-null optval should have 3 elements. Emacs=({emacs:?}) Wasm=({wasm:?}).", + emacs = emacs, + wasm = wasm + ) + .into(), + )], + children: Vec::new(), + name: "".into(), + }); + } + let emacs_optval = emacs + .first() + .expect("If-statement proves this will be Some."); + let emacs_val = emacs + .get(2) + .expect("If-statement proves this will be Some."); + result.extend(compare_json_value(source, emacs_optval, wasm_optval)?)?; + result.extend(compare_json_value(source, emacs_val, wasm_val)?)?; + } + Ok(result) +} + +fn compare_object_tree<'e, 's, 'w>( + source: &'s str, + emacs: &'e Vec>, + wasm: &'w serde_json::Map, +) -> Result, Box> { + let mut result = WasmDiffResult::default(); + let wasm_attributes = wasm + .get("object-tree") + .ok_or(r#"Wasm object tree should have an "object-tree" attribute."#)? + .as_array() + .ok_or(r#"Wasm "object-tree" attribute should be a list."#)?; + let emacs_outer_length = emacs.len(); + let wasm_outer_length = wasm_attributes.len(); + if emacs_outer_length != wasm_outer_length { + result.status.push(WasmDiffStatus::Bad( + format!( + "Child length mismatch. Emacs=({emacs:?}) Wasm=({wasm:?}).", + emacs = emacs_outer_length, + wasm = wasm_outer_length + ) + .into(), + )); + return Ok(result); + } + + for (emacs_attribute, wasm_attribute) in emacs.iter().zip(wasm_attributes.iter()) { + let emacs_attribute = emacs_attribute.as_list()?; + let wasm_attribute = wasm_attribute + .as_array() + .ok_or("Wasm middle layer in object tree should be a list.")?; + if wasm_attribute.len() != 2 { + result.status.push(WasmDiffStatus::Bad( + format!( + "Wasm middle layer in object tree should have a length of 2. Wasm=({wasm:?}).", + wasm = wasm_attribute.len() + ) + .into(), + )); + return Ok(result); + } + if let Some(serde_json::Value::Null) = wasm_attribute.first() { + // If optval is null then the emacs array should only contain 1 value. + if emacs_attribute.len() != 1 { + result.status.push(WasmDiffStatus::Bad( + format!( + "Emacs middle layer in object tree should have a length of 1. Emacs=({emacs:?}) Wasm=({wasm:?}).", + emacs = emacs_attribute, + wasm = wasm_attribute + ) + .into(), + )); + return Ok(result); + } + + let emacs_val = emacs_attribute + .first() + .expect("If-statement proves this will be Some."); + let wasm_val = wasm_attribute + .get(1) + .expect("If-statement proves this will be Some."); + result.extend(compare_json_value(source, emacs_val, wasm_val)?)?; + } else { + // If optval is not null, then the emacs array should contain 3 values, the optval, a dot, and the val. + if emacs_attribute.len() != 3 { + result.status.push(WasmDiffStatus::Bad( + format!( + "Emacs middle layer in object tree should have a length of 3. Emacs=({emacs:?}) Wasm=({wasm:?}).", + emacs = emacs_attribute, + wasm = wasm_attribute + ) + .into(), + )); + return Ok(result); + } + let emacs_optval = emacs_attribute + .first() + .expect("If-statement proves this will be Some."); + let wasm_optval = wasm_attribute + .first() + .expect("If-statement proves this will be Some."); + let emacs_val = emacs_attribute + .get(2) + .expect("If-statement proves this will be Some."); + let wasm_val = wasm_attribute + .get(1) + .expect("If-statement proves this will be Some."); + result.extend(compare_json_value(source, emacs_optval, wasm_optval)?)?; + result.extend(compare_json_value(source, emacs_val, wasm_val)?)?; + } + } + + Ok(result) +} + +fn is_plain_text<'e, 's, 'w>(wasm: &'w serde_json::Map) -> bool { + if let Some(serde_json::Value::String(node_type)) = wasm.get("ast-node") { + node_type == "plain-text" + } else { + false } } -impl<'s, 'p> WasmElispCompare<'s, 'p> for WasmHeadline<'s, 'p> { - fn compare_ast_node<'b>( - &self, - source: &'s str, - emacs: &'b Token<'s>, - ) -> Result, Box> { - // TODO: Implement this. - let result = WasmDiffResult::default(); - // let result = wasm_compare!( - // source, - // emacs, - // self, - // ( - // EmacsField::Required(":path"), - // |w| w.path.as_ref().and_then(|p| p.to_str()), - // wasm_compare_property_quoted_string - // ), - // ( - // EmacsField::Required(":CATEGORY"), - // |w| w.category.as_ref(), - // wasm_compare_property_quoted_string - // ) - // ); - - Ok(result) +fn compare_plain_text<'e, 's, 'w>( + source: &'s str, + emacs: &'e TextWithProperties<'s>, + wasm: &'w serde_json::Map, +) -> Result, Box> { + let mut result = WasmDiffResult::default(); + result.name = "plain-text".into(); + if !is_plain_text(wasm) { + result.status.push(WasmDiffStatus::Bad( + format!( + "AST node type mismatch. Emacs=({emacs:?}) Wasm=({wasm:?}).", + emacs = emacs, + wasm = wasm, + ) + .into(), + )); + return Ok(result); } -} -impl<'s, 'p> WasmElispCompare<'s, 'p> for WasmSection<'s, 'p> { - fn compare_ast_node<'b>( - &self, - source: &'s str, - emacs: &'b Token<'s>, - ) -> Result, Box> { - let result = wasm_compare!(source, emacs, self,); - - Ok(result) + let emacs_text = unquote(emacs.text)?; + let wasm_standard_properties = wasm + .get("standard-properties") + .ok_or(r#"Wasm AST nodes should have a "standard-properties" attribute."#)? + .as_object() + .ok_or(r#"Wasm ast node "standard-properties" attribute should be an object."#)?; + let wasm_begin = { + if let Some(serde_json::Value::Number(begin)) = wasm_standard_properties.get("begin") { + begin + .as_u64() + .map(|w| w as usize) + .ok_or("Begin should be a number.")? + } else { + result.status.push(WasmDiffStatus::Bad( + format!( + "AST node type mismatch. Emacs=({emacs:?}) Wasm=({wasm:?}).", + emacs = emacs, + wasm = wasm, + ) + .into(), + )); + return Ok(result); + } + }; + let wasm_end = { + if let Some(serde_json::Value::Number(end)) = wasm_standard_properties.get("end") { + end.as_u64() + .map(|w| w as usize) + .ok_or("End should be a number.")? + } else { + result.status.push(WasmDiffStatus::Bad( + format!( + "AST node type mismatch. Emacs=({emacs:?}) Wasm=({wasm:?}).", + emacs = emacs, + wasm = wasm, + ) + .into(), + )); + return Ok(result); + } + }; + let wasm_text: String = source + .chars() + .skip(wasm_begin - 1) + .take(wasm_end - wasm_begin) + .collect(); + if wasm_text != emacs_text { + result.status.push(WasmDiffStatus::Bad( + format!( + "Text mismatch. Emacs=({emacs:?}) Wasm=({wasm:?}).", + emacs = emacs_text, + wasm = wasm_text, + ) + .into(), + )); + return Ok(result); } -} -impl<'s, 'p> WasmElispCompare<'s, 'p> for WasmParagraph<'s, 'p> { - fn compare_ast_node<'b>( - &self, - source: &'s str, - emacs: &'b Token<'s>, - ) -> Result, Box> { - let result = wasm_compare!(source, emacs, self,); - - Ok(result) + let emacs_start = emacs + .properties + .first() + .map(|t| t.as_atom()) + .map_or(Ok(None), |r| r.map(Some))?; + if emacs_start != Some("0") { + result.status.push(WasmDiffStatus::Bad( + format!( + "Text should start at offset 0. Emacs=({emacs:?}) Wasm=({wasm:?}).", + emacs = emacs, + wasm = wasm, + ) + .into(), + )); } -} - -impl<'s, 'p> WasmElispCompare<'s, 'p> for WasmPlainList<'s, 'p> { - fn compare_ast_node<'b>( - &self, - source: &'s str, - emacs: &'b Token<'s>, - ) -> Result, Box> { - // TODO: Implement this. - let result = WasmDiffResult::default(); - // let result = wasm_compare!( - // source, - // emacs, - // self, - // ( - // EmacsField::Required(":path"), - // |w| w.path.as_ref().and_then(|p| p.to_str()), - // wasm_compare_property_quoted_string - // ), - // ( - // EmacsField::Required(":CATEGORY"), - // |w| w.category.as_ref(), - // wasm_compare_property_quoted_string - // ) - // ); - - Ok(result) - } -} - -impl<'s, 'p> WasmElispCompare<'s, 'p> for WasmPlainListItem<'s, 'p> { - fn compare_ast_node<'b>( - &self, - source: &'s str, - emacs: &'b Token<'s>, - ) -> Result, Box> { - // TODO: Implement this. - let result = WasmDiffResult::default(); - // let result = wasm_compare!( - // source, - // emacs, - // self, - // ( - // EmacsField::Required(":path"), - // |w| w.path.as_ref().and_then(|p| p.to_str()), - // wasm_compare_property_quoted_string - // ), - // ( - // EmacsField::Required(":CATEGORY"), - // |w| w.category.as_ref(), - // wasm_compare_property_quoted_string - // ) - // ); - - Ok(result) - } -} - -impl<'s, 'p> WasmElispCompare<'s, 'p> for WasmCenterBlock<'s, 'p> { - fn compare_ast_node<'b>( - &self, - source: &'s str, - emacs: &'b Token<'s>, - ) -> Result, Box> { - // TODO: Implement this. - let result = WasmDiffResult::default(); - // let result = wasm_compare!( - // source, - // emacs, - // self, - // ( - // EmacsField::Required(":path"), - // |w| w.path.as_ref().and_then(|p| p.to_str()), - // wasm_compare_property_quoted_string - // ), - // ( - // EmacsField::Required(":CATEGORY"), - // |w| w.category.as_ref(), - // wasm_compare_property_quoted_string - // ) - // ); - - Ok(result) - } -} - -impl<'s, 'p> WasmElispCompare<'s, 'p> for WasmQuoteBlock<'s, 'p> { - fn compare_ast_node<'b>( - &self, - source: &'s str, - emacs: &'b Token<'s>, - ) -> Result, Box> { - // TODO: Implement this. - let result = WasmDiffResult::default(); - // let result = wasm_compare!( - // source, - // emacs, - // self, - // ( - // EmacsField::Required(":path"), - // |w| w.path.as_ref().and_then(|p| p.to_str()), - // wasm_compare_property_quoted_string - // ), - // ( - // EmacsField::Required(":CATEGORY"), - // |w| w.category.as_ref(), - // wasm_compare_property_quoted_string - // ) - // ); - - Ok(result) - } -} - -impl<'s, 'p> WasmElispCompare<'s, 'p> for WasmSpecialBlock<'s, 'p> { - fn compare_ast_node<'b>( - &self, - source: &'s str, - emacs: &'b Token<'s>, - ) -> Result, Box> { - // TODO: Implement this. - let result = WasmDiffResult::default(); - // let result = wasm_compare!( - // source, - // emacs, - // self, - // ( - // EmacsField::Required(":path"), - // |w| w.path.as_ref().and_then(|p| p.to_str()), - // wasm_compare_property_quoted_string - // ), - // ( - // EmacsField::Required(":CATEGORY"), - // |w| w.category.as_ref(), - // wasm_compare_property_quoted_string - // ) - // ); - - Ok(result) - } -} - -impl<'s, 'p> WasmElispCompare<'s, 'p> for WasmDynamicBlock<'s, 'p> { - fn compare_ast_node<'b>( - &self, - source: &'s str, - emacs: &'b Token<'s>, - ) -> Result, Box> { - // TODO: Implement this. - let result = WasmDiffResult::default(); - // let result = wasm_compare!( - // source, - // emacs, - // self, - // ( - // EmacsField::Required(":path"), - // |w| w.path.as_ref().and_then(|p| p.to_str()), - // wasm_compare_property_quoted_string - // ), - // ( - // EmacsField::Required(":CATEGORY"), - // |w| w.category.as_ref(), - // wasm_compare_property_quoted_string - // ) - // ); - - Ok(result) - } -} - -impl<'s, 'p> WasmElispCompare<'s, 'p> for WasmFootnoteDefinition<'s, 'p> { - fn compare_ast_node<'b>( - &self, - source: &'s str, - emacs: &'b Token<'s>, - ) -> Result, Box> { - // TODO: Implement this. - let result = WasmDiffResult::default(); - // let result = wasm_compare!( - // source, - // emacs, - // self, - // ( - // EmacsField::Required(":path"), - // |w| w.path.as_ref().and_then(|p| p.to_str()), - // wasm_compare_property_quoted_string - // ), - // ( - // EmacsField::Required(":CATEGORY"), - // |w| w.category.as_ref(), - // wasm_compare_property_quoted_string - // ) - // ); - - Ok(result) - } -} - -impl<'s, 'p> WasmElispCompare<'s, 'p> for WasmComment<'s, 'p> { - fn compare_ast_node<'b>( - &self, - source: &'s str, - emacs: &'b Token<'s>, - ) -> Result, Box> { - // TODO: Implement this. - let result = WasmDiffResult::default(); - // let result = wasm_compare!( - // source, - // emacs, - // self, - // ( - // EmacsField::Required(":path"), - // |w| w.path.as_ref().and_then(|p| p.to_str()), - // wasm_compare_property_quoted_string - // ), - // ( - // EmacsField::Required(":CATEGORY"), - // |w| w.category.as_ref(), - // wasm_compare_property_quoted_string - // ) - // ); - - Ok(result) - } -} - -impl<'s, 'p> WasmElispCompare<'s, 'p> for WasmDrawer<'s, 'p> { - fn compare_ast_node<'b>( - &self, - source: &'s str, - emacs: &'b Token<'s>, - ) -> Result, Box> { - // TODO: Implement this. - let result = WasmDiffResult::default(); - // let result = wasm_compare!( - // source, - // emacs, - // self, - // ( - // EmacsField::Required(":path"), - // |w| w.path.as_ref().and_then(|p| p.to_str()), - // wasm_compare_property_quoted_string - // ), - // ( - // EmacsField::Required(":CATEGORY"), - // |w| w.category.as_ref(), - // wasm_compare_property_quoted_string - // ) - // ); - - Ok(result) - } -} - -impl<'s, 'p> WasmElispCompare<'s, 'p> for WasmPropertyDrawer<'s, 'p> { - fn compare_ast_node<'b>( - &self, - source: &'s str, - emacs: &'b Token<'s>, - ) -> Result, Box> { - // TODO: Implement this. - let result = WasmDiffResult::default(); - // let result = wasm_compare!( - // source, - // emacs, - // self, - // ( - // EmacsField::Required(":path"), - // |w| w.path.as_ref().and_then(|p| p.to_str()), - // wasm_compare_property_quoted_string - // ), - // ( - // EmacsField::Required(":CATEGORY"), - // |w| w.category.as_ref(), - // wasm_compare_property_quoted_string - // ) - // ); - - Ok(result) - } -} - -impl<'s, 'p> WasmElispCompare<'s, 'p> for WasmNodeProperty<'s, 'p> { - fn compare_ast_node<'b>( - &self, - source: &'s str, - emacs: &'b Token<'s>, - ) -> Result, Box> { - // TODO: Implement this. - let result = WasmDiffResult::default(); - // let result = wasm_compare!( - // source, - // emacs, - // self, - // ( - // EmacsField::Required(":path"), - // |w| w.path.as_ref().and_then(|p| p.to_str()), - // wasm_compare_property_quoted_string - // ), - // ( - // EmacsField::Required(":CATEGORY"), - // |w| w.category.as_ref(), - // wasm_compare_property_quoted_string - // ) - // ); - - Ok(result) - } -} - -impl<'s, 'p> WasmElispCompare<'s, 'p> for WasmTable<'s, 'p> { - fn compare_ast_node<'b>( - &self, - source: &'s str, - emacs: &'b Token<'s>, - ) -> Result, Box> { - // TODO: Implement this. - let result = WasmDiffResult::default(); - // let result = wasm_compare!( - // source, - // emacs, - // self, - // ( - // EmacsField::Required(":path"), - // |w| w.path.as_ref().and_then(|p| p.to_str()), - // wasm_compare_property_quoted_string - // ), - // ( - // EmacsField::Required(":CATEGORY"), - // |w| w.category.as_ref(), - // wasm_compare_property_quoted_string - // ) - // ); - - Ok(result) - } -} - -impl<'s, 'p> WasmElispCompare<'s, 'p> for WasmTableRow<'s, 'p> { - fn compare_ast_node<'b>( - &self, - source: &'s str, - emacs: &'b Token<'s>, - ) -> Result, Box> { - // TODO: Implement this. - let result = WasmDiffResult::default(); - // let result = wasm_compare!( - // source, - // emacs, - // self, - // ( - // EmacsField::Required(":path"), - // |w| w.path.as_ref().and_then(|p| p.to_str()), - // wasm_compare_property_quoted_string - // ), - // ( - // EmacsField::Required(":CATEGORY"), - // |w| w.category.as_ref(), - // wasm_compare_property_quoted_string - // ) - // ); - - Ok(result) - } -} - -impl<'s, 'p> WasmElispCompare<'s, 'p> for WasmVerseBlock<'s, 'p> { - fn compare_ast_node<'b>( - &self, - source: &'s str, - emacs: &'b Token<'s>, - ) -> Result, Box> { - // TODO: Implement this. - let result = WasmDiffResult::default(); - // let result = wasm_compare!( - // source, - // emacs, - // self, - // ( - // EmacsField::Required(":path"), - // |w| w.path.as_ref().and_then(|p| p.to_str()), - // wasm_compare_property_quoted_string - // ), - // ( - // EmacsField::Required(":CATEGORY"), - // |w| w.category.as_ref(), - // wasm_compare_property_quoted_string - // ) - // ); - - Ok(result) - } -} - -impl<'s, 'p> WasmElispCompare<'s, 'p> for WasmCommentBlock<'s, 'p> { - fn compare_ast_node<'b>( - &self, - source: &'s str, - emacs: &'b Token<'s>, - ) -> Result, Box> { - // TODO: Implement this. - let result = WasmDiffResult::default(); - // let result = wasm_compare!( - // source, - // emacs, - // self, - // ( - // EmacsField::Required(":path"), - // |w| w.path.as_ref().and_then(|p| p.to_str()), - // wasm_compare_property_quoted_string - // ), - // ( - // EmacsField::Required(":CATEGORY"), - // |w| w.category.as_ref(), - // wasm_compare_property_quoted_string - // ) - // ); - - Ok(result) - } -} - -impl<'s, 'p> WasmElispCompare<'s, 'p> for WasmExampleBlock<'s, 'p> { - fn compare_ast_node<'b>( - &self, - source: &'s str, - emacs: &'b Token<'s>, - ) -> Result, Box> { - // TODO: Implement this. - let result = WasmDiffResult::default(); - // let result = wasm_compare!( - // source, - // emacs, - // self, - // ( - // EmacsField::Required(":path"), - // |w| w.path.as_ref().and_then(|p| p.to_str()), - // wasm_compare_property_quoted_string - // ), - // ( - // EmacsField::Required(":CATEGORY"), - // |w| w.category.as_ref(), - // wasm_compare_property_quoted_string - // ) - // ); - - Ok(result) - } -} - -impl<'s, 'p> WasmElispCompare<'s, 'p> for WasmExportBlock<'s, 'p> { - fn compare_ast_node<'b>( - &self, - source: &'s str, - emacs: &'b Token<'s>, - ) -> Result, Box> { - // TODO: Implement this. - let result = WasmDiffResult::default(); - // let result = wasm_compare!( - // source, - // emacs, - // self, - // ( - // EmacsField::Required(":path"), - // |w| w.path.as_ref().and_then(|p| p.to_str()), - // wasm_compare_property_quoted_string - // ), - // ( - // EmacsField::Required(":CATEGORY"), - // |w| w.category.as_ref(), - // wasm_compare_property_quoted_string - // ) - // ); - - Ok(result) - } -} - -impl<'s, 'p> WasmElispCompare<'s, 'p> for WasmSrcBlock<'s, 'p> { - fn compare_ast_node<'b>( - &self, - source: &'s str, - emacs: &'b Token<'s>, - ) -> Result, Box> { - // TODO: Implement this. - let result = WasmDiffResult::default(); - // let result = wasm_compare!( - // source, - // emacs, - // self, - // ( - // EmacsField::Required(":path"), - // |w| w.path.as_ref().and_then(|p| p.to_str()), - // wasm_compare_property_quoted_string - // ), - // ( - // EmacsField::Required(":CATEGORY"), - // |w| w.category.as_ref(), - // wasm_compare_property_quoted_string - // ) - // ); - - Ok(result) - } -} - -impl<'s, 'p> WasmElispCompare<'s, 'p> for WasmClock<'s, 'p> { - fn compare_ast_node<'b>( - &self, - source: &'s str, - emacs: &'b Token<'s>, - ) -> Result, Box> { - // TODO: Implement this. - let result = WasmDiffResult::default(); - // let result = wasm_compare!( - // source, - // emacs, - // self, - // ( - // EmacsField::Required(":path"), - // |w| w.path.as_ref().and_then(|p| p.to_str()), - // wasm_compare_property_quoted_string - // ), - // ( - // EmacsField::Required(":CATEGORY"), - // |w| w.category.as_ref(), - // wasm_compare_property_quoted_string - // ) - // ); - - Ok(result) - } -} - -impl<'s, 'p> WasmElispCompare<'s, 'p> for WasmDiarySexp<'s, 'p> { - fn compare_ast_node<'b>( - &self, - source: &'s str, - emacs: &'b Token<'s>, - ) -> Result, Box> { - // TODO: Implement this. - let result = WasmDiffResult::default(); - // let result = wasm_compare!( - // source, - // emacs, - // self, - // ( - // EmacsField::Required(":path"), - // |w| w.path.as_ref().and_then(|p| p.to_str()), - // wasm_compare_property_quoted_string - // ), - // ( - // EmacsField::Required(":CATEGORY"), - // |w| w.category.as_ref(), - // wasm_compare_property_quoted_string - // ) - // ); - - Ok(result) - } -} - -impl<'s, 'p> WasmElispCompare<'s, 'p> for WasmPlanning<'s, 'p> { - fn compare_ast_node<'b>( - &self, - source: &'s str, - emacs: &'b Token<'s>, - ) -> Result, Box> { - // TODO: Implement this. - let result = WasmDiffResult::default(); - // let result = wasm_compare!( - // source, - // emacs, - // self, - // ( - // EmacsField::Required(":path"), - // |w| w.path.as_ref().and_then(|p| p.to_str()), - // wasm_compare_property_quoted_string - // ), - // ( - // EmacsField::Required(":CATEGORY"), - // |w| w.category.as_ref(), - // wasm_compare_property_quoted_string - // ) - // ); - - Ok(result) - } -} - -impl<'s, 'p> WasmElispCompare<'s, 'p> for WasmFixedWidthArea<'s, 'p> { - fn compare_ast_node<'b>( - &self, - source: &'s str, - emacs: &'b Token<'s>, - ) -> Result, Box> { - // TODO: Implement this. - let result = WasmDiffResult::default(); - // let result = wasm_compare!( - // source, - // emacs, - // self, - // ( - // EmacsField::Required(":path"), - // |w| w.path.as_ref().and_then(|p| p.to_str()), - // wasm_compare_property_quoted_string - // ), - // ( - // EmacsField::Required(":CATEGORY"), - // |w| w.category.as_ref(), - // wasm_compare_property_quoted_string - // ) - // ); - - Ok(result) - } -} - -impl<'s, 'p> WasmElispCompare<'s, 'p> for WasmHorizontalRule<'s, 'p> { - fn compare_ast_node<'b>( - &self, - source: &'s str, - emacs: &'b Token<'s>, - ) -> Result, Box> { - // TODO: Implement this. - let result = WasmDiffResult::default(); - // let result = wasm_compare!( - // source, - // emacs, - // self, - // ( - // EmacsField::Required(":path"), - // |w| w.path.as_ref().and_then(|p| p.to_str()), - // wasm_compare_property_quoted_string - // ), - // ( - // EmacsField::Required(":CATEGORY"), - // |w| w.category.as_ref(), - // wasm_compare_property_quoted_string - // ) - // ); - - Ok(result) - } -} - -impl<'s, 'p> WasmElispCompare<'s, 'p> for WasmKeyword<'s, 'p> { - fn compare_ast_node<'b>( - &self, - source: &'s str, - emacs: &'b Token<'s>, - ) -> Result, Box> { - // TODO: Implement this. - let result = WasmDiffResult::default(); - // let result = wasm_compare!( - // source, - // emacs, - // self, - // ( - // EmacsField::Required(":path"), - // |w| w.path.as_ref().and_then(|p| p.to_str()), - // wasm_compare_property_quoted_string - // ), - // ( - // EmacsField::Required(":CATEGORY"), - // |w| w.category.as_ref(), - // wasm_compare_property_quoted_string - // ) - // ); - - Ok(result) - } -} - -impl<'s, 'p> WasmElispCompare<'s, 'p> for WasmBabelCall<'s, 'p> { - fn compare_ast_node<'b>( - &self, - source: &'s str, - emacs: &'b Token<'s>, - ) -> Result, Box> { - // TODO: Implement this. - let result = WasmDiffResult::default(); - // let result = wasm_compare!( - // source, - // emacs, - // self, - // ( - // EmacsField::Required(":path"), - // |w| w.path.as_ref().and_then(|p| p.to_str()), - // wasm_compare_property_quoted_string - // ), - // ( - // EmacsField::Required(":CATEGORY"), - // |w| w.category.as_ref(), - // wasm_compare_property_quoted_string - // ) - // ); - - Ok(result) - } -} - -impl<'s, 'p> WasmElispCompare<'s, 'p> for WasmLatexEnvironment<'s, 'p> { - fn compare_ast_node<'b>( - &self, - source: &'s str, - emacs: &'b Token<'s>, - ) -> Result, Box> { - // TODO: Implement this. - let result = WasmDiffResult::default(); - // let result = wasm_compare!( - // source, - // emacs, - // self, - // ( - // EmacsField::Required(":path"), - // |w| w.path.as_ref().and_then(|p| p.to_str()), - // wasm_compare_property_quoted_string - // ), - // ( - // EmacsField::Required(":CATEGORY"), - // |w| w.category.as_ref(), - // wasm_compare_property_quoted_string - // ) - // ); - - Ok(result) - } -} - -impl<'s, 'p> WasmElispCompare<'s, 'p> for WasmBold<'s, 'p> { - fn compare_ast_node<'b>( - &self, - source: &'s str, - emacs: &'b Token<'s>, - ) -> Result, Box> { - // TODO: Implement this. - let result = WasmDiffResult::default(); - // let result = wasm_compare!( - // source, - // emacs, - // self, - // ( - // EmacsField::Required(":path"), - // |w| w.path.as_ref().and_then(|p| p.to_str()), - // wasm_compare_property_quoted_string - // ), - // ( - // EmacsField::Required(":CATEGORY"), - // |w| w.category.as_ref(), - // wasm_compare_property_quoted_string - // ) - // ); - - Ok(result) - } -} - -impl<'s, 'p> WasmElispCompare<'s, 'p> for WasmItalic<'s, 'p> { - fn compare_ast_node<'b>( - &self, - source: &'s str, - emacs: &'b Token<'s>, - ) -> Result, Box> { - // TODO: Implement this. - let result = WasmDiffResult::default(); - // let result = wasm_compare!( - // source, - // emacs, - // self, - // ( - // EmacsField::Required(":path"), - // |w| w.path.as_ref().and_then(|p| p.to_str()), - // wasm_compare_property_quoted_string - // ), - // ( - // EmacsField::Required(":CATEGORY"), - // |w| w.category.as_ref(), - // wasm_compare_property_quoted_string - // ) - // ); - - Ok(result) - } -} - -impl<'s, 'p> WasmElispCompare<'s, 'p> for WasmUnderline<'s, 'p> { - fn compare_ast_node<'b>( - &self, - source: &'s str, - emacs: &'b Token<'s>, - ) -> Result, Box> { - // TODO: Implement this. - let result = WasmDiffResult::default(); - // let result = wasm_compare!( - // source, - // emacs, - // self, - // ( - // EmacsField::Required(":path"), - // |w| w.path.as_ref().and_then(|p| p.to_str()), - // wasm_compare_property_quoted_string - // ), - // ( - // EmacsField::Required(":CATEGORY"), - // |w| w.category.as_ref(), - // wasm_compare_property_quoted_string - // ) - // ); - - Ok(result) - } -} - -impl<'s, 'p> WasmElispCompare<'s, 'p> for WasmStrikeThrough<'s, 'p> { - fn compare_ast_node<'b>( - &self, - source: &'s str, - emacs: &'b Token<'s>, - ) -> Result, Box> { - // TODO: Implement this. - let result = WasmDiffResult::default(); - // let result = wasm_compare!( - // source, - // emacs, - // self, - // ( - // EmacsField::Required(":path"), - // |w| w.path.as_ref().and_then(|p| p.to_str()), - // wasm_compare_property_quoted_string - // ), - // ( - // EmacsField::Required(":CATEGORY"), - // |w| w.category.as_ref(), - // wasm_compare_property_quoted_string - // ) - // ); - - Ok(result) - } -} - -impl<'s, 'p> WasmElispCompare<'s, 'p> for WasmCode<'s, 'p> { - fn compare_ast_node<'b>( - &self, - source: &'s str, - emacs: &'b Token<'s>, - ) -> Result, Box> { - // TODO: Implement this. - let result = WasmDiffResult::default(); - // let result = wasm_compare!( - // source, - // emacs, - // self, - // ( - // EmacsField::Required(":path"), - // |w| w.path.as_ref().and_then(|p| p.to_str()), - // wasm_compare_property_quoted_string - // ), - // ( - // EmacsField::Required(":CATEGORY"), - // |w| w.category.as_ref(), - // wasm_compare_property_quoted_string - // ) - // ); - - Ok(result) - } -} - -impl<'s, 'p> WasmElispCompare<'s, 'p> for WasmVerbatim<'s, 'p> { - fn compare_ast_node<'b>( - &self, - source: &'s str, - emacs: &'b Token<'s>, - ) -> Result, Box> { - // TODO: Implement this. - let result = WasmDiffResult::default(); - // let result = wasm_compare!( - // source, - // emacs, - // self, - // ( - // EmacsField::Required(":path"), - // |w| w.path.as_ref().and_then(|p| p.to_str()), - // wasm_compare_property_quoted_string - // ), - // ( - // EmacsField::Required(":CATEGORY"), - // |w| w.category.as_ref(), - // wasm_compare_property_quoted_string - // ) - // ); - - Ok(result) - } -} - -impl<'s, 'p> WasmElispCompare<'s, 'p> for WasmPlainText<'s, 'p> { - fn compare_ast_node<'b>( - &self, - source: &'s str, - emacs: &'b Token<'s>, - ) -> Result, Box> { - // TODO: Implement this. - let result = WasmDiffResult::default(); - - Ok(result) - } -} - -impl<'s, 'p> WasmElispCompare<'s, 'p> for WasmRegularLink<'s, 'p> { - fn compare_ast_node<'b>( - &self, - source: &'s str, - emacs: &'b Token<'s>, - ) -> Result, Box> { - // TODO: Implement this. - let result = WasmDiffResult::default(); - // let result = wasm_compare!( - // source, - // emacs, - // self, - // ( - // EmacsField::Required(":path"), - // |w| w.path.as_ref().and_then(|p| p.to_str()), - // wasm_compare_property_quoted_string - // ), - // ( - // EmacsField::Required(":CATEGORY"), - // |w| w.category.as_ref(), - // wasm_compare_property_quoted_string - // ) - // ); - - Ok(result) - } -} - -impl<'s, 'p> WasmElispCompare<'s, 'p> for WasmRadioLink<'s, 'p> { - fn compare_ast_node<'b>( - &self, - source: &'s str, - emacs: &'b Token<'s>, - ) -> Result, Box> { - // TODO: Implement this. - let result = WasmDiffResult::default(); - // let result = wasm_compare!( - // source, - // emacs, - // self, - // ( - // EmacsField::Required(":path"), - // |w| w.path.as_ref().and_then(|p| p.to_str()), - // wasm_compare_property_quoted_string - // ), - // ( - // EmacsField::Required(":CATEGORY"), - // |w| w.category.as_ref(), - // wasm_compare_property_quoted_string - // ) - // ); - - Ok(result) - } -} - -impl<'s, 'p> WasmElispCompare<'s, 'p> for WasmRadioTarget<'s, 'p> { - fn compare_ast_node<'b>( - &self, - source: &'s str, - emacs: &'b Token<'s>, - ) -> Result, Box> { - // TODO: Implement this. - let result = WasmDiffResult::default(); - // let result = wasm_compare!( - // source, - // emacs, - // self, - // ( - // EmacsField::Required(":path"), - // |w| w.path.as_ref().and_then(|p| p.to_str()), - // wasm_compare_property_quoted_string - // ), - // ( - // EmacsField::Required(":CATEGORY"), - // |w| w.category.as_ref(), - // wasm_compare_property_quoted_string - // ) - // ); - - Ok(result) - } -} - -impl<'s, 'p> WasmElispCompare<'s, 'p> for WasmPlainLink<'s, 'p> { - fn compare_ast_node<'b>( - &self, - source: &'s str, - emacs: &'b Token<'s>, - ) -> Result, Box> { - // TODO: Implement this. - let result = WasmDiffResult::default(); - // let result = wasm_compare!( - // source, - // emacs, - // self, - // ( - // EmacsField::Required(":path"), - // |w| w.path.as_ref().and_then(|p| p.to_str()), - // wasm_compare_property_quoted_string - // ), - // ( - // EmacsField::Required(":CATEGORY"), - // |w| w.category.as_ref(), - // wasm_compare_property_quoted_string - // ) - // ); - - Ok(result) - } -} - -impl<'s, 'p> WasmElispCompare<'s, 'p> for WasmAngleLink<'s, 'p> { - fn compare_ast_node<'b>( - &self, - source: &'s str, - emacs: &'b Token<'s>, - ) -> Result, Box> { - // TODO: Implement this. - let result = WasmDiffResult::default(); - // let result = wasm_compare!( - // source, - // emacs, - // self, - // ( - // EmacsField::Required(":path"), - // |w| w.path.as_ref().and_then(|p| p.to_str()), - // wasm_compare_property_quoted_string - // ), - // ( - // EmacsField::Required(":CATEGORY"), - // |w| w.category.as_ref(), - // wasm_compare_property_quoted_string - // ) - // ); - - Ok(result) - } -} - -impl<'s, 'p> WasmElispCompare<'s, 'p> for WasmOrgMacro<'s, 'p> { - fn compare_ast_node<'b>( - &self, - source: &'s str, - emacs: &'b Token<'s>, - ) -> Result, Box> { - // TODO: Implement this. - let result = WasmDiffResult::default(); - // let result = wasm_compare!( - // source, - // emacs, - // self, - // ( - // EmacsField::Required(":path"), - // |w| w.path.as_ref().and_then(|p| p.to_str()), - // wasm_compare_property_quoted_string - // ), - // ( - // EmacsField::Required(":CATEGORY"), - // |w| w.category.as_ref(), - // wasm_compare_property_quoted_string - // ) - // ); - - Ok(result) - } -} - -impl<'s, 'p> WasmElispCompare<'s, 'p> for WasmEntity<'s, 'p> { - fn compare_ast_node<'b>( - &self, - source: &'s str, - emacs: &'b Token<'s>, - ) -> Result, Box> { - // TODO: Implement this. - let result = WasmDiffResult::default(); - // let result = wasm_compare!( - // source, - // emacs, - // self, - // ( - // EmacsField::Required(":path"), - // |w| w.path.as_ref().and_then(|p| p.to_str()), - // wasm_compare_property_quoted_string - // ), - // ( - // EmacsField::Required(":CATEGORY"), - // |w| w.category.as_ref(), - // wasm_compare_property_quoted_string - // ) - // ); - - Ok(result) - } -} - -impl<'s, 'p> WasmElispCompare<'s, 'p> for WasmLatexFragment<'s, 'p> { - fn compare_ast_node<'b>( - &self, - source: &'s str, - emacs: &'b Token<'s>, - ) -> Result, Box> { - // TODO: Implement this. - let result = WasmDiffResult::default(); - // let result = wasm_compare!( - // source, - // emacs, - // self, - // ( - // EmacsField::Required(":path"), - // |w| w.path.as_ref().and_then(|p| p.to_str()), - // wasm_compare_property_quoted_string - // ), - // ( - // EmacsField::Required(":CATEGORY"), - // |w| w.category.as_ref(), - // wasm_compare_property_quoted_string - // ) - // ); - - Ok(result) - } -} - -impl<'s, 'p> WasmElispCompare<'s, 'p> for WasmExportSnippet<'s, 'p> { - fn compare_ast_node<'b>( - &self, - source: &'s str, - emacs: &'b Token<'s>, - ) -> Result, Box> { - // TODO: Implement this. - let result = WasmDiffResult::default(); - // let result = wasm_compare!( - // source, - // emacs, - // self, - // ( - // EmacsField::Required(":path"), - // |w| w.path.as_ref().and_then(|p| p.to_str()), - // wasm_compare_property_quoted_string - // ), - // ( - // EmacsField::Required(":CATEGORY"), - // |w| w.category.as_ref(), - // wasm_compare_property_quoted_string - // ) - // ); - - Ok(result) - } -} - -impl<'s, 'p> WasmElispCompare<'s, 'p> for WasmFootnoteReference<'s, 'p> { - fn compare_ast_node<'b>( - &self, - source: &'s str, - emacs: &'b Token<'s>, - ) -> Result, Box> { - // TODO: Implement this. - let result = WasmDiffResult::default(); - // let result = wasm_compare!( - // source, - // emacs, - // self, - // ( - // EmacsField::Required(":path"), - // |w| w.path.as_ref().and_then(|p| p.to_str()), - // wasm_compare_property_quoted_string - // ), - // ( - // EmacsField::Required(":CATEGORY"), - // |w| w.category.as_ref(), - // wasm_compare_property_quoted_string - // ) - // ); - - Ok(result) - } -} - -impl<'s, 'p> WasmElispCompare<'s, 'p> for WasmCitation<'s, 'p> { - fn compare_ast_node<'b>( - &self, - source: &'s str, - emacs: &'b Token<'s>, - ) -> Result, Box> { - // TODO: Implement this. - let result = WasmDiffResult::default(); - // let result = wasm_compare!( - // source, - // emacs, - // self, - // ( - // EmacsField::Required(":path"), - // |w| w.path.as_ref().and_then(|p| p.to_str()), - // wasm_compare_property_quoted_string - // ), - // ( - // EmacsField::Required(":CATEGORY"), - // |w| w.category.as_ref(), - // wasm_compare_property_quoted_string - // ) - // ); - - Ok(result) - } -} - -impl<'s, 'p> WasmElispCompare<'s, 'p> for WasmCitationReference<'s, 'p> { - fn compare_ast_node<'b>( - &self, - source: &'s str, - emacs: &'b Token<'s>, - ) -> Result, Box> { - // TODO: Implement this. - let result = WasmDiffResult::default(); - // let result = wasm_compare!( - // source, - // emacs, - // self, - // ( - // EmacsField::Required(":path"), - // |w| w.path.as_ref().and_then(|p| p.to_str()), - // wasm_compare_property_quoted_string - // ), - // ( - // EmacsField::Required(":CATEGORY"), - // |w| w.category.as_ref(), - // wasm_compare_property_quoted_string - // ) - // ); - - Ok(result) - } -} - -impl<'s, 'p> WasmElispCompare<'s, 'p> for WasmInlineBabelCall<'s, 'p> { - fn compare_ast_node<'b>( - &self, - source: &'s str, - emacs: &'b Token<'s>, - ) -> Result, Box> { - // TODO: Implement this. - let result = WasmDiffResult::default(); - // let result = wasm_compare!( - // source, - // emacs, - // self, - // ( - // EmacsField::Required(":path"), - // |w| w.path.as_ref().and_then(|p| p.to_str()), - // wasm_compare_property_quoted_string - // ), - // ( - // EmacsField::Required(":CATEGORY"), - // |w| w.category.as_ref(), - // wasm_compare_property_quoted_string - // ) - // ); - - Ok(result) - } -} - -impl<'s, 'p> WasmElispCompare<'s, 'p> for WasmInlineSourceBlock<'s, 'p> { - fn compare_ast_node<'b>( - &self, - source: &'s str, - emacs: &'b Token<'s>, - ) -> Result, Box> { - // TODO: Implement this. - let result = WasmDiffResult::default(); - // let result = wasm_compare!( - // source, - // emacs, - // self, - // ( - // EmacsField::Required(":path"), - // |w| w.path.as_ref().and_then(|p| p.to_str()), - // wasm_compare_property_quoted_string - // ), - // ( - // EmacsField::Required(":CATEGORY"), - // |w| w.category.as_ref(), - // wasm_compare_property_quoted_string - // ) - // ); - - Ok(result) - } -} - -impl<'s, 'p> WasmElispCompare<'s, 'p> for WasmLineBreak<'s, 'p> { - fn compare_ast_node<'b>( - &self, - source: &'s str, - emacs: &'b Token<'s>, - ) -> Result, Box> { - // TODO: Implement this. - let result = WasmDiffResult::default(); - // let result = wasm_compare!( - // source, - // emacs, - // self, - // ( - // EmacsField::Required(":path"), - // |w| w.path.as_ref().and_then(|p| p.to_str()), - // wasm_compare_property_quoted_string - // ), - // ( - // EmacsField::Required(":CATEGORY"), - // |w| w.category.as_ref(), - // wasm_compare_property_quoted_string - // ) - // ); - - Ok(result) - } -} - -impl<'s, 'p> WasmElispCompare<'s, 'p> for WasmTarget<'s, 'p> { - fn compare_ast_node<'b>( - &self, - source: &'s str, - emacs: &'b Token<'s>, - ) -> Result, Box> { - // TODO: Implement this. - let result = WasmDiffResult::default(); - // let result = wasm_compare!( - // source, - // emacs, - // self, - // ( - // EmacsField::Required(":path"), - // |w| w.path.as_ref().and_then(|p| p.to_str()), - // wasm_compare_property_quoted_string - // ), - // ( - // EmacsField::Required(":CATEGORY"), - // |w| w.category.as_ref(), - // wasm_compare_property_quoted_string - // ) - // ); - - Ok(result) - } -} - -impl<'s, 'p> WasmElispCompare<'s, 'p> for WasmStatisticsCookie<'s, 'p> { - fn compare_ast_node<'b>( - &self, - source: &'s str, - emacs: &'b Token<'s>, - ) -> Result, Box> { - // TODO: Implement this. - let result = WasmDiffResult::default(); - // let result = wasm_compare!( - // source, - // emacs, - // self, - // ( - // EmacsField::Required(":path"), - // |w| w.path.as_ref().and_then(|p| p.to_str()), - // wasm_compare_property_quoted_string - // ), - // ( - // EmacsField::Required(":CATEGORY"), - // |w| w.category.as_ref(), - // wasm_compare_property_quoted_string - // ) - // ); - - Ok(result) - } -} - -impl<'s, 'p> WasmElispCompare<'s, 'p> for WasmSubscript<'s, 'p> { - fn compare_ast_node<'b>( - &self, - source: &'s str, - emacs: &'b Token<'s>, - ) -> Result, Box> { - // TODO: Implement this. - let result = WasmDiffResult::default(); - // let result = wasm_compare!( - // source, - // emacs, - // self, - // ( - // EmacsField::Required(":path"), - // |w| w.path.as_ref().and_then(|p| p.to_str()), - // wasm_compare_property_quoted_string - // ), - // ( - // EmacsField::Required(":CATEGORY"), - // |w| w.category.as_ref(), - // wasm_compare_property_quoted_string - // ) - // ); - - Ok(result) - } -} - -impl<'s, 'p> WasmElispCompare<'s, 'p> for WasmSuperscript<'s, 'p> { - fn compare_ast_node<'b>( - &self, - source: &'s str, - emacs: &'b Token<'s>, - ) -> Result, Box> { - // TODO: Implement this. - let result = WasmDiffResult::default(); - // let result = wasm_compare!( - // source, - // emacs, - // self, - // ( - // EmacsField::Required(":path"), - // |w| w.path.as_ref().and_then(|p| p.to_str()), - // wasm_compare_property_quoted_string - // ), - // ( - // EmacsField::Required(":CATEGORY"), - // |w| w.category.as_ref(), - // wasm_compare_property_quoted_string - // ) - // ); - - Ok(result) - } -} - -impl<'s, 'p> WasmElispCompare<'s, 'p> for WasmTableCell<'s, 'p> { - fn compare_ast_node<'b>( - &self, - source: &'s str, - emacs: &'b Token<'s>, - ) -> Result, Box> { - // TODO: Implement this. - let result = WasmDiffResult::default(); - // let result = wasm_compare!( - // source, - // emacs, - // self, - // ( - // EmacsField::Required(":path"), - // |w| w.path.as_ref().and_then(|p| p.to_str()), - // wasm_compare_property_quoted_string - // ), - // ( - // EmacsField::Required(":CATEGORY"), - // |w| w.category.as_ref(), - // wasm_compare_property_quoted_string - // ) - // ); - - Ok(result) - } -} - -impl<'s, 'p> WasmElispCompare<'s, 'p> for WasmTimestamp<'s, 'p> { - fn compare_ast_node<'b>( - &self, - source: &'s str, - emacs: &'b Token<'s>, - ) -> Result, Box> { - // TODO: Implement this. - let result = WasmDiffResult::default(); - // let result = wasm_compare!( - // source, - // emacs, - // self, - // ( - // EmacsField::Required(":path"), - // |w| w.path.as_ref().and_then(|p| p.to_str()), - // wasm_compare_property_quoted_string - // ), - // ( - // EmacsField::Required(":CATEGORY"), - // |w| w.category.as_ref(), - // wasm_compare_property_quoted_string - // ) - // ); - - Ok(result) + let emacs_end = emacs + .properties + .get(1) + .map(|t| t.as_atom()) + .map_or(Ok(None), |r| r.map(Some))?; + if emacs_end != Some((wasm_end - wasm_begin).to_string().as_str()) { + result.status.push(WasmDiffStatus::Bad( + format!( + "Text end mismatch. Emacs=({emacs:?}) Wasm=({wasm:?}).", + emacs = emacs_end, + wasm = wasm_end - wasm_begin, + ) + .into(), + )); } + + Ok(result) } diff --git a/src/wasm_test/diff.rs b/src/wasm_test/diff.rs index 0cccf4d..7101a9d 100644 --- a/src/wasm_test/diff.rs +++ b/src/wasm_test/diff.rs @@ -55,7 +55,7 @@ impl<'s> WasmDiffResult<'s> { original_document: &str, ) -> Result<(), Box> { let status_text = { - if self.is_bad() { + if self.is_self_bad() { format!( "{color}BAD{reset}", color = foreground_color(255, 0, 0), diff --git a/src/wasm_test/elisp_compare.rs b/src/wasm_test/elisp_compare.rs deleted file mode 100644 index fc23b52..0000000 --- a/src/wasm_test/elisp_compare.rs +++ /dev/null @@ -1,10 +0,0 @@ -use super::diff::WasmDiffResult; -use crate::compare::Token; - -pub trait WasmElispCompare<'s, 'p> { - fn compare_ast_node<'b>( - &self, - source: &'s str, - emacs: &'b Token<'s>, - ) -> Result, Box>; -} diff --git a/src/wasm_test/logic.rs b/src/wasm_test/logic.rs deleted file mode 100644 index 29a460a..0000000 --- a/src/wasm_test/logic.rs +++ /dev/null @@ -1,387 +0,0 @@ -use super::diff::WasmDiffResult; -use super::diff::WasmDiffStatus; -use super::elisp_compare::WasmElispCompare; -use crate::compare::get_emacs_standard_properties; -use crate::compare::get_property; -use crate::compare::get_property_quoted_string; -use crate::compare::unquote; -use crate::compare::Token; -use crate::wasm::AdditionalProperties; -use crate::wasm::AdditionalPropertyValue; -use crate::wasm::WasmStandardProperties; - -pub(crate) fn wasm_compare_list<'b, 's: 'b, 'p, EI, WI, WC>( - source: &'s str, - emacs: EI, - wasm: WI, -) -> Result, Box> -where - EI: Iterator> + ExactSizeIterator, - WI: Iterator + ExactSizeIterator, - WC: WasmElispCompare<'s, 'p>, -{ - let status = Vec::new(); - let emacs_length = emacs.len(); - let wasm_length = wasm.len(); - if emacs_length != wasm_length { - return Ok(WasmDiffResult { - status: vec![WasmDiffStatus::Bad( - format!( - "Child length mismatch (emacs != rust) {:?} != {:?}", - emacs_length, wasm_length - ) - .into(), - )], - children: Vec::new(), - name: "".into(), - }); - } - - let mut child_status = Vec::with_capacity(emacs_length); - for (emacs_child, wasm_child) in emacs.zip(wasm) { - child_status.push(wasm_child.compare_ast_node(source, emacs_child)?); - } - Ok(WasmDiffResult { - status, - children: child_status, - name: "".into(), - }) -} - -pub(crate) fn wasm_compare_property_quoted_string< - 'b, - 's, - W, - WV: AsRef + std::fmt::Debug, - WG: Fn(W) -> Option, ->( - _source: &'s str, - emacs: &'b Token<'s>, - wasm_node: W, - emacs_field: &str, - wasm_value_getter: WG, -) -> Result, Box> { - let mut result = WasmDiffResult::default(); - let emacs_value = get_property_quoted_string(emacs, emacs_field)?; - let wasm_value = wasm_value_getter(wasm_node); - if wasm_value.as_ref().map(|s| s.as_ref()) != emacs_value.as_deref() { - result.status.push(WasmDiffStatus::Bad( - format!( - "Property mismatch. Property=({property}) Emacs=({emacs:?}) Wasm=({wasm:?}).", - property = emacs_field, - emacs = emacs_value, - wasm = wasm_value, - ) - .into(), - )) - } - Ok(result) -} - -pub(crate) fn wasm_compare_property_list_of_quoted_string< - 'b, - 's, - WI: Iterator + ExactSizeIterator, - W, - WV: AsRef + std::fmt::Debug, - WG: Fn(W) -> Option, ->( - _source: &'s str, - emacs: &'b Token<'s>, - wasm_node: W, - emacs_field: &str, - wasm_value_getter: WG, -) -> Result, Box> { - let mut result = WasmDiffResult::default(); - let emacs_value = get_property(emacs, emacs_field)? - .map(Token::as_list) - .map_or(Ok(None), |r| r.map(Some))?; - let wasm_value = wasm_value_getter(wasm_node); - match (emacs_value, wasm_value) { - (None, None) => {} - (None, Some(_)) | (Some(_), None) => { - return Ok(WasmDiffResult { - status: vec![WasmDiffStatus::Bad( - format!( - "Property list length mismatch. Property=({property}) Emacs=({emacs:?}) Wasm=({wasm:?}).", - property = emacs_field, - emacs = if emacs_value.is_some() {"Some"} else {"None"}, - wasm = if !emacs_value.is_some() {"Some"} else {"None"} - ) - .into(), - )], - children: Vec::new(), - name: "".into(), - }); - } - (Some(el), Some(wl)) if el.len() != wl.len() => { - return Ok(WasmDiffResult { - status: vec![WasmDiffStatus::Bad( - format!( - "Property list length mismatch. Property=({property}) Emacs=({emacs:?}) Wasm=({wasm:?}).", - property = emacs_field, - emacs = el.len(), - wasm = wl.len() - ) - .into(), - )], - children: Vec::new(), - name: "".into(), - }); - } - (Some(el), Some(wl)) => { - for (e, w) in el.iter().zip(wl) { - let e = unquote(e.as_atom()?)?; - let w = w.as_ref(); - if e != w { - result.status.push(WasmDiffStatus::Bad( - format!( - "Property list value mismatch. Property=({property}) Emacs=({emacs:?}) Wasm=({wasm:?}).", - property = emacs_field, - emacs = e, - wasm = w - ) - .into(), - )); - } - } - } - }; - - Ok(result) -} - -pub(crate) fn wasm_compare_property_optional_pair< - 'b, - 's, - W, - WV: AsRef + std::fmt::Debug, - WOV: AsRef + std::fmt::Debug, - WG: Fn(W) -> Option<(Option, WV)>, ->( - _source: &'s str, - emacs: &'b Token<'s>, - wasm_node: W, - emacs_field: &str, - wasm_value_getter: WG, -) -> Result, Box> { - let mut result = WasmDiffResult::default(); - let emacs_value = get_property(emacs, emacs_field)? - .map(Token::as_list) - .map_or(Ok(None), |r| r.map(Some))?; - let wasm_value = wasm_value_getter(wasm_node); - match (emacs_value, &wasm_value) { - (None, None) => {} - (None, Some(_)) | (Some(_), None) => { - return Ok(WasmDiffResult { - status: vec![WasmDiffStatus::Bad( - format!( - "Property list length mismatch. Property=({property}) Emacs=({emacs:?}) Wasm=({wasm:?}).", - property = emacs_field, - emacs = if emacs_value.is_some() {"Some"} else {"None"}, - wasm = if !emacs_value.is_some() {"Some"} else {"None"} - ) - .into(), - )], - children: Vec::new(), - name: "".into(), - }); - } - (Some(el), Some((Some(owl), wl))) if el.len() == 3 => { - let e = el - .first() - .map(Token::as_atom) - .map_or(Ok(None), |r| r.map(Some))? - .map(unquote) - .map_or(Ok(None), |r| r.map(Some))? - .expect("Above match proved length to be 3."); - let oe = el - .get(2) - .map(Token::as_atom) - .map_or(Ok(None), |r| r.map(Some))? - .map(unquote) - .map_or(Ok(None), |r| r.map(Some))? - .expect("Above match proved length to be 3."); - let w = wl.as_ref(); - let ow = owl.as_ref(); - if e != w { - result.status.push(WasmDiffStatus::Bad( - format!( - "Property mismatch. Property=({property}) Emacs=({emacs:?}) Wasm=({wasm:?}).", - property = "end", - emacs = e, - wasm = w, - ) - .into(), - )); - } - if oe != ow { - result.status.push(WasmDiffStatus::Bad( - format!( - "Property mismatch. Property=({property}) Emacs=({emacs:?}) Wasm=({wasm:?}).", - property = "end", - emacs = oe, - wasm = ow, - ) - .into(), - )); - } - } - (Some(el), Some((None, wl))) if el.len() == 1 => { - let e = el - .first() - .map(Token::as_atom) - .map_or(Ok(None), |r| r.map(Some))? - .map(unquote) - .map_or(Ok(None), |r| r.map(Some))? - .expect("Above match proved length to be 3."); - let w = wl.as_ref(); - if e != w { - result.status.push(WasmDiffStatus::Bad( - format!( - "Property mismatch. Property=({property}) Emacs=({emacs:?}) Wasm=({wasm:?}).", - property = "end", - emacs = e, - wasm = w, - ) - .into(), - )); - } - } - (Some(el), Some(_)) => { - return Ok(WasmDiffResult { - status: vec![WasmDiffStatus::Bad( - format!( - "Property list length mismatch. Property=({property}) Emacs=({emacs:?}) Wasm=({wasm:?}).", - property = emacs_field, - emacs = el.len(), - wasm = wasm_value - ) - .into(), - )], - children: Vec::new(), - name: "".into(), - }); - } - } - Ok(result) -} - -pub(crate) fn wasm_compare_standard_properties<'b, 's>( - _source: &'s str, - emacs: &'b Token<'s>, - wasm: &WasmStandardProperties, -) -> Result, Box> { - let mut result = WasmDiffResult::default(); - let mut layer = WasmDiffResult::default(); - layer.name = "standard-properties".into(); - let standard_properties = get_emacs_standard_properties(emacs)?; - - if Some(wasm.begin) != standard_properties.begin { - layer.status.push(WasmDiffStatus::Bad( - format!( - "Property mismatch. Property=({property}) Emacs=({emacs:?}) Wasm=({wasm:?}).", - property = "begin", - emacs = standard_properties.begin, - wasm = Some(wasm.begin), - ) - .into(), - )); - } - if Some(wasm.end) != standard_properties.end { - layer.status.push(WasmDiffStatus::Bad( - format!( - "Property mismatch. Property=({property}) Emacs=({emacs:?}) Wasm=({wasm:?}).", - property = "end", - emacs = standard_properties.end, - wasm = Some(wasm.end), - ) - .into(), - )); - } - if wasm.contents_begin != standard_properties.contents_begin { - layer.status.push(WasmDiffStatus::Bad( - format!( - "Property mismatch. Property=({property}) Emacs=({emacs:?}) Wasm=({wasm:?}).", - property = "contents-begin", - emacs = standard_properties.contents_begin, - wasm = wasm.contents_begin, - ) - .into(), - )); - } - if wasm.contents_end != standard_properties.contents_end { - layer.status.push(WasmDiffStatus::Bad( - format!( - "Property mismatch. Property=({property}) Emacs=({emacs:?}) Wasm=({wasm:?}).", - property = "contents-end", - emacs = standard_properties.contents_end, - wasm = wasm.contents_end, - ) - .into(), - )); - } - if Some(wasm.post_blank).map(|post_blank| post_blank as usize) != standard_properties.post_blank - { - layer.status.push(WasmDiffStatus::Bad( - format!( - "Property mismatch. Property=({property}) Emacs=({emacs:?}) Wasm=({wasm:?}).", - property = "post-blank", - emacs = standard_properties.post_blank, - wasm = Some(wasm.post_blank), - ) - .into(), - )); - } - - result.children.push(layer); - Ok(result) -} - -pub(crate) fn wasm_compare_additional_properties<'b, 's>( - source: &'s str, - emacs: &'b Token<'s>, - wasm: &AdditionalProperties<'_, '_>, -) -> Result, Box> { - let mut result = WasmDiffResult::default(); - let mut layer = WasmDiffResult::default(); - layer.name = "additional-properties".into(); - - for (property_name, property_value) in wasm.properties.iter() { - let emacs_property_name = format!(":{property_name}", property_name = property_name); - match property_value { - AdditionalPropertyValue::SingleString(wasm_value) => { - layer.extend(wasm_compare_property_quoted_string( - source, - emacs, - wasm, - &emacs_property_name, - |_| Some(wasm_value), - )?)?; - } - AdditionalPropertyValue::ListOfStrings(wasm_value) => { - layer.extend(wasm_compare_property_list_of_quoted_string( - source, - emacs, - wasm, - &emacs_property_name, - |_| Some(wasm_value.iter()), - )?)?; - } - // TODO: similar to compare_affiliated_keywords - AdditionalPropertyValue::OptionalPair { optval, val } => { - layer.extend(wasm_compare_property_optional_pair( - source, - emacs, - wasm, - &emacs_property_name, - |_| Some((*optval, *val)), - )?)?; - } - AdditionalPropertyValue::ObjectTree(_) => todo!(), - } - } - - result.children.push(layer); - Ok(result) -} diff --git a/src/wasm_test/mod.rs b/src/wasm_test/mod.rs index 7032539..038b592 100644 --- a/src/wasm_test/mod.rs +++ b/src/wasm_test/mod.rs @@ -1,7 +1,5 @@ mod compare; mod diff; -mod elisp_compare; -mod logic; mod macros; mod runner; diff --git a/src/wasm_test/runner.rs b/src/wasm_test/runner.rs index c14f143..054137b 100644 --- a/src/wasm_test/runner.rs +++ b/src/wasm_test/runner.rs @@ -47,7 +47,7 @@ pub async fn wasm_run_anonymous_compare_with_settings<'g, 's, P: AsRef>( } // We do the diffing after printing out both parsed forms in case the diffing panics - let diff_result = wasm_compare_document(org_contents, &parsed_sexp, wasm_parsed)?; + let diff_result = wasm_compare_document(org_contents, &parsed_sexp, &wasm_parsed)?; if !silent { diff_result.print(org_contents)?; } @@ -112,7 +112,7 @@ pub async fn wasm_run_compare_on_file_with_settings<'g, 's, P: AsRef>( } // We do the diffing after printing out both parsed forms in case the diffing panics - let diff_result = wasm_compare_document(org_contents, &parsed_sexp, wasm_parsed)?; + let diff_result = wasm_compare_document(org_contents, &parsed_sexp, &wasm_parsed)?; if !silent { diff_result.print(org_contents)?; }