2023-12-27 12:20:58 -05: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 00:59:41 -05:00
|
|
|
use wasm_bindgen::prelude::wasm_bindgen;
|
2023-12-24 00:39:57 -05:00
|
|
|
|
2023-12-24 00:59:41 -05:00
|
|
|
#[wasm_bindgen]
|
2023-12-24 01:35:21 -05:00
|
|
|
pub fn parse_org(org_contents: &str) -> wasm_bindgen::JsValue {
|
2023-12-27 12:20:58 -05: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 12:03:59 -05:00
|
|
|
}
|
2023-12-26 20:51:14 -05:00
|
|
|
|
|
|
|
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|
|
|
Ok(())
|
|
|
|
}
|