2023-12-25 13:10:40 -05:00
|
|
|
use organic::parser::parse_with_settings;
|
|
|
|
use organic::settings::GlobalSettings;
|
2023-12-24 01:35:21 -05:00
|
|
|
use serde::Serialize;
|
|
|
|
|
|
|
|
use super::document::WasmDocument;
|
2023-12-25 13:10:40 -05:00
|
|
|
use super::ToWasm;
|
|
|
|
use super::ToWasmContext;
|
2023-12-24 01:35:21 -05:00
|
|
|
|
2023-12-25 12:42:38 -05:00
|
|
|
#[derive(Debug, Serialize)]
|
2023-12-24 01:35:21 -05:00
|
|
|
#[serde(tag = "status", content = "content")]
|
2023-12-25 11:19:09 -05:00
|
|
|
pub(crate) enum ParseResult<'s> {
|
2023-12-24 01:35:21 -05:00
|
|
|
#[serde(rename = "success")]
|
2023-12-25 11:19:09 -05:00
|
|
|
Success(WasmDocument<'s>),
|
2023-12-24 01:35:21 -05:00
|
|
|
|
|
|
|
#[serde(rename = "error")]
|
|
|
|
Error(String),
|
|
|
|
}
|
2023-12-25 13:10:40 -05:00
|
|
|
|
|
|
|
pub(crate) fn wasm_parse_org(org_contents: &str) -> ParseResult<'_> {
|
|
|
|
let global_settings = GlobalSettings::default();
|
|
|
|
let to_wasm_context = ToWasmContext::new(org_contents);
|
|
|
|
let rust_parsed = match parse_with_settings(org_contents, &global_settings)
|
|
|
|
.map(|document| document.to_wasm(to_wasm_context))
|
|
|
|
.map(|wasm_document| match wasm_document {
|
|
|
|
Ok(wasm_document) => ParseResult::Success(wasm_document),
|
|
|
|
Err(err) => ParseResult::Error(format!("{:?}", err)),
|
|
|
|
}) {
|
|
|
|
Ok(wasm_document) => wasm_document,
|
|
|
|
Err(err) => ParseResult::Error(format!("{:?}", err)),
|
|
|
|
};
|
|
|
|
rust_parsed
|
|
|
|
}
|