Files
organic/src/wasm/table.rs

76 lines
2.0 KiB
Rust
Raw Normal View History

2023-12-30 18:25:15 -05:00
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;
2023-12-30 18:25:15 -05:00
use crate::types::GetAffiliatedKeywords;
use crate::types::Table;
use crate::wasm::to_wasm::ToWasmStandardProperties;
#[derive(Debug, Serialize, Deserialize)]
2023-12-29 12:49:43 -05:00
pub struct WasmTable {
#[serde(flatten)]
pub(crate) additional_properties: AdditionalProperties,
2023-12-30 18:25:15 -05:00
#[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!(
2023-12-29 12:49:43 -05:00
WasmTable,
2023-12-25 11:51:39 -05:00
Table<'s>,
2023-12-25 12:32:35 -05:00
original,
wasm_context,
{ WasmAstNode::Table(original) },
2023-12-30 18:25:15 -05:00
{ "table".into() },
{
2023-12-30 18:25:15 -05:00
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<_>, _>>()?;
2023-12-27 19:10:43 -05:00
Ok((
children,
WasmTable {
2023-12-30 18:25:15 -05:00
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,
},
))
2023-12-27 19:10:43 -05:00
}
);