organic/src/wasm/table.rs
2023-12-30 18:52:51 -05:00

76 lines
2.0 KiB
Rust

use std::collections::BTreeSet;
use serde::Deserialize;
use serde::Serialize;
use super::ast_node::WasmAstNode;
use super::macros::to_wasm;
use super::to_wasm::ToWasm;
use super::AdditionalProperties;
use crate::compare::ElispFact;
use crate::types::GetAffiliatedKeywords;
use crate::types::Table;
use crate::wasm::to_wasm::ToWasmStandardProperties;
#[derive(Debug, Serialize, Deserialize)]
pub struct WasmTable {
#[serde(flatten)]
pub(crate) additional_properties: AdditionalProperties,
#[serde(rename = "tblfm")]
pub(crate) formulas: Option<WasmStringSet>,
#[serde(rename = "type")]
pub(crate) table_type: String,
pub(crate) value: Option<String>, // Always None
}
#[derive(Debug, Serialize, Deserialize)]
#[serde(tag = "string-set")]
#[serde(rename = "string-set")]
struct WasmStringSet {
value: BTreeSet<String>,
}
to_wasm!(
WasmTable,
Table<'s>,
original,
wasm_context,
{ WasmAstNode::Table(original) },
{ "table".into() },
{
let additional_properties = original
.get_affiliated_keywords()
.to_wasm(wasm_context.clone())?;
let children = original
.children
.iter()
.map(|child| {
child
.to_wasm(wasm_context.clone())
.map(Into::<WasmAstNode>::into)
})
.collect::<Result<Vec<_>, _>>()?;
Ok((
children,
WasmTable {
additional_properties,
formulas: if original.formulas.is_empty() {
None
} else {
Some(WasmStringSet {
value: original
.formulas
.iter()
.map(|kw| kw.value.to_owned())
.collect(),
})
},
table_type: "org".to_owned(),
value: None,
},
))
}
);