Define a wasm document.

This commit is contained in:
Tom Alexander 2023-12-24 13:18:06 -05:00
parent 2d5593681f
commit 53320070da
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE
4 changed files with 27 additions and 7 deletions

View File

@ -11,7 +11,7 @@ mod wasm;
pub fn parse_org(org_contents: &str) -> wasm_bindgen::JsValue {
let global_settings = GlobalSettings::default();
let rust_parsed = parse_with_settings(org_contents, &global_settings)
.map(|document| ParseResult::Success(document.into()))
.map(|document| ParseResult::Success((org_contents, document).into()))
.unwrap_or_else(|err| ParseResult::Error(format!("{:?}", err)));
serde_wasm_bindgen::to_value(&rust_parsed).unwrap()
}

View File

@ -2,13 +2,17 @@ use organic::types::Document;
use serde::Deserialize;
use serde::Serialize;
use super::macros::to_wasm;
#[derive(Serialize, Deserialize)]
#[serde(tag = "ast_node")]
#[serde(rename = "org-data")]
pub(crate) struct WasmDocument {}
impl From<Document<'_>> for WasmDocument {
fn from(value: Document) -> Self {
todo!()
}
pub(crate) struct WasmDocument {
children: Vec<()>,
}
to_wasm!(WasmDocument, Document<'s>, original, document, {
WasmDocument {
children: Vec::new(),
}
});

15
src/wasm/macros.rs Normal file
View File

@ -0,0 +1,15 @@
/// Write the implementation for the intermediate ast node.
///
/// This exists to make changing the type signature easier.
macro_rules! to_wasm {
($ostruct:ty, $istruct:ty, $original:ident, $document:ident, $fnbody:tt) => {
impl<'s> From<(&'s str, $istruct)> for $ostruct {
fn from(value: (&'s str, $istruct)) -> $ostruct {
let ($original, $document) = value;
$fnbody
}
}
};
}
pub(crate) use to_wasm;

View File

@ -1,4 +1,5 @@
mod document;
mod macros;
mod parse_result;
pub(crate) use parse_result::ParseResult;