2023-12-27 17:20:58 +00:00
|
|
|
use organic::parser::parse_with_settings;
|
|
|
|
use organic::settings::GlobalSettings;
|
|
|
|
use organic::wasm::ParseResult;
|
|
|
|
use organic::wasm::ToWasm;
|
|
|
|
use organic::wasm::ToWasmContext;
|
2023-12-24 05:59:41 +00:00
|
|
|
use wasm_bindgen::prelude::wasm_bindgen;
|
2023-12-24 05:39:57 +00:00
|
|
|
|
2023-12-24 05:59:41 +00:00
|
|
|
#[wasm_bindgen]
|
2023-12-24 06:35:21 +00:00
|
|
|
pub fn parse_org(org_contents: &str) -> wasm_bindgen::JsValue {
|
2023-12-27 17:20:58 +00:00
|
|
|
let rust_parsed = match parse_with_settings(org_contents, &GlobalSettings::default()) {
|
|
|
|
Ok(document) => document,
|
|
|
|
Err(err) => {
|
|
|
|
return serde_wasm_bindgen::to_value(&ParseResult::Error(format!("{:?}", err)))
|
|
|
|
.unwrap();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
let to_wasm_context = ToWasmContext::new(org_contents);
|
|
|
|
let wasm_document = match rust_parsed.to_wasm(to_wasm_context) {
|
|
|
|
Ok(document) => document,
|
|
|
|
Err(err) => {
|
|
|
|
return serde_wasm_bindgen::to_value(&ParseResult::Error(format!("{:?}", err)))
|
|
|
|
.unwrap();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
serde_wasm_bindgen::to_value(&ParseResult::Success(wasm_document)).unwrap()
|
2023-12-25 17:03:59 +00:00
|
|
|
}
|
2023-12-27 01:51:14 +00:00
|
|
|
|
|
|
|
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|
|
|
Ok(())
|
|
|
|
}
|