Define a wasm document.
This commit is contained in:
parent
2d5593681f
commit
53320070da
@ -11,7 +11,7 @@ mod wasm;
|
|||||||
pub fn parse_org(org_contents: &str) -> wasm_bindgen::JsValue {
|
pub fn parse_org(org_contents: &str) -> wasm_bindgen::JsValue {
|
||||||
let global_settings = GlobalSettings::default();
|
let global_settings = GlobalSettings::default();
|
||||||
let rust_parsed = parse_with_settings(org_contents, &global_settings)
|
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)));
|
.unwrap_or_else(|err| ParseResult::Error(format!("{:?}", err)));
|
||||||
serde_wasm_bindgen::to_value(&rust_parsed).unwrap()
|
serde_wasm_bindgen::to_value(&rust_parsed).unwrap()
|
||||||
}
|
}
|
||||||
|
@ -2,13 +2,17 @@ use organic::types::Document;
|
|||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
|
|
||||||
|
use super::macros::to_wasm;
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
#[derive(Serialize, Deserialize)]
|
||||||
#[serde(tag = "ast_node")]
|
#[serde(tag = "ast_node")]
|
||||||
#[serde(rename = "org-data")]
|
#[serde(rename = "org-data")]
|
||||||
pub(crate) struct WasmDocument {}
|
pub(crate) struct WasmDocument {
|
||||||
|
children: Vec<()>,
|
||||||
impl From<Document<'_>> for WasmDocument {
|
|
||||||
fn from(value: Document) -> Self {
|
|
||||||
todo!()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
to_wasm!(WasmDocument, Document<'s>, original, document, {
|
||||||
|
WasmDocument {
|
||||||
|
children: Vec::new(),
|
||||||
|
}
|
||||||
|
});
|
||||||
|
15
src/wasm/macros.rs
Normal file
15
src/wasm/macros.rs
Normal 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;
|
@ -1,4 +1,5 @@
|
|||||||
mod document;
|
mod document;
|
||||||
|
mod macros;
|
||||||
mod parse_result;
|
mod parse_result;
|
||||||
|
|
||||||
pub(crate) use parse_result::ParseResult;
|
pub(crate) use parse_result::ParseResult;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user