From 99376515efbfa69250f03123fb28a6de774cb079 Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Wed, 27 Dec 2023 09:31:54 -0500 Subject: [PATCH] Invoking wasm_compare_document. --- src/compare/mod.rs | 1 + src/lib.rs | 3 ++- src/wasm/document.rs | 4 ++-- src/wasm/mod.rs | 1 + src/wasm_test/compare.rs | 9 +++++++++ src/wasm_test/mod.rs | 1 + src/wasm_test/runner.rs | 11 +++++------ 7 files changed, 21 insertions(+), 9 deletions(-) create mode 100644 src/wasm_test/compare.rs diff --git a/src/compare/mod.rs b/src/compare/mod.rs index 95290e22..65a8f576 100644 --- a/src/compare/mod.rs +++ b/src/compare/mod.rs @@ -13,3 +13,4 @@ pub use compare::run_compare_on_file_with_settings; pub use compare::silent_anonymous_compare; pub use compare::silent_compare_on_file; pub use sexp::sexp; +pub use sexp::Token; diff --git a/src/lib.rs b/src/lib.rs index 621dc601..3a791a23 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -8,7 +8,8 @@ extern crate test; -#[cfg(feature = "compare")] +// TODO: I only include compare to use some shared stuff like sexp and DiffResult. Ideally, this would be moved to a shared module. +#[cfg(any(feature = "compare", feature = "wasm_test"))] pub mod compare; #[cfg(any(feature = "compare", feature = "wasm_test"))] pub mod util; diff --git a/src/wasm/document.rs b/src/wasm/document.rs index 1eda47e3..eac8ba4c 100644 --- a/src/wasm/document.rs +++ b/src/wasm/document.rs @@ -1,16 +1,16 @@ -use crate::types::Document; use serde::Serialize; use super::ast_node::WasmAstNode; use super::macros::to_wasm; use super::standard_properties::WasmStandardProperties; use super::to_wasm::ToWasm; +use crate::types::Document; use crate::wasm::to_wasm::ToWasmStandardProperties; #[derive(Debug, Serialize)] #[serde(tag = "ast_node")] #[serde(rename = "org-data")] -pub(crate) struct WasmDocument<'s> { +pub struct WasmDocument<'s> { standard_properties: WasmStandardProperties, additional_properties: Vec<(String, &'s str)>, children: Vec>, diff --git a/src/wasm/mod.rs b/src/wasm/mod.rs index 246fbc21..ed985d63 100644 --- a/src/wasm/mod.rs +++ b/src/wasm/mod.rs @@ -62,6 +62,7 @@ mod underline; mod verbatim; mod verse_block; +pub use document::WasmDocument; pub use parse_result::wasm_parse_org; pub use parse_result::ParseResult; pub(crate) use to_wasm::ToWasm; diff --git a/src/wasm_test/compare.rs b/src/wasm_test/compare.rs new file mode 100644 index 00000000..392715f2 --- /dev/null +++ b/src/wasm_test/compare.rs @@ -0,0 +1,9 @@ +use crate::compare::Token; +use crate::wasm::WasmDocument; + +pub fn wasm_compare_document<'b, 's>( + emacs: &'b Token<'s>, + wasm: &'b WasmDocument<'s>, +) -> Result<(), Box> { + todo!() +} diff --git a/src/wasm_test/mod.rs b/src/wasm_test/mod.rs index 723c677a..8a434dc4 100644 --- a/src/wasm_test/mod.rs +++ b/src/wasm_test/mod.rs @@ -1,3 +1,4 @@ +mod compare; mod runner; pub use runner::wasm_run_anonymous_compare; diff --git a/src/wasm_test/runner.rs b/src/wasm_test/runner.rs index 0f5aa7e7..587dd240 100644 --- a/src/wasm_test/runner.rs +++ b/src/wasm_test/runner.rs @@ -1,9 +1,9 @@ +use super::compare::wasm_compare_document; use crate::compare::sexp; use crate::context::GlobalSettings; use crate::parser::parse_with_settings; use crate::util::emacs_parse_anonymous_org_document; use crate::util::print_versions; -use crate::wasm::ParseResult; use crate::wasm::ToWasm; use crate::wasm::ToWasmContext; @@ -26,10 +26,9 @@ pub async fn wasm_run_anonymous_compare_with_settings<'g, 's, P: AsRef>( } let rust_parsed = parse_with_settings(org_contents, global_settings)?; let to_wasm_context = ToWasmContext::new(org_contents); - let wasm_parsed = match rust_parsed.to_wasm(to_wasm_context) { - Ok(wasm_document) => ParseResult::Success(wasm_document), - Err(err) => ParseResult::Error(format!("{:?}", err)), - }; + let wasm_parsed = rust_parsed + .to_wasm(to_wasm_context) + .map_err(|_e| "Failed to convert to wasm.")?; let org_sexp = emacs_parse_anonymous_org_document(org_contents, global_settings).await?; let (_remaining, parsed_sexp) = sexp(org_sexp.as_str()).map_err(|e| e.to_string())?; @@ -41,7 +40,7 @@ pub async fn wasm_run_anonymous_compare_with_settings<'g, 's, P: AsRef>( } // We do the diffing after printing out both parsed forms in case the diffing panics - // let diff_result = compare_document(&parsed_sexp, &rust_parsed)?; + let diff_result = wasm_compare_document(&parsed_sexp, &wasm_parsed)?; // if !silent { // diff_result.print(org_contents)?; // }