Hide the wasm module.
This commit is contained in:
parent
556afecbb8
commit
122adee23b
@ -1,28 +1,8 @@
|
||||
use organic::parser::parse_with_settings;
|
||||
use organic::settings::GlobalSettings;
|
||||
use organic::wasm::ParseResult;
|
||||
use organic::wasm::ToWasm;
|
||||
use organic::wasm::ToWasmContext;
|
||||
use wasm_bindgen::prelude::wasm_bindgen;
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn parse_org(org_contents: &str) -> wasm_bindgen::JsValue {
|
||||
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()
|
||||
organic::wasm_cli::parse_org(org_contents)
|
||||
}
|
||||
|
||||
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
|
@ -16,7 +16,9 @@ pub mod parse_cli;
|
||||
#[cfg(any(feature = "compare", feature = "wasm", feature = "wasm_test"))]
|
||||
mod util;
|
||||
#[cfg(any(feature = "wasm", feature = "wasm_test"))]
|
||||
pub mod wasm;
|
||||
mod wasm;
|
||||
#[cfg(any(feature = "wasm", feature = "wasm_test"))]
|
||||
pub mod wasm_cli;
|
||||
#[cfg(feature = "wasm_test")]
|
||||
pub mod wasm_test;
|
||||
|
||||
|
@ -3,8 +3,12 @@ mod util;
|
||||
|
||||
pub use sexp::sexp;
|
||||
pub(crate) use sexp::unquote;
|
||||
#[cfg(feature = "wasm_test")]
|
||||
pub(crate) use sexp::TextWithProperties;
|
||||
pub use sexp::Token;
|
||||
#[cfg(feature = "compare")]
|
||||
pub(crate) use util::get_emacs_standard_properties;
|
||||
#[cfg(feature = "wasm_test")]
|
||||
pub(crate) use util::maybe_token_to_usize;
|
||||
#[cfg(feature = "wasm_test")]
|
||||
pub(crate) use util::EmacsStandardProperties;
|
||||
|
@ -61,6 +61,7 @@ impl<'s> Token<'s> {
|
||||
}?)
|
||||
}
|
||||
|
||||
#[cfg(feature = "compare")]
|
||||
pub(crate) fn as_text<'p>(
|
||||
&'p self,
|
||||
) -> Result<&'p TextWithProperties<'s>, Box<dyn std::error::Error>> {
|
||||
|
@ -29,6 +29,7 @@ pub(crate) struct EmacsStandardProperties {
|
||||
pub(crate) post_blank: Option<usize>,
|
||||
}
|
||||
|
||||
#[cfg(feature = "compare")]
|
||||
pub(crate) fn get_emacs_standard_properties(
|
||||
emacs: &Token<'_>,
|
||||
) -> Result<EmacsStandardProperties, Box<dyn std::error::Error>> {
|
||||
|
@ -66,7 +66,9 @@ mod verse_block;
|
||||
pub use additional_property::AdditionalProperties;
|
||||
pub use additional_property::AdditionalPropertyValue;
|
||||
pub use ast_node::WasmAstNode;
|
||||
#[cfg(feature = "wasm_test")]
|
||||
pub use ast_node::WasmAstNodeWrapper;
|
||||
#[cfg(feature = "wasm_test")]
|
||||
pub use document::WasmDocument;
|
||||
pub use parse_result::ParseResult;
|
||||
pub(crate) use standard_properties::WasmStandardProperties;
|
||||
|
24
src/wasm_cli/mod.rs
Normal file
24
src/wasm_cli/mod.rs
Normal file
@ -0,0 +1,24 @@
|
||||
use crate::parser::parse_with_settings;
|
||||
use crate::settings::GlobalSettings;
|
||||
use crate::wasm::ParseResult;
|
||||
use crate::wasm::ToWasm;
|
||||
use crate::wasm::ToWasmContext;
|
||||
|
||||
pub fn parse_org(org_contents: &str) -> wasm_bindgen::JsValue {
|
||||
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()
|
||||
}
|
Loading…
Reference in New Issue
Block a user