From 122adee23be942490874a309355d3372b9053546 Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Wed, 3 Jan 2024 23:38:04 -0500 Subject: [PATCH] Hide the wasm module. --- src/bin_wasm.rs | 22 +--------------------- src/lib.rs | 4 +++- src/util/elisp/mod.rs | 4 ++++ src/util/elisp/sexp.rs | 1 + src/util/elisp/util.rs | 1 + src/wasm/mod.rs | 2 ++ src/wasm_cli/mod.rs | 24 ++++++++++++++++++++++++ 7 files changed, 36 insertions(+), 22 deletions(-) create mode 100644 src/wasm_cli/mod.rs diff --git a/src/bin_wasm.rs b/src/bin_wasm.rs index a1384646..7ec51c56 100644 --- a/src/bin_wasm.rs +++ b/src/bin_wasm.rs @@ -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> { diff --git a/src/lib.rs b/src/lib.rs index e6521e50..44ed0763 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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; diff --git a/src/util/elisp/mod.rs b/src/util/elisp/mod.rs index 5a63924f..1fac0cb5 100644 --- a/src/util/elisp/mod.rs +++ b/src/util/elisp/mod.rs @@ -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; diff --git a/src/util/elisp/sexp.rs b/src/util/elisp/sexp.rs index a45816a4..cd72fd33 100644 --- a/src/util/elisp/sexp.rs +++ b/src/util/elisp/sexp.rs @@ -61,6 +61,7 @@ impl<'s> Token<'s> { }?) } + #[cfg(feature = "compare")] pub(crate) fn as_text<'p>( &'p self, ) -> Result<&'p TextWithProperties<'s>, Box> { diff --git a/src/util/elisp/util.rs b/src/util/elisp/util.rs index ccfef138..2978d0fb 100644 --- a/src/util/elisp/util.rs +++ b/src/util/elisp/util.rs @@ -29,6 +29,7 @@ pub(crate) struct EmacsStandardProperties { pub(crate) post_blank: Option, } +#[cfg(feature = "compare")] pub(crate) fn get_emacs_standard_properties( emacs: &Token<'_>, ) -> Result> { diff --git a/src/wasm/mod.rs b/src/wasm/mod.rs index 78c69e0e..20e4b571 100644 --- a/src/wasm/mod.rs +++ b/src/wasm/mod.rs @@ -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; diff --git a/src/wasm_cli/mod.rs b/src/wasm_cli/mod.rs new file mode 100644 index 00000000..54cf0c58 --- /dev/null +++ b/src/wasm_cli/mod.rs @@ -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() +}