Hide the wasm module.
All checks were successful
clippy Build clippy has succeeded
rust-foreign-document-test Build rust-foreign-document-test has succeeded
rust-build Build rust-build has succeeded
rust-test Build rust-test has succeeded

This commit is contained in:
Tom Alexander 2024-01-03 23:38:04 -05:00
parent 556afecbb8
commit 122adee23b
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE
7 changed files with 36 additions and 22 deletions

View File

@ -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>> {

View File

@ -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;

View File

@ -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;

View File

@ -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>> {

View File

@ -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>> {

View File

@ -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
View 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()
}