27 Commits

Author SHA1 Message Date
Tom Alexander
23f4ba4205 Serialize to wasm during wasm compare.
Some checks failed
clippy Build clippy has failed
rust-foreign-document-test Build rust-foreign-document-test has succeeded
rust-build Build rust-build has failed
rust-test Build rust-test has succeeded
2023-12-27 08:57:56 -05:00
Tom Alexander
55ad136283 Fix imports for wasm. 2023-12-27 08:49:34 -05:00
Tom Alexander
c717541099 Move the parsing of the elisp to the util module. 2023-12-27 08:46:18 -05:00
Tom Alexander
c2e921c2dc Move wasm test to a top-level module.
For some unknown reason, this makes rust-analyzer not angry.
2023-12-27 08:42:13 -05:00
Tom Alexander
e499169f0e Fix imports for wasm_test.
Some checks failed
clippy Build clippy has failed
rust-build Build rust-build has failed
rust-foreign-document-test Build rust-foreign-document-test has succeeded
rust-test Build rust-test has succeeded
2023-12-27 08:37:34 -05:00
Tom Alexander
84c088df67 Add wasm targets to the build test in the CI.
Some checks failed
clippy Build clippy has failed
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
2023-12-27 08:04:03 -05:00
Tom Alexander
f210f95f99 Use a temporary folder for the builds. 2023-12-26 21:23:20 -05:00
Tom Alexander
17b81c7c72 Add a script to build every possible feature combination. 2023-12-26 21:05:40 -05:00
Tom Alexander
2911fce7cc Put util under the library. 2023-12-26 20:18:41 -05:00
Tom Alexander
e622d9fa6b Remove the old implementation of print_versions.
Some checks failed
clippy Build clippy has failed
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
2023-12-26 19:15:02 -05:00
Tom Alexander
8186fbb8b3 Move print_versions into a util crate. 2023-12-26 19:06:12 -05:00
Tom Alexander
68ccff74fa Outline for the wasm compare function. 2023-12-26 18:55:28 -05:00
Tom Alexander
9a13cb72c6 Make the wasm test binary async. 2023-12-25 14:32:01 -05:00
Tom Alexander
65abaa332f Separate out the wasm test into its own feature/binary. 2023-12-25 13:12:32 -05:00
Tom Alexander
67e5829fd9 Populating document's children. 2023-12-25 12:55:48 -05:00
Tom Alexander
995b41e697 Remove deserialize to support borrows. 2023-12-25 12:42:38 -05:00
Tom Alexander
eb51bdfe2f Add original field name to wasm macro. 2023-12-25 12:32:35 -05:00
Tom Alexander
bbb9ec637a Add code to test the wasm code path without actually dropping into wasm. 2023-12-25 12:14:50 -05:00
Tom Alexander
dc012b49f5 Add a generic WasmAstNode enum. 2023-12-25 11:51:39 -05:00
Tom Alexander
13863a68f7 Add placeholders for all the wasm ast nodes. 2023-12-25 11:33:43 -05:00
Tom Alexander
2962f76c81 Add lifetime to wasm objects. 2023-12-25 11:19:09 -05:00
Tom Alexander
b9b3ef6e74 Populate standard properties. 2023-12-25 10:47:10 -05:00
Tom Alexander
310ab2eab2 Add standard properties to wasm. 2023-12-24 15:26:45 -05:00
Tom Alexander
53320070da Define a wasm document. 2023-12-24 15:17:41 -05:00
Tom Alexander
2d5593681f Start defining the return type. 2023-12-24 13:02:34 -05:00
Tom Alexander
b3f97dbb40 Add wasm-bindgen. 2023-12-24 00:59:41 -05:00
Tom Alexander
a48d76321e Building basic wasm. 2023-12-24 00:47:32 -05:00
78 changed files with 2738 additions and 69 deletions

View File

@@ -192,6 +192,54 @@ spec:
] ]
- name: docker-image - name: docker-image
value: "$(params.image-name):$(tasks.fetch-repository.results.commit)" value: "$(params.image-name):$(tasks.fetch-repository.results.commit)"
- name: run-image-wasm
taskRef:
name: run-docker-image
workspaces:
- name: source
workspace: git-source
- name: cargo-cache
workspace: cargo-cache
runAfter:
- run-image-all
params:
- name: args
value:
[
"--target",
"wasm32-unknown-unknown",
"--profile",
"wasm",
"--bin",
"wasm",
"--no-default-features",
"--features",
"wasm",
]
- name: docker-image
value: "$(params.image-name):$(tasks.fetch-repository.results.commit)"
- name: run-image-wasm-test
taskRef:
name: run-docker-image
workspaces:
- name: source
workspace: git-source
- name: cargo-cache
workspace: cargo-cache
runAfter:
- run-image-wasm
params:
- name: args
value:
[
"--bin",
"wasm_test",
"--no-default-features",
"--features",
"wasm_test",
]
- name: docker-image
value: "$(params.image-name):$(tasks.fetch-repository.results.commit)"
finally: finally:
- name: report-success - name: report-success
when: when:

View File

@@ -39,17 +39,31 @@ path = "src/lib.rs"
path = "src/bin_foreign_document_test.rs" path = "src/bin_foreign_document_test.rs"
required-features = ["foreign_document_test"] required-features = ["foreign_document_test"]
[[bin]]
name = "wasm"
path = "src/bin_wasm.rs"
required-features = ["wasm"]
[[bin]]
name = "wasm_test"
path = "src/bin_wasm_test.rs"
required-features = ["wasm_test"]
[dependencies] [dependencies]
futures = { version = "0.3.28", optional = true } futures = { version = "0.3.28", optional = true }
nom = "7.1.1" nom = "7.1.1"
opentelemetry = { version = "0.20.0", optional = true, default-features = false, features = ["trace", "rt-tokio"] } opentelemetry = { version = "0.20.0", optional = true, default-features = false, features = ["trace", "rt-tokio"] }
opentelemetry-otlp = { version = "0.13.0", optional = true } opentelemetry-otlp = { version = "0.13.0", optional = true }
opentelemetry-semantic-conventions = { version = "0.12.0", optional = true } opentelemetry-semantic-conventions = { version = "0.12.0", optional = true }
serde = { version = "1.0.193", optional = true, features = ["derive"] }
serde-wasm-bindgen = { version = "0.6.3", optional = true }
serde_json = { version = "1.0.108", optional = true }
tokio = { version = "1.30.0", optional = true, default-features = false, features = ["rt", "rt-multi-thread"] } tokio = { version = "1.30.0", optional = true, default-features = false, features = ["rt", "rt-multi-thread"] }
tracing = { version = "0.1.37", optional = true } tracing = { version = "0.1.37", optional = true }
tracing-opentelemetry = { version = "0.20.0", optional = true } tracing-opentelemetry = { version = "0.20.0", optional = true }
tracing-subscriber = { version = "0.3.17", optional = true, features = ["env-filter"] } tracing-subscriber = { version = "0.3.17", optional = true, features = ["env-filter"] }
walkdir = { version = "2.3.3", optional = true } walkdir = { version = "2.3.3", optional = true }
wasm-bindgen = { version = "0.2.89", optional = true }
[build-dependencies] [build-dependencies]
walkdir = "2.3.3" walkdir = "2.3.3"
@@ -60,6 +74,8 @@ compare = ["tokio/process", "tokio/macros"]
foreign_document_test = ["compare", "dep:futures", "tokio/sync", "dep:walkdir", "tokio/process"] foreign_document_test = ["compare", "dep:futures", "tokio/sync", "dep:walkdir", "tokio/process"]
tracing = ["dep:opentelemetry", "dep:opentelemetry-otlp", "dep:opentelemetry-semantic-conventions", "dep:tokio", "dep:tracing", "dep:tracing-opentelemetry", "dep:tracing-subscriber"] tracing = ["dep:opentelemetry", "dep:opentelemetry-otlp", "dep:opentelemetry-semantic-conventions", "dep:tokio", "dep:tracing", "dep:tracing-opentelemetry", "dep:tracing-subscriber"]
event_count = [] event_count = []
wasm = ["dep:serde", "dep:wasm-bindgen", "dep:serde-wasm-bindgen"]
wasm_test = ["wasm", "dep:serde_json", "tokio/process", "tokio/macros"]
# Optimized build for any sort of release. # Optimized build for any sort of release.
[profile.release-lto] [profile.release-lto]
@@ -79,3 +95,8 @@ strip = "symbols"
inherits = "release" inherits = "release"
lto = true lto = true
debug = true debug = true
[profile.wasm]
inherits = "release"
lto = true
strip = true

View File

@@ -29,6 +29,15 @@ build:
release: release:
> cargo build --release $(RELEASEFLAGS) > cargo build --release $(RELEASEFLAGS)
.PHONY: wasm
wasm:
> cargo build --target=wasm32-unknown-unknown --profile wasm --bin wasm --features wasm
> wasm-bindgen --target web --out-dir target/wasm32-unknown-unknown/js target/wasm32-unknown-unknown/wasm/wasm.wasm
.PHONY: run_wasm
run_wasm:
> cat /tmp/test.org | cargo run --profile wasm --bin wasm_test --features wasm_test | jq
.PHONY: clean .PHONY: clean
clean: clean:
> cargo clean > cargo clean

View File

@@ -2,5 +2,6 @@ FROM rustlang/rust:nightly-alpine3.17
RUN apk add --no-cache musl-dev RUN apk add --no-cache musl-dev
RUN cargo install --locked --no-default-features --features ci-autoclean cargo-cache RUN cargo install --locked --no-default-features --features ci-autoclean cargo-cache
RUN rustup target add wasm32-unknown-unknown
ENTRYPOINT ["cargo", "build"] ENTRYPOINT ["cargo", "build"]

View File

@@ -0,0 +1,76 @@
#!/usr/bin/env bash
#
# Time running a single parse without invoking a compare with emacs.
set -euo pipefail
IFS=$'\n\t'
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
: ${PROFILE:="debug"}
############## Setup #########################
function cleanup {
for f in "${folders[@]}"; do
log "Deleting $f"
rm -rf "$f"
done
}
folders=()
for sig in EXIT INT QUIT HUP TERM; do
trap "set +e; cleanup" "$sig"
done
function die {
local status_code="$1"
shift
(>&2 echo "${@}")
exit "$status_code"
}
function log {
(>&2 echo "${@}")
}
############## Program #########################
function main {
if [ "$#" -gt 0 ]; then
export CARGO_TARGET_DIR="$1"
else
local work_directory=$(mktemp -d -t 'organic.XXXXXX')
folders+=("$work_directory")
export CARGO_TARGET_DIR="$work_directory"
fi
local features=(compare foreign_document_test tracing event_count wasm wasm_test)
ENABLED_FEATURES= for_each_combination "${features[@]}"
}
function for_each_combination {
local additional_flags=()
if [ "$PROFILE" = "dev" ] || [ "$PROFILE" = "debug" ]; then
PROFILE="debug"
else
additional_flags+=(--profile "$PROFILE")
fi
local flag=$1
shift
if [ "$#" -gt 0 ]; then
ENABLED_FEATURES="$ENABLED_FEATURES" for_each_combination "${@}"
elif [ -z "$ENABLED_FEATURES" ]; then
(cd "$DIR/../" && printf "\n\n\n========== no features ==========\n\n\n" && set -x && cargo build "${additional_flags[@]}" --no-default-features)
else
(cd "$DIR/../" && printf "\n\n\n========== %s ==========\n\n\n" "${ENABLED_FEATURES:1}" && set -x && cargo build "${additional_flags[@]}" --no-default-features --features "${ENABLED_FEATURES:1}")
fi
ENABLED_FEATURES="$ENABLED_FEATURES,$flag"
if [ "$#" -gt 0 ]; then
ENABLED_FEATURES="$ENABLED_FEATURES" for_each_combination "${@}"
else
(cd "$DIR/../" && printf "\n\n\n========== %s ==========\n\n\n" "${ENABLED_FEATURES:1}" && set -x && cargo build "${additional_flags[@]}" --no-default-features --features "${ENABLED_FEATURES:1}")
fi
}
main "${@}"

View File

@@ -1,3 +1,4 @@
#![feature(exit_status_error)]
#![feature(round_char_boundary)] #![feature(round_char_boundary)]
#![feature(exact_size_is_empty)] #![feature(exact_size_is_empty)]
use std::io::Read; use std::io::Read;

12
src/bin_wasm.rs Normal file
View File

@@ -0,0 +1,12 @@
use organic::wasm::wasm_parse_org;
use wasm_bindgen::prelude::wasm_bindgen;
#[wasm_bindgen]
pub fn parse_org(org_contents: &str) -> wasm_bindgen::JsValue {
let rust_parsed = wasm_parse_org(org_contents);
serde_wasm_bindgen::to_value(&rust_parsed).unwrap()
}
fn main() -> Result<(), Box<dyn std::error::Error>> {
Ok(())
}

62
src/bin_wasm_test.rs Normal file
View File

@@ -0,0 +1,62 @@
#![feature(exact_size_is_empty)]
#![feature(exit_status_error)]
use std::io::Read;
use organic::wasm_test::wasm_run_anonymous_compare;
#[cfg(feature = "tracing")]
use crate::init_tracing::init_telemetry;
#[cfg(feature = "tracing")]
use crate::init_tracing::shutdown_telemetry;
#[cfg(feature = "tracing")]
mod init_tracing;
#[cfg(not(feature = "tracing"))]
fn main() -> Result<(), Box<dyn std::error::Error>> {
let rt = tokio::runtime::Runtime::new()?;
rt.block_on(async {
let main_body_result = main_body().await;
main_body_result
})
}
#[cfg(feature = "tracing")]
fn main() -> Result<(), Box<dyn std::error::Error>> {
let rt = tokio::runtime::Runtime::new()?;
rt.block_on(async {
init_telemetry()?;
let main_body_result = main_body().await;
shutdown_telemetry()?;
main_body_result
})
}
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
async fn main_body() -> Result<(), Box<dyn std::error::Error>> {
let args = std::env::args().skip(1);
if args.is_empty() {
let org_contents = read_stdin_to_string()?;
if wasm_run_anonymous_compare(org_contents).await? {
} else {
Err("Diff results do not match.")?;
}
Ok(())
} else {
todo!()
// for arg in args {
// if run_compare_on_file(arg).await? {
// } else {
// Err("Diff results do not match.")?;
// }
// }
// Ok(())
}
}
fn read_stdin_to_string() -> Result<String, Box<dyn std::error::Error>> {
let mut stdin_contents = String::new();
std::io::stdin()
.lock()
.read_to_string(&mut stdin_contents)?;
Ok(stdin_contents)
}

View File

@@ -2,15 +2,14 @@ use std::path::Path;
use crate::compare::diff::compare_document; use crate::compare::diff::compare_document;
use crate::compare::diff::DiffResult; use crate::compare::diff::DiffResult;
use crate::compare::parse::emacs_parse_anonymous_org_document;
use crate::compare::parse::emacs_parse_file_org_document;
use crate::compare::parse::get_emacs_version;
use crate::compare::parse::get_org_mode_version;
use crate::compare::sexp::sexp; use crate::compare::sexp::sexp;
use crate::context::GlobalSettings; use crate::context::GlobalSettings;
use crate::context::LocalFileAccessInterface; use crate::context::LocalFileAccessInterface;
use crate::parser::parse_file_with_settings; use crate::parser::parse_file_with_settings;
use crate::parser::parse_with_settings; use crate::parser::parse_with_settings;
use crate::util::emacs_parse_anonymous_org_document;
use crate::util::emacs_parse_file_org_document;
use crate::util::print_versions;
pub async fn run_anonymous_compare<P: AsRef<str>>( pub async fn run_anonymous_compare<P: AsRef<str>>(
org_contents: P, org_contents: P,
@@ -128,12 +127,3 @@ pub async fn run_compare_on_file_with_settings<'g, 's, P: AsRef<Path>>(
Ok(true) Ok(true)
} }
async fn print_versions() -> Result<(), Box<dyn std::error::Error>> {
eprintln!("Using emacs version: {}", get_emacs_version().await?.trim());
eprintln!(
"Using org-mode version: {}",
get_org_mode_version().await?.trim()
);
Ok(())
}

View File

@@ -4,7 +4,6 @@ mod compare_field;
mod diff; mod diff;
mod elisp_fact; mod elisp_fact;
mod macros; mod macros;
mod parse;
mod sexp; mod sexp;
mod util; mod util;
pub use compare::run_anonymous_compare; pub use compare::run_anonymous_compare;
@@ -13,3 +12,4 @@ pub use compare::run_compare_on_file;
pub use compare::run_compare_on_file_with_settings; pub use compare::run_compare_on_file_with_settings;
pub use compare::silent_anonymous_compare; pub use compare::silent_anonymous_compare;
pub use compare::silent_compare_on_file; pub use compare::silent_compare_on_file;
pub use sexp::sexp;

View File

@@ -10,6 +10,12 @@ extern crate test;
#[cfg(feature = "compare")] #[cfg(feature = "compare")]
pub mod compare; pub mod compare;
#[cfg(any(feature = "compare", feature = "wasm_test"))]
pub mod util;
#[cfg(any(feature = "wasm", feature = "wasm_test"))]
pub mod wasm;
#[cfg(feature = "wasm_test")]
pub mod wasm_test;
mod context; mod context;
mod error; mod error;

View File

@@ -2,28 +2,53 @@ use std::path::Path;
use tokio::process::Command; use tokio::process::Command;
use crate::context::HeadlineLevelFilter;
use crate::settings::GlobalSettings; use crate::settings::GlobalSettings;
use crate::settings::HeadlineLevelFilter;
/// Generate elisp to configure org-mode parsing settings pub async fn print_versions() -> Result<(), Box<dyn std::error::Error>> {
/// eprintln!("Using emacs version: {}", get_emacs_version().await?.trim());
/// Currently only org-list-allow-alphabetical is supported. eprintln!(
fn global_settings_elisp(global_settings: &GlobalSettings) -> String { "Using org-mode version: {}",
// This string concatenation is wildly inefficient but its only called in tests 🤷. get_org_mode_version().await?.trim()
let mut ret = "".to_owned(); );
if global_settings.list_allow_alphabetical { Ok(())
ret += "(setq org-list-allow-alphabetical t)\n"
} }
if global_settings.tab_width != crate::settings::DEFAULT_TAB_WIDTH {
ret += format!("(setq-default tab-width {})", global_settings.tab_width).as_str(); pub(crate) async fn get_emacs_version() -> Result<String, Box<dyn std::error::Error>> {
let elisp_script = r#"(progn
(message "%s" (version))
)"#;
let mut cmd = Command::new("emacs");
let cmd = cmd
.arg("-q")
.arg("--no-site-file")
.arg("--no-splash")
.arg("--batch")
.arg("--eval")
.arg(elisp_script);
let out = cmd.output().await?;
out.status.exit_ok()?;
Ok(String::from_utf8(out.stderr)?)
} }
if global_settings.odd_levels_only != HeadlineLevelFilter::default() {
ret += match global_settings.odd_levels_only { pub(crate) async fn get_org_mode_version() -> Result<String, Box<dyn std::error::Error>> {
HeadlineLevelFilter::Odd => "(setq org-odd-levels-only t)\n", let elisp_script = r#"(progn
HeadlineLevelFilter::OddEven => "(setq org-odd-levels-only nil)\n", (org-mode)
}; (message "%s" (org-version nil t nil))
} )"#;
ret let mut cmd = Command::new("emacs");
let cmd = cmd
.arg("-q")
.arg("--no-site-file")
.arg("--no-splash")
.arg("--batch")
.arg("--eval")
.arg(elisp_script);
let out = cmd.output().await?;
out.status.exit_ok()?;
Ok(String::from_utf8(out.stderr)?)
} }
pub(crate) async fn emacs_parse_anonymous_org_document<'g, 's, C>( pub(crate) async fn emacs_parse_anonymous_org_document<'g, 's, C>(
@@ -144,39 +169,23 @@ where
output output
} }
pub async fn get_emacs_version() -> Result<String, Box<dyn std::error::Error>> { /// Generate elisp to configure org-mode parsing settings
let elisp_script = r#"(progn ///
(message "%s" (version)) /// Currently only org-list-allow-alphabetical is supported.
)"#; fn global_settings_elisp(global_settings: &GlobalSettings) -> String {
let mut cmd = Command::new("emacs"); // This string concatenation is wildly inefficient but its only called in tests 🤷.
let cmd = cmd let mut ret = "".to_owned();
.arg("-q") if global_settings.list_allow_alphabetical {
.arg("--no-site-file") ret += "(setq org-list-allow-alphabetical t)\n"
.arg("--no-splash")
.arg("--batch")
.arg("--eval")
.arg(elisp_script);
let out = cmd.output().await?;
out.status.exit_ok()?;
Ok(String::from_utf8(out.stderr)?)
} }
if global_settings.tab_width != crate::settings::DEFAULT_TAB_WIDTH {
pub async fn get_org_mode_version() -> Result<String, Box<dyn std::error::Error>> { ret += format!("(setq-default tab-width {})", global_settings.tab_width).as_str();
let elisp_script = r#"(progn }
(org-mode) if global_settings.odd_levels_only != HeadlineLevelFilter::default() {
(message "%s" (org-version nil t nil)) ret += match global_settings.odd_levels_only {
)"#; HeadlineLevelFilter::Odd => "(setq org-odd-levels-only t)\n",
let mut cmd = Command::new("emacs"); HeadlineLevelFilter::OddEven => "(setq org-odd-levels-only nil)\n",
let cmd = cmd };
.arg("-q") }
.arg("--no-site-file") ret
.arg("--no-splash")
.arg("--batch")
.arg("--eval")
.arg(elisp_script);
let out = cmd.output().await?;
out.status.exit_ok()?;
Ok(String::from_utf8(out.stderr)?)
} }

34
src/wasm/angle_link.rs Normal file
View File

@@ -0,0 +1,34 @@
use std::marker::PhantomData;
use crate::types::AngleLink;
use serde::Deserialize;
use serde::Serialize;
use super::macros::to_wasm;
use super::standard_properties::WasmStandardProperties;
use super::to_wasm::ToWasm;
use crate::wasm::to_wasm::ToWasmStandardProperties;
#[derive(Debug, Serialize)]
#[serde(tag = "ast_node")]
#[serde(rename = "org-data")]
pub(crate) struct WasmAngleLink<'s> {
standard_properties: WasmStandardProperties,
children: Vec<()>,
phantom: PhantomData<&'s ()>,
}
to_wasm!(
WasmAngleLink<'s>,
AngleLink<'s>,
original,
wasm_context,
standard_properties,
{
Ok(WasmAngleLink {
standard_properties,
children: Vec::new(),
phantom: PhantomData,
})
}
);

128
src/wasm/ast_node.rs Normal file
View File

@@ -0,0 +1,128 @@
use serde::Serialize;
use super::angle_link::WasmAngleLink;
use super::babel_call::WasmBabelCall;
use super::bold::WasmBold;
use super::center_block::WasmCenterBlock;
use super::citation::WasmCitation;
use super::citation_reference::WasmCitationReference;
use super::clock::WasmClock;
use super::code::WasmCode;
use super::comment::WasmComment;
use super::comment_block::WasmCommentBlock;
use super::diary_sexp::WasmDiarySexp;
use super::document::WasmDocument;
use super::drawer::WasmDrawer;
use super::dynamic_block::WasmDynamicBlock;
use super::entity::WasmEntity;
use super::example_block::WasmExampleBlock;
use super::export_block::WasmExportBlock;
use super::export_snippet::WasmExportSnippet;
use super::fixed_width_area::WasmFixedWidthArea;
use super::footnote_definition::WasmFootnoteDefinition;
use super::footnote_reference::WasmFootnoteReference;
use super::headline::WasmHeadline;
use super::horizontal_rule::WasmHorizontalRule;
use super::inline_babel_call::WasmInlineBabelCall;
use super::inline_source_block::WasmInlineSourceBlock;
use super::italic::WasmItalic;
use super::keyword::WasmKeyword;
use super::latex_environment::WasmLatexEnvironment;
use super::latex_fragment::WasmLatexFragment;
use super::line_break::WasmLineBreak;
use super::node_property::WasmNodeProperty;
use super::org_macro::WasmOrgMacro;
use super::paragraph::WasmParagraph;
use super::plain_link::WasmPlainLink;
use super::plain_list::WasmPlainList;
use super::plain_list_item::WasmPlainListItem;
use super::plain_text::WasmPlainText;
use super::planning::WasmPlanning;
use super::property_drawer::WasmPropertyDrawer;
use super::quote_block::WasmQuoteBlock;
use super::radio_link::WasmRadioLink;
use super::radio_target::WasmRadioTarget;
use super::regular_link::WasmRegularLink;
use super::section::WasmSection;
use super::special_block::WasmSpecialBlock;
use super::src_block::WasmSrcBlock;
use super::statistics_cookie::WasmStatisticsCookie;
use super::strike_through::WasmStrikeThrough;
use super::subscript::WasmSubscript;
use super::superscript::WasmSuperscript;
use super::table::WasmTable;
use super::table_cell::WasmTableCell;
use super::table_row::WasmTableRow;
use super::target::WasmTarget;
use super::timestamp::WasmTimestamp;
use super::underline::WasmUnderline;
use super::verbatim::WasmVerbatim;
use super::verse_block::WasmVerseBlock;
#[derive(Debug, Serialize)]
#[serde(untagged)]
pub enum WasmAstNode<'s> {
// Document Nodes
Document(WasmDocument<'s>),
Headline(WasmHeadline<'s>),
Section(WasmSection<'s>),
// Elements
Paragraph(WasmParagraph<'s>),
PlainList(WasmPlainList<'s>),
PlainListItem(WasmPlainListItem<'s>),
CenterBlock(WasmCenterBlock<'s>),
QuoteBlock(WasmQuoteBlock<'s>),
SpecialBlock(WasmSpecialBlock<'s>),
DynamicBlock(WasmDynamicBlock<'s>),
FootnoteDefinition(WasmFootnoteDefinition<'s>),
Comment(WasmComment<'s>),
Drawer(WasmDrawer<'s>),
PropertyDrawer(WasmPropertyDrawer<'s>),
NodeProperty(WasmNodeProperty<'s>),
Table(WasmTable<'s>),
TableRow(WasmTableRow<'s>),
VerseBlock(WasmVerseBlock<'s>),
CommentBlock(WasmCommentBlock<'s>),
ExampleBlock(WasmExampleBlock<'s>),
ExportBlock(WasmExportBlock<'s>),
SrcBlock(WasmSrcBlock<'s>),
Clock(WasmClock<'s>),
DiarySexp(WasmDiarySexp<'s>),
Planning(WasmPlanning<'s>),
FixedWidthArea(WasmFixedWidthArea<'s>),
HorizontalRule(WasmHorizontalRule<'s>),
Keyword(WasmKeyword<'s>),
BabelCall(WasmBabelCall<'s>),
LatexEnvironment(WasmLatexEnvironment<'s>),
// Objects
Bold(WasmBold<'s>),
Italic(WasmItalic<'s>),
Underline(WasmUnderline<'s>),
StrikeThrough(WasmStrikeThrough<'s>),
Code(WasmCode<'s>),
Verbatim(WasmVerbatim<'s>),
PlainText(WasmPlainText<'s>),
RegularLink(WasmRegularLink<'s>),
RadioLink(WasmRadioLink<'s>),
RadioTarget(WasmRadioTarget<'s>),
PlainLink(WasmPlainLink<'s>),
AngleLink(WasmAngleLink<'s>),
OrgMacro(WasmOrgMacro<'s>),
Entity(WasmEntity<'s>),
LatexFragment(WasmLatexFragment<'s>),
ExportSnippet(WasmExportSnippet<'s>),
FootnoteReference(WasmFootnoteReference<'s>),
Citation(WasmCitation<'s>),
CitationReference(WasmCitationReference<'s>),
InlineBabelCall(WasmInlineBabelCall<'s>),
InlineSourceBlock(WasmInlineSourceBlock<'s>),
LineBreak(WasmLineBreak<'s>),
Target(WasmTarget<'s>),
StatisticsCookie(WasmStatisticsCookie<'s>),
Subscript(WasmSubscript<'s>),
Superscript(WasmSuperscript<'s>),
TableCell(WasmTableCell<'s>),
Timestamp(WasmTimestamp<'s>),
}
impl<'s> WasmAstNode<'s> {}

34
src/wasm/babel_call.rs Normal file
View File

@@ -0,0 +1,34 @@
use std::marker::PhantomData;
use crate::types::BabelCall;
use serde::Deserialize;
use serde::Serialize;
use super::macros::to_wasm;
use super::standard_properties::WasmStandardProperties;
use super::to_wasm::ToWasm;
use crate::wasm::to_wasm::ToWasmStandardProperties;
#[derive(Debug, Serialize)]
#[serde(tag = "ast_node")]
#[serde(rename = "org-data")]
pub(crate) struct WasmBabelCall<'s> {
standard_properties: WasmStandardProperties,
children: Vec<()>,
phantom: PhantomData<&'s ()>,
}
to_wasm!(
WasmBabelCall<'s>,
BabelCall<'s>,
original,
wasm_context,
standard_properties,
{
Ok(WasmBabelCall {
standard_properties,
children: Vec::new(),
phantom: PhantomData,
})
}
);

34
src/wasm/bold.rs Normal file
View File

@@ -0,0 +1,34 @@
use std::marker::PhantomData;
use serde::Deserialize;
use serde::Serialize;
use super::macros::to_wasm;
use super::standard_properties::WasmStandardProperties;
use super::to_wasm::ToWasm;
use crate::types::Bold;
use crate::wasm::to_wasm::ToWasmStandardProperties;
#[derive(Debug, Serialize)]
#[serde(tag = "ast_node")]
#[serde(rename = "org-data")]
pub(crate) struct WasmBold<'s> {
standard_properties: WasmStandardProperties,
children: Vec<()>,
phantom: PhantomData<&'s ()>,
}
to_wasm!(
WasmBold<'s>,
Bold<'s>,
original,
wasm_context,
standard_properties,
{
Ok(WasmBold {
standard_properties,
children: Vec::new(),
phantom: PhantomData,
})
}
);

34
src/wasm/center_block.rs Normal file
View File

@@ -0,0 +1,34 @@
use std::marker::PhantomData;
use crate::types::CenterBlock;
use serde::Deserialize;
use serde::Serialize;
use super::macros::to_wasm;
use super::standard_properties::WasmStandardProperties;
use super::to_wasm::ToWasm;
use crate::wasm::to_wasm::ToWasmStandardProperties;
#[derive(Debug, Serialize)]
#[serde(tag = "ast_node")]
#[serde(rename = "org-data")]
pub(crate) struct WasmCenterBlock<'s> {
standard_properties: WasmStandardProperties,
children: Vec<()>,
phantom: PhantomData<&'s ()>,
}
to_wasm!(
WasmCenterBlock<'s>,
CenterBlock<'s>,
original,
wasm_context,
standard_properties,
{
Ok(WasmCenterBlock {
standard_properties,
children: Vec::new(),
phantom: PhantomData,
})
}
);

34
src/wasm/citation.rs Normal file
View File

@@ -0,0 +1,34 @@
use std::marker::PhantomData;
use crate::types::Citation;
use serde::Deserialize;
use serde::Serialize;
use super::macros::to_wasm;
use super::standard_properties::WasmStandardProperties;
use super::to_wasm::ToWasm;
use crate::wasm::to_wasm::ToWasmStandardProperties;
#[derive(Debug, Serialize)]
#[serde(tag = "ast_node")]
#[serde(rename = "org-data")]
pub(crate) struct WasmCitation<'s> {
standard_properties: WasmStandardProperties,
children: Vec<()>,
phantom: PhantomData<&'s ()>,
}
to_wasm!(
WasmCitation<'s>,
Citation<'s>,
original,
wasm_context,
standard_properties,
{
Ok(WasmCitation {
standard_properties,
children: Vec::new(),
phantom: PhantomData,
})
}
);

View File

@@ -0,0 +1,34 @@
use std::marker::PhantomData;
use crate::types::CitationReference;
use serde::Deserialize;
use serde::Serialize;
use super::macros::to_wasm;
use super::standard_properties::WasmStandardProperties;
use super::to_wasm::ToWasm;
use crate::wasm::to_wasm::ToWasmStandardProperties;
#[derive(Debug, Serialize)]
#[serde(tag = "ast_node")]
#[serde(rename = "org-data")]
pub(crate) struct WasmCitationReference<'s> {
standard_properties: WasmStandardProperties,
children: Vec<()>,
phantom: PhantomData<&'s ()>,
}
to_wasm!(
WasmCitationReference<'s>,
CitationReference<'s>,
original,
wasm_context,
standard_properties,
{
Ok(WasmCitationReference {
standard_properties,
children: Vec::new(),
phantom: PhantomData,
})
}
);

34
src/wasm/clock.rs Normal file
View File

@@ -0,0 +1,34 @@
use std::marker::PhantomData;
use crate::types::Clock;
use serde::Deserialize;
use serde::Serialize;
use super::macros::to_wasm;
use super::standard_properties::WasmStandardProperties;
use super::to_wasm::ToWasm;
use crate::wasm::to_wasm::ToWasmStandardProperties;
#[derive(Debug, Serialize)]
#[serde(tag = "ast_node")]
#[serde(rename = "org-data")]
pub(crate) struct WasmClock<'s> {
standard_properties: WasmStandardProperties,
children: Vec<()>,
phantom: PhantomData<&'s ()>,
}
to_wasm!(
WasmClock<'s>,
Clock<'s>,
original,
wasm_context,
standard_properties,
{
Ok(WasmClock {
standard_properties,
children: Vec::new(),
phantom: PhantomData,
})
}
);

34
src/wasm/code.rs Normal file
View File

@@ -0,0 +1,34 @@
use std::marker::PhantomData;
use crate::types::Code;
use serde::Deserialize;
use serde::Serialize;
use super::macros::to_wasm;
use super::standard_properties::WasmStandardProperties;
use super::to_wasm::ToWasm;
use crate::wasm::to_wasm::ToWasmStandardProperties;
#[derive(Debug, Serialize)]
#[serde(tag = "ast_node")]
#[serde(rename = "org-data")]
pub(crate) struct WasmCode<'s> {
standard_properties: WasmStandardProperties,
children: Vec<()>,
phantom: PhantomData<&'s ()>,
}
to_wasm!(
WasmCode<'s>,
Code<'s>,
original,
wasm_context,
standard_properties,
{
Ok(WasmCode {
standard_properties,
children: Vec::new(),
phantom: PhantomData,
})
}
);

34
src/wasm/comment.rs Normal file
View File

@@ -0,0 +1,34 @@
use std::marker::PhantomData;
use crate::types::Comment;
use serde::Deserialize;
use serde::Serialize;
use super::macros::to_wasm;
use super::standard_properties::WasmStandardProperties;
use super::to_wasm::ToWasm;
use crate::wasm::to_wasm::ToWasmStandardProperties;
#[derive(Debug, Serialize)]
#[serde(tag = "ast_node")]
#[serde(rename = "org-data")]
pub(crate) struct WasmComment<'s> {
standard_properties: WasmStandardProperties,
children: Vec<()>,
phantom: PhantomData<&'s ()>,
}
to_wasm!(
WasmComment<'s>,
Comment<'s>,
original,
wasm_context,
standard_properties,
{
Ok(WasmComment {
standard_properties,
children: Vec::new(),
phantom: PhantomData,
})
}
);

34
src/wasm/comment_block.rs Normal file
View File

@@ -0,0 +1,34 @@
use std::marker::PhantomData;
use crate::types::CommentBlock;
use serde::Deserialize;
use serde::Serialize;
use super::macros::to_wasm;
use super::standard_properties::WasmStandardProperties;
use super::to_wasm::ToWasm;
use crate::wasm::to_wasm::ToWasmStandardProperties;
#[derive(Debug, Serialize)]
#[serde(tag = "ast_node")]
#[serde(rename = "org-data")]
pub(crate) struct WasmCommentBlock<'s> {
standard_properties: WasmStandardProperties,
children: Vec<()>,
phantom: PhantomData<&'s ()>,
}
to_wasm!(
WasmCommentBlock<'s>,
CommentBlock<'s>,
original,
wasm_context,
standard_properties,
{
Ok(WasmCommentBlock {
standard_properties,
children: Vec::new(),
phantom: PhantomData,
})
}
);

34
src/wasm/diary_sexp.rs Normal file
View File

@@ -0,0 +1,34 @@
use std::marker::PhantomData;
use crate::types::DiarySexp;
use serde::Deserialize;
use serde::Serialize;
use super::macros::to_wasm;
use super::standard_properties::WasmStandardProperties;
use super::to_wasm::ToWasm;
use crate::wasm::to_wasm::ToWasmStandardProperties;
#[derive(Debug, Serialize)]
#[serde(tag = "ast_node")]
#[serde(rename = "org-data")]
pub(crate) struct WasmDiarySexp<'s> {
standard_properties: WasmStandardProperties,
children: Vec<()>,
phantom: PhantomData<&'s ()>,
}
to_wasm!(
WasmDiarySexp<'s>,
DiarySexp<'s>,
original,
wasm_context,
standard_properties,
{
Ok(WasmDiarySexp {
standard_properties,
children: Vec::new(),
phantom: PhantomData,
})
}
);

72
src/wasm/document.rs Normal file
View File

@@ -0,0 +1,72 @@
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::wasm::to_wasm::ToWasmStandardProperties;
#[derive(Debug, Serialize)]
#[serde(tag = "ast_node")]
#[serde(rename = "org-data")]
pub(crate) struct WasmDocument<'s> {
standard_properties: WasmStandardProperties,
additional_properties: Vec<(String, &'s str)>,
children: Vec<WasmAstNode<'s>>,
}
to_wasm!(
WasmDocument<'s>,
Document<'s>,
original,
wasm_context,
standard_properties,
{
let additional_properties: Vec<(String, &str)> = original
.get_additional_properties()
.map(|node_property| {
(
format!(":{}", node_property.property_name.to_uppercase()),
node_property.value.unwrap_or(""),
)
})
.collect();
let children = original
.zeroth_section
.iter()
.map(|child| {
child
.to_wasm(wasm_context.clone())
.map(Into::<WasmAstNode<'_>>::into)
})
.chain(original.children.iter().map(|child| {
child
.to_wasm(wasm_context.clone())
.map(Into::<WasmAstNode<'_>>::into)
}))
.collect::<Result<Vec<_>, _>>()?;
// let children = original
// .children
// .iter()
// .map(|child| {
// child
// .to_wasm(wasm_context.clone())
// .map(Into::<WasmAstNode<'_>>::into)
// })
// .collect::<Result<Vec<_>, _>>()?;
Ok(WasmDocument {
standard_properties,
additional_properties,
children,
})
}
);
impl<'s> Into<WasmAstNode<'s>> for WasmDocument<'s> {
fn into(self) -> WasmAstNode<'s> {
WasmAstNode::Document(self)
}
}

34
src/wasm/drawer.rs Normal file
View File

@@ -0,0 +1,34 @@
use std::marker::PhantomData;
use crate::types::Drawer;
use serde::Deserialize;
use serde::Serialize;
use super::macros::to_wasm;
use super::standard_properties::WasmStandardProperties;
use super::to_wasm::ToWasm;
use crate::wasm::to_wasm::ToWasmStandardProperties;
#[derive(Debug, Serialize)]
#[serde(tag = "ast_node")]
#[serde(rename = "org-data")]
pub(crate) struct WasmDrawer<'s> {
standard_properties: WasmStandardProperties,
children: Vec<()>,
phantom: PhantomData<&'s ()>,
}
to_wasm!(
WasmDrawer<'s>,
Drawer<'s>,
original,
wasm_context,
standard_properties,
{
Ok(WasmDrawer {
standard_properties,
children: Vec::new(),
phantom: PhantomData,
})
}
);

34
src/wasm/dynamic_block.rs Normal file
View File

@@ -0,0 +1,34 @@
use std::marker::PhantomData;
use crate::types::DynamicBlock;
use serde::Deserialize;
use serde::Serialize;
use super::macros::to_wasm;
use super::standard_properties::WasmStandardProperties;
use super::to_wasm::ToWasm;
use crate::wasm::to_wasm::ToWasmStandardProperties;
#[derive(Debug, Serialize)]
#[serde(tag = "ast_node")]
#[serde(rename = "org-data")]
pub(crate) struct WasmDynamicBlock<'s> {
standard_properties: WasmStandardProperties,
children: Vec<()>,
phantom: PhantomData<&'s ()>,
}
to_wasm!(
WasmDynamicBlock<'s>,
DynamicBlock<'s>,
original,
wasm_context,
standard_properties,
{
Ok(WasmDynamicBlock {
standard_properties,
children: Vec::new(),
phantom: PhantomData,
})
}
);

34
src/wasm/entity.rs Normal file
View File

@@ -0,0 +1,34 @@
use std::marker::PhantomData;
use crate::types::Entity;
use serde::Deserialize;
use serde::Serialize;
use super::macros::to_wasm;
use super::standard_properties::WasmStandardProperties;
use super::to_wasm::ToWasm;
use crate::wasm::to_wasm::ToWasmStandardProperties;
#[derive(Debug, Serialize)]
#[serde(tag = "ast_node")]
#[serde(rename = "org-data")]
pub(crate) struct WasmEntity<'s> {
standard_properties: WasmStandardProperties,
children: Vec<()>,
phantom: PhantomData<&'s ()>,
}
to_wasm!(
WasmEntity<'s>,
Entity<'s>,
original,
wasm_context,
standard_properties,
{
Ok(WasmEntity {
standard_properties,
children: Vec::new(),
phantom: PhantomData,
})
}
);

34
src/wasm/example_block.rs Normal file
View File

@@ -0,0 +1,34 @@
use std::marker::PhantomData;
use crate::types::ExampleBlock;
use serde::Deserialize;
use serde::Serialize;
use super::macros::to_wasm;
use super::standard_properties::WasmStandardProperties;
use super::to_wasm::ToWasm;
use crate::wasm::to_wasm::ToWasmStandardProperties;
#[derive(Debug, Serialize)]
#[serde(tag = "ast_node")]
#[serde(rename = "org-data")]
pub(crate) struct WasmExampleBlock<'s> {
standard_properties: WasmStandardProperties,
children: Vec<()>,
phantom: PhantomData<&'s ()>,
}
to_wasm!(
WasmExampleBlock<'s>,
ExampleBlock<'s>,
original,
wasm_context,
standard_properties,
{
Ok(WasmExampleBlock {
standard_properties,
children: Vec::new(),
phantom: PhantomData,
})
}
);

34
src/wasm/export_block.rs Normal file
View File

@@ -0,0 +1,34 @@
use std::marker::PhantomData;
use crate::types::ExportBlock;
use serde::Deserialize;
use serde::Serialize;
use super::macros::to_wasm;
use super::standard_properties::WasmStandardProperties;
use super::to_wasm::ToWasm;
use crate::wasm::to_wasm::ToWasmStandardProperties;
#[derive(Debug, Serialize)]
#[serde(tag = "ast_node")]
#[serde(rename = "org-data")]
pub(crate) struct WasmExportBlock<'s> {
standard_properties: WasmStandardProperties,
children: Vec<()>,
phantom: PhantomData<&'s ()>,
}
to_wasm!(
WasmExportBlock<'s>,
ExportBlock<'s>,
original,
wasm_context,
standard_properties,
{
Ok(WasmExportBlock {
standard_properties,
children: Vec::new(),
phantom: PhantomData,
})
}
);

View File

@@ -0,0 +1,34 @@
use std::marker::PhantomData;
use crate::types::ExportSnippet;
use serde::Deserialize;
use serde::Serialize;
use super::macros::to_wasm;
use super::standard_properties::WasmStandardProperties;
use super::to_wasm::ToWasm;
use crate::wasm::to_wasm::ToWasmStandardProperties;
#[derive(Debug, Serialize)]
#[serde(tag = "ast_node")]
#[serde(rename = "org-data")]
pub(crate) struct WasmExportSnippet<'s> {
standard_properties: WasmStandardProperties,
children: Vec<()>,
phantom: PhantomData<&'s ()>,
}
to_wasm!(
WasmExportSnippet<'s>,
ExportSnippet<'s>,
original,
wasm_context,
standard_properties,
{
Ok(WasmExportSnippet {
standard_properties,
children: Vec::new(),
phantom: PhantomData,
})
}
);

View File

@@ -0,0 +1,34 @@
use std::marker::PhantomData;
use crate::types::FixedWidthArea;
use serde::Deserialize;
use serde::Serialize;
use super::macros::to_wasm;
use super::standard_properties::WasmStandardProperties;
use super::to_wasm::ToWasm;
use crate::wasm::to_wasm::ToWasmStandardProperties;
#[derive(Debug, Serialize)]
#[serde(tag = "ast_node")]
#[serde(rename = "org-data")]
pub(crate) struct WasmFixedWidthArea<'s> {
standard_properties: WasmStandardProperties,
children: Vec<()>,
phantom: PhantomData<&'s ()>,
}
to_wasm!(
WasmFixedWidthArea<'s>,
FixedWidthArea<'s>,
original,
wasm_context,
standard_properties,
{
Ok(WasmFixedWidthArea {
standard_properties,
children: Vec::new(),
phantom: PhantomData,
})
}
);

View File

@@ -0,0 +1,34 @@
use std::marker::PhantomData;
use crate::types::FootnoteDefinition;
use serde::Deserialize;
use serde::Serialize;
use super::macros::to_wasm;
use super::standard_properties::WasmStandardProperties;
use super::to_wasm::ToWasm;
use crate::wasm::to_wasm::ToWasmStandardProperties;
#[derive(Debug, Serialize)]
#[serde(tag = "ast_node")]
#[serde(rename = "org-data")]
pub(crate) struct WasmFootnoteDefinition<'s> {
standard_properties: WasmStandardProperties,
children: Vec<()>,
phantom: PhantomData<&'s ()>,
}
to_wasm!(
WasmFootnoteDefinition<'s>,
FootnoteDefinition<'s>,
original,
wasm_context,
standard_properties,
{
Ok(WasmFootnoteDefinition {
standard_properties,
children: Vec::new(),
phantom: PhantomData,
})
}
);

View File

@@ -0,0 +1,34 @@
use std::marker::PhantomData;
use crate::types::FootnoteReference;
use serde::Deserialize;
use serde::Serialize;
use super::macros::to_wasm;
use super::standard_properties::WasmStandardProperties;
use super::to_wasm::ToWasm;
use crate::wasm::to_wasm::ToWasmStandardProperties;
#[derive(Debug, Serialize)]
#[serde(tag = "ast_node")]
#[serde(rename = "org-data")]
pub(crate) struct WasmFootnoteReference<'s> {
standard_properties: WasmStandardProperties,
children: Vec<()>,
phantom: PhantomData<&'s ()>,
}
to_wasm!(
WasmFootnoteReference<'s>,
FootnoteReference<'s>,
original,
wasm_context,
standard_properties,
{
Ok(WasmFootnoteReference {
standard_properties,
children: Vec::new(),
phantom: PhantomData,
})
}
);

40
src/wasm/headline.rs Normal file
View File

@@ -0,0 +1,40 @@
use std::marker::PhantomData;
use crate::types::Heading;
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::wasm::to_wasm::ToWasmStandardProperties;
#[derive(Debug, Serialize)]
#[serde(tag = "ast_node")]
#[serde(rename = "headline")]
pub(crate) struct WasmHeadline<'s> {
standard_properties: WasmStandardProperties,
children: Vec<()>,
phantom: PhantomData<&'s ()>,
}
to_wasm!(
WasmHeadline<'s>,
Heading<'s>,
original,
wasm_context,
standard_properties,
{
Ok(WasmHeadline {
standard_properties,
children: Vec::new(),
phantom: PhantomData,
})
}
);
impl<'s> Into<WasmAstNode<'s>> for WasmHeadline<'s> {
fn into(self) -> WasmAstNode<'s> {
WasmAstNode::Headline(self)
}
}

View File

@@ -0,0 +1,34 @@
use std::marker::PhantomData;
use crate::types::HorizontalRule;
use serde::Deserialize;
use serde::Serialize;
use super::macros::to_wasm;
use super::standard_properties::WasmStandardProperties;
use super::to_wasm::ToWasm;
use crate::wasm::to_wasm::ToWasmStandardProperties;
#[derive(Debug, Serialize)]
#[serde(tag = "ast_node")]
#[serde(rename = "org-data")]
pub(crate) struct WasmHorizontalRule<'s> {
standard_properties: WasmStandardProperties,
children: Vec<()>,
phantom: PhantomData<&'s ()>,
}
to_wasm!(
WasmHorizontalRule<'s>,
HorizontalRule<'s>,
original,
wasm_context,
standard_properties,
{
Ok(WasmHorizontalRule {
standard_properties,
children: Vec::new(),
phantom: PhantomData,
})
}
);

View File

@@ -0,0 +1,34 @@
use std::marker::PhantomData;
use crate::types::InlineBabelCall;
use serde::Deserialize;
use serde::Serialize;
use super::macros::to_wasm;
use super::standard_properties::WasmStandardProperties;
use super::to_wasm::ToWasm;
use crate::wasm::to_wasm::ToWasmStandardProperties;
#[derive(Debug, Serialize)]
#[serde(tag = "ast_node")]
#[serde(rename = "org-data")]
pub(crate) struct WasmInlineBabelCall<'s> {
standard_properties: WasmStandardProperties,
children: Vec<()>,
phantom: PhantomData<&'s ()>,
}
to_wasm!(
WasmInlineBabelCall<'s>,
InlineBabelCall<'s>,
original,
wasm_context,
standard_properties,
{
Ok(WasmInlineBabelCall {
standard_properties,
children: Vec::new(),
phantom: PhantomData,
})
}
);

View File

@@ -0,0 +1,34 @@
use std::marker::PhantomData;
use crate::types::InlineSourceBlock;
use serde::Deserialize;
use serde::Serialize;
use super::macros::to_wasm;
use super::standard_properties::WasmStandardProperties;
use super::to_wasm::ToWasm;
use crate::wasm::to_wasm::ToWasmStandardProperties;
#[derive(Debug, Serialize)]
#[serde(tag = "ast_node")]
#[serde(rename = "org-data")]
pub(crate) struct WasmInlineSourceBlock<'s> {
standard_properties: WasmStandardProperties,
children: Vec<()>,
phantom: PhantomData<&'s ()>,
}
to_wasm!(
WasmInlineSourceBlock<'s>,
InlineSourceBlock<'s>,
original,
wasm_context,
standard_properties,
{
Ok(WasmInlineSourceBlock {
standard_properties,
children: Vec::new(),
phantom: PhantomData,
})
}
);

34
src/wasm/italic.rs Normal file
View File

@@ -0,0 +1,34 @@
use std::marker::PhantomData;
use crate::types::Italic;
use serde::Deserialize;
use serde::Serialize;
use super::macros::to_wasm;
use super::standard_properties::WasmStandardProperties;
use super::to_wasm::ToWasm;
use crate::wasm::to_wasm::ToWasmStandardProperties;
#[derive(Debug, Serialize)]
#[serde(tag = "ast_node")]
#[serde(rename = "org-data")]
pub(crate) struct WasmItalic<'s> {
standard_properties: WasmStandardProperties,
children: Vec<()>,
phantom: PhantomData<&'s ()>,
}
to_wasm!(
WasmItalic<'s>,
Italic<'s>,
original,
wasm_context,
standard_properties,
{
Ok(WasmItalic {
standard_properties,
children: Vec::new(),
phantom: PhantomData,
})
}
);

34
src/wasm/keyword.rs Normal file
View File

@@ -0,0 +1,34 @@
use std::marker::PhantomData;
use crate::types::Keyword;
use serde::Deserialize;
use serde::Serialize;
use super::macros::to_wasm;
use super::standard_properties::WasmStandardProperties;
use super::to_wasm::ToWasm;
use crate::wasm::to_wasm::ToWasmStandardProperties;
#[derive(Debug, Serialize)]
#[serde(tag = "ast_node")]
#[serde(rename = "org-data")]
pub(crate) struct WasmKeyword<'s> {
standard_properties: WasmStandardProperties,
children: Vec<()>,
phantom: PhantomData<&'s ()>,
}
to_wasm!(
WasmKeyword<'s>,
Keyword<'s>,
original,
wasm_context,
standard_properties,
{
Ok(WasmKeyword {
standard_properties,
children: Vec::new(),
phantom: PhantomData,
})
}
);

View File

@@ -0,0 +1,34 @@
use std::marker::PhantomData;
use crate::types::LatexEnvironment;
use serde::Deserialize;
use serde::Serialize;
use super::macros::to_wasm;
use super::standard_properties::WasmStandardProperties;
use super::to_wasm::ToWasm;
use crate::wasm::to_wasm::ToWasmStandardProperties;
#[derive(Debug, Serialize)]
#[serde(tag = "ast_node")]
#[serde(rename = "org-data")]
pub(crate) struct WasmLatexEnvironment<'s> {
standard_properties: WasmStandardProperties,
children: Vec<()>,
phantom: PhantomData<&'s ()>,
}
to_wasm!(
WasmLatexEnvironment<'s>,
LatexEnvironment<'s>,
original,
wasm_context,
standard_properties,
{
Ok(WasmLatexEnvironment {
standard_properties,
children: Vec::new(),
phantom: PhantomData,
})
}
);

View File

@@ -0,0 +1,34 @@
use std::marker::PhantomData;
use crate::types::LatexFragment;
use serde::Deserialize;
use serde::Serialize;
use super::macros::to_wasm;
use super::standard_properties::WasmStandardProperties;
use super::to_wasm::ToWasm;
use crate::wasm::to_wasm::ToWasmStandardProperties;
#[derive(Debug, Serialize)]
#[serde(tag = "ast_node")]
#[serde(rename = "org-data")]
pub(crate) struct WasmLatexFragment<'s> {
standard_properties: WasmStandardProperties,
children: Vec<()>,
phantom: PhantomData<&'s ()>,
}
to_wasm!(
WasmLatexFragment<'s>,
LatexFragment<'s>,
original,
wasm_context,
standard_properties,
{
Ok(WasmLatexFragment {
standard_properties,
children: Vec::new(),
phantom: PhantomData,
})
}
);

34
src/wasm/line_break.rs Normal file
View File

@@ -0,0 +1,34 @@
use std::marker::PhantomData;
use crate::types::LineBreak;
use serde::Deserialize;
use serde::Serialize;
use super::macros::to_wasm;
use super::standard_properties::WasmStandardProperties;
use super::to_wasm::ToWasm;
use crate::wasm::to_wasm::ToWasmStandardProperties;
#[derive(Debug, Serialize)]
#[serde(tag = "ast_node")]
#[serde(rename = "org-data")]
pub(crate) struct WasmLineBreak<'s> {
standard_properties: WasmStandardProperties,
children: Vec<()>,
phantom: PhantomData<&'s ()>,
}
to_wasm!(
WasmLineBreak<'s>,
LineBreak<'s>,
original,
wasm_context,
standard_properties,
{
Ok(WasmLineBreak {
standard_properties,
children: Vec::new(),
phantom: PhantomData,
})
}
);

22
src/wasm/macros.rs Normal file
View File

@@ -0,0 +1,22 @@
/// Write the implementation for the intermediate ast node.
///
/// This exists to make changing the type signature easier.
macro_rules! to_wasm {
($ostruct:ty, $istruct:ty, $original:ident, $wasm_context:ident, $standard_properties:ident, $fnbody:tt) => {
impl<'s> ToWasm for $istruct {
type Output = $ostruct;
fn to_wasm(
&self,
$wasm_context: crate::wasm::to_wasm::ToWasmContext<'_>,
) -> Result<Self::Output, crate::error::CustomError> {
let $original = self;
let $standard_properties =
self.to_wasm_standard_properties($wasm_context.clone())?;
$fnbody
}
}
};
}
pub(crate) use to_wasm;

68
src/wasm/mod.rs Normal file
View File

@@ -0,0 +1,68 @@
mod angle_link;
mod ast_node;
mod babel_call;
mod bold;
mod center_block;
mod citation;
mod citation_reference;
mod clock;
mod code;
mod comment;
mod comment_block;
mod diary_sexp;
mod document;
mod drawer;
mod dynamic_block;
mod entity;
mod example_block;
mod export_block;
mod export_snippet;
mod fixed_width_area;
mod footnote_definition;
mod footnote_reference;
mod headline;
mod horizontal_rule;
mod inline_babel_call;
mod inline_source_block;
mod italic;
mod keyword;
mod latex_environment;
mod latex_fragment;
mod line_break;
mod macros;
mod node_property;
mod org_macro;
mod paragraph;
mod parse_result;
mod plain_link;
mod plain_list;
mod plain_list_item;
mod plain_text;
mod planning;
mod property_drawer;
mod quote_block;
mod radio_link;
mod radio_target;
mod regular_link;
mod section;
mod special_block;
mod src_block;
mod standard_properties;
mod statistics_cookie;
mod strike_through;
mod subscript;
mod superscript;
mod table;
mod table_cell;
mod table_row;
mod target;
mod timestamp;
mod to_wasm;
mod underline;
mod verbatim;
mod verse_block;
pub use parse_result::wasm_parse_org;
pub use parse_result::ParseResult;
pub(crate) use to_wasm::ToWasm;
pub(crate) use to_wasm::ToWasmContext;

34
src/wasm/node_property.rs Normal file
View File

@@ -0,0 +1,34 @@
use std::marker::PhantomData;
use crate::types::NodeProperty;
use serde::Deserialize;
use serde::Serialize;
use super::macros::to_wasm;
use super::standard_properties::WasmStandardProperties;
use super::to_wasm::ToWasm;
use crate::wasm::to_wasm::ToWasmStandardProperties;
#[derive(Debug, Serialize)]
#[serde(tag = "ast_node")]
#[serde(rename = "org-data")]
pub(crate) struct WasmNodeProperty<'s> {
standard_properties: WasmStandardProperties,
children: Vec<()>,
phantom: PhantomData<&'s ()>,
}
to_wasm!(
WasmNodeProperty<'s>,
NodeProperty<'s>,
original,
wasm_context,
standard_properties,
{
Ok(WasmNodeProperty {
standard_properties,
children: Vec::new(),
phantom: PhantomData,
})
}
);

34
src/wasm/org_macro.rs Normal file
View File

@@ -0,0 +1,34 @@
use std::marker::PhantomData;
use crate::types::OrgMacro;
use serde::Deserialize;
use serde::Serialize;
use super::macros::to_wasm;
use super::standard_properties::WasmStandardProperties;
use super::to_wasm::ToWasm;
use crate::wasm::to_wasm::ToWasmStandardProperties;
#[derive(Debug, Serialize)]
#[serde(tag = "ast_node")]
#[serde(rename = "org-data")]
pub(crate) struct WasmOrgMacro<'s> {
standard_properties: WasmStandardProperties,
children: Vec<()>,
phantom: PhantomData<&'s ()>,
}
to_wasm!(
WasmOrgMacro<'s>,
OrgMacro<'s>,
original,
wasm_context,
standard_properties,
{
Ok(WasmOrgMacro {
standard_properties,
children: Vec::new(),
phantom: PhantomData,
})
}
);

34
src/wasm/paragraph.rs Normal file
View File

@@ -0,0 +1,34 @@
use std::marker::PhantomData;
use crate::types::Paragraph;
use serde::Deserialize;
use serde::Serialize;
use super::macros::to_wasm;
use super::standard_properties::WasmStandardProperties;
use super::to_wasm::ToWasm;
use crate::wasm::to_wasm::ToWasmStandardProperties;
#[derive(Debug, Serialize)]
#[serde(tag = "ast_node")]
#[serde(rename = "org-data")]
pub(crate) struct WasmParagraph<'s> {
standard_properties: WasmStandardProperties,
children: Vec<()>,
phantom: PhantomData<&'s ()>,
}
to_wasm!(
WasmParagraph<'s>,
Paragraph<'s>,
original,
wasm_context,
standard_properties,
{
Ok(WasmParagraph {
standard_properties,
children: Vec::new(),
phantom: PhantomData,
})
}
);

32
src/wasm/parse_result.rs Normal file
View File

@@ -0,0 +1,32 @@
use serde::Serialize;
use super::document::WasmDocument;
use super::ToWasm;
use super::ToWasmContext;
use crate::parser::parse_with_settings;
use crate::settings::GlobalSettings;
#[derive(Debug, Serialize)]
#[serde(tag = "status", content = "content")]
pub enum ParseResult<'s> {
#[serde(rename = "success")]
Success(WasmDocument<'s>),
#[serde(rename = "error")]
Error(String),
}
pub 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
}

34
src/wasm/plain_link.rs Normal file
View File

@@ -0,0 +1,34 @@
use std::marker::PhantomData;
use crate::types::PlainLink;
use serde::Deserialize;
use serde::Serialize;
use super::macros::to_wasm;
use super::standard_properties::WasmStandardProperties;
use super::to_wasm::ToWasm;
use crate::wasm::to_wasm::ToWasmStandardProperties;
#[derive(Debug, Serialize)]
#[serde(tag = "ast_node")]
#[serde(rename = "org-data")]
pub(crate) struct WasmPlainLink<'s> {
standard_properties: WasmStandardProperties,
children: Vec<()>,
phantom: PhantomData<&'s ()>,
}
to_wasm!(
WasmPlainLink<'s>,
PlainLink<'s>,
original,
wasm_context,
standard_properties,
{
Ok(WasmPlainLink {
standard_properties,
children: Vec::new(),
phantom: PhantomData,
})
}
);

34
src/wasm/plain_list.rs Normal file
View File

@@ -0,0 +1,34 @@
use std::marker::PhantomData;
use crate::types::PlainList;
use serde::Deserialize;
use serde::Serialize;
use super::macros::to_wasm;
use super::standard_properties::WasmStandardProperties;
use super::to_wasm::ToWasm;
use crate::wasm::to_wasm::ToWasmStandardProperties;
#[derive(Debug, Serialize)]
#[serde(tag = "ast_node")]
#[serde(rename = "org-data")]
pub(crate) struct WasmPlainList<'s> {
standard_properties: WasmStandardProperties,
children: Vec<()>,
phantom: PhantomData<&'s ()>,
}
to_wasm!(
WasmPlainList<'s>,
PlainList<'s>,
original,
wasm_context,
standard_properties,
{
Ok(WasmPlainList {
standard_properties,
children: Vec::new(),
phantom: PhantomData,
})
}
);

View File

@@ -0,0 +1,34 @@
use std::marker::PhantomData;
use crate::types::PlainListItem;
use serde::Deserialize;
use serde::Serialize;
use super::macros::to_wasm;
use super::standard_properties::WasmStandardProperties;
use super::to_wasm::ToWasm;
use crate::wasm::to_wasm::ToWasmStandardProperties;
#[derive(Debug, Serialize)]
#[serde(tag = "ast_node")]
#[serde(rename = "org-data")]
pub(crate) struct WasmPlainListItem<'s> {
standard_properties: WasmStandardProperties,
children: Vec<()>,
phantom: PhantomData<&'s ()>,
}
to_wasm!(
WasmPlainListItem<'s>,
PlainListItem<'s>,
original,
wasm_context,
standard_properties,
{
Ok(WasmPlainListItem {
standard_properties,
children: Vec::new(),
phantom: PhantomData,
})
}
);

34
src/wasm/plain_text.rs Normal file
View File

@@ -0,0 +1,34 @@
use std::marker::PhantomData;
use crate::types::PlainText;
use serde::Deserialize;
use serde::Serialize;
use super::macros::to_wasm;
use super::standard_properties::WasmStandardProperties;
use super::to_wasm::ToWasm;
use crate::wasm::to_wasm::ToWasmStandardProperties;
#[derive(Debug, Serialize)]
#[serde(tag = "ast_node")]
#[serde(rename = "org-data")]
pub(crate) struct WasmPlainText<'s> {
standard_properties: WasmStandardProperties,
children: Vec<()>,
phantom: PhantomData<&'s ()>,
}
to_wasm!(
WasmPlainText<'s>,
PlainText<'s>,
original,
wasm_context,
standard_properties,
{
Ok(WasmPlainText {
standard_properties,
children: Vec::new(),
phantom: PhantomData,
})
}
);

34
src/wasm/planning.rs Normal file
View File

@@ -0,0 +1,34 @@
use std::marker::PhantomData;
use crate::types::Planning;
use serde::Deserialize;
use serde::Serialize;
use super::macros::to_wasm;
use super::standard_properties::WasmStandardProperties;
use super::to_wasm::ToWasm;
use crate::wasm::to_wasm::ToWasmStandardProperties;
#[derive(Debug, Serialize)]
#[serde(tag = "ast_node")]
#[serde(rename = "org-data")]
pub(crate) struct WasmPlanning<'s> {
standard_properties: WasmStandardProperties,
children: Vec<()>,
phantom: PhantomData<&'s ()>,
}
to_wasm!(
WasmPlanning<'s>,
Planning<'s>,
original,
wasm_context,
standard_properties,
{
Ok(WasmPlanning {
standard_properties,
children: Vec::new(),
phantom: PhantomData,
})
}
);

View File

@@ -0,0 +1,34 @@
use std::marker::PhantomData;
use crate::types::PropertyDrawer;
use serde::Deserialize;
use serde::Serialize;
use super::macros::to_wasm;
use super::standard_properties::WasmStandardProperties;
use super::to_wasm::ToWasm;
use crate::wasm::to_wasm::ToWasmStandardProperties;
#[derive(Debug, Serialize)]
#[serde(tag = "ast_node")]
#[serde(rename = "org-data")]
pub(crate) struct WasmPropertyDrawer<'s> {
standard_properties: WasmStandardProperties,
children: Vec<()>,
phantom: PhantomData<&'s ()>,
}
to_wasm!(
WasmPropertyDrawer<'s>,
PropertyDrawer<'s>,
original,
wasm_context,
standard_properties,
{
Ok(WasmPropertyDrawer {
standard_properties,
children: Vec::new(),
phantom: PhantomData,
})
}
);

34
src/wasm/quote_block.rs Normal file
View File

@@ -0,0 +1,34 @@
use std::marker::PhantomData;
use crate::types::QuoteBlock;
use serde::Deserialize;
use serde::Serialize;
use super::macros::to_wasm;
use super::standard_properties::WasmStandardProperties;
use super::to_wasm::ToWasm;
use crate::wasm::to_wasm::ToWasmStandardProperties;
#[derive(Debug, Serialize)]
#[serde(tag = "ast_node")]
#[serde(rename = "org-data")]
pub(crate) struct WasmQuoteBlock<'s> {
standard_properties: WasmStandardProperties,
children: Vec<()>,
phantom: PhantomData<&'s ()>,
}
to_wasm!(
WasmQuoteBlock<'s>,
QuoteBlock<'s>,
original,
wasm_context,
standard_properties,
{
Ok(WasmQuoteBlock {
standard_properties,
children: Vec::new(),
phantom: PhantomData,
})
}
);

34
src/wasm/radio_link.rs Normal file
View File

@@ -0,0 +1,34 @@
use std::marker::PhantomData;
use crate::types::RadioLink;
use serde::Deserialize;
use serde::Serialize;
use super::macros::to_wasm;
use super::standard_properties::WasmStandardProperties;
use super::to_wasm::ToWasm;
use crate::wasm::to_wasm::ToWasmStandardProperties;
#[derive(Debug, Serialize)]
#[serde(tag = "ast_node")]
#[serde(rename = "org-data")]
pub(crate) struct WasmRadioLink<'s> {
standard_properties: WasmStandardProperties,
children: Vec<()>,
phantom: PhantomData<&'s ()>,
}
to_wasm!(
WasmRadioLink<'s>,
RadioLink<'s>,
original,
wasm_context,
standard_properties,
{
Ok(WasmRadioLink {
standard_properties,
children: Vec::new(),
phantom: PhantomData,
})
}
);

34
src/wasm/radio_target.rs Normal file
View File

@@ -0,0 +1,34 @@
use std::marker::PhantomData;
use crate::types::RadioTarget;
use serde::Deserialize;
use serde::Serialize;
use super::macros::to_wasm;
use super::standard_properties::WasmStandardProperties;
use super::to_wasm::ToWasm;
use crate::wasm::to_wasm::ToWasmStandardProperties;
#[derive(Debug, Serialize)]
#[serde(tag = "ast_node")]
#[serde(rename = "org-data")]
pub(crate) struct WasmRadioTarget<'s> {
standard_properties: WasmStandardProperties,
children: Vec<()>,
phantom: PhantomData<&'s ()>,
}
to_wasm!(
WasmRadioTarget<'s>,
RadioTarget<'s>,
original,
wasm_context,
standard_properties,
{
Ok(WasmRadioTarget {
standard_properties,
children: Vec::new(),
phantom: PhantomData,
})
}
);

34
src/wasm/regular_link.rs Normal file
View File

@@ -0,0 +1,34 @@
use std::marker::PhantomData;
use crate::types::RegularLink;
use serde::Deserialize;
use serde::Serialize;
use super::macros::to_wasm;
use super::standard_properties::WasmStandardProperties;
use super::to_wasm::ToWasm;
use crate::wasm::to_wasm::ToWasmStandardProperties;
#[derive(Debug, Serialize)]
#[serde(tag = "ast_node")]
#[serde(rename = "org-data")]
pub(crate) struct WasmRegularLink<'s> {
standard_properties: WasmStandardProperties,
children: Vec<()>,
phantom: PhantomData<&'s ()>,
}
to_wasm!(
WasmRegularLink<'s>,
RegularLink<'s>,
original,
wasm_context,
standard_properties,
{
Ok(WasmRegularLink {
standard_properties,
children: Vec::new(),
phantom: PhantomData,
})
}
);

40
src/wasm/section.rs Normal file
View File

@@ -0,0 +1,40 @@
use std::marker::PhantomData;
use crate::types::Section;
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::wasm::to_wasm::ToWasmStandardProperties;
#[derive(Debug, Serialize)]
#[serde(tag = "ast_node")]
#[serde(rename = "section")]
pub(crate) struct WasmSection<'s> {
standard_properties: WasmStandardProperties,
children: Vec<()>,
phantom: PhantomData<&'s ()>,
}
to_wasm!(
WasmSection<'s>,
Section<'s>,
original,
wasm_context,
standard_properties,
{
Ok(WasmSection {
standard_properties,
children: Vec::new(),
phantom: PhantomData,
})
}
);
impl<'s> Into<WasmAstNode<'s>> for WasmSection<'s> {
fn into(self) -> WasmAstNode<'s> {
WasmAstNode::Section(self)
}
}

34
src/wasm/special_block.rs Normal file
View File

@@ -0,0 +1,34 @@
use std::marker::PhantomData;
use crate::types::SpecialBlock;
use serde::Deserialize;
use serde::Serialize;
use super::macros::to_wasm;
use super::standard_properties::WasmStandardProperties;
use super::to_wasm::ToWasm;
use crate::wasm::to_wasm::ToWasmStandardProperties;
#[derive(Debug, Serialize)]
#[serde(tag = "ast_node")]
#[serde(rename = "org-data")]
pub(crate) struct WasmSpecialBlock<'s> {
standard_properties: WasmStandardProperties,
children: Vec<()>,
phantom: PhantomData<&'s ()>,
}
to_wasm!(
WasmSpecialBlock<'s>,
SpecialBlock<'s>,
original,
wasm_context,
standard_properties,
{
Ok(WasmSpecialBlock {
standard_properties,
children: Vec::new(),
phantom: PhantomData,
})
}
);

34
src/wasm/src_block.rs Normal file
View File

@@ -0,0 +1,34 @@
use std::marker::PhantomData;
use crate::types::SrcBlock;
use serde::Deserialize;
use serde::Serialize;
use super::macros::to_wasm;
use super::standard_properties::WasmStandardProperties;
use super::to_wasm::ToWasm;
use crate::wasm::to_wasm::ToWasmStandardProperties;
#[derive(Debug, Serialize)]
#[serde(tag = "ast_node")]
#[serde(rename = "org-data")]
pub(crate) struct WasmSrcBlock<'s> {
standard_properties: WasmStandardProperties,
children: Vec<()>,
phantom: PhantomData<&'s ()>,
}
to_wasm!(
WasmSrcBlock<'s>,
SrcBlock<'s>,
original,
wasm_context,
standard_properties,
{
Ok(WasmSrcBlock {
standard_properties,
children: Vec::new(),
phantom: PhantomData,
})
}
);

View File

@@ -0,0 +1,71 @@
use crate::types::PostBlank;
use crate::types::StandardProperties;
use serde::Deserialize;
use serde::Serialize;
use super::to_wasm::ToWasmContext;
use super::to_wasm::ToWasmStandardProperties;
#[derive(Debug, Serialize)]
pub(crate) struct WasmStandardProperties {
begin: usize,
end: usize,
contents_begin: Option<usize>,
contents_end: Option<usize>,
post_blank: PostBlank,
}
impl<'s, SP: StandardProperties<'s>> ToWasmStandardProperties for SP {
type Output = WasmStandardProperties;
fn to_wasm_standard_properties(
&self,
wasm_context: ToWasmContext<'_>,
) -> Result<Self::Output, crate::error::CustomError> {
let (begin, end) = get_char_indices(wasm_context.full_document, self.get_source());
let (contents_begin, contents_end) = match self.get_contents() {
Some(contents) => {
let (begin, end) = get_char_indices(wasm_context.full_document, contents);
(Some(begin), Some(end))
}
None => (None, None),
};
let post_blank = self.get_post_blank();
Ok(WasmStandardProperties {
begin,
end,
contents_begin,
contents_end,
post_blank,
})
}
}
fn get_char_indices(original_document: &str, subset: &str) -> (usize, usize) {
let (begin_byte, end_byte) = get_rust_byte_offsets(original_document, subset);
// Add 1 to make this 1-based to match emacs.
let begin_char = original_document[..begin_byte].chars().count() + 1;
// Also 1-based:
let end_char = begin_char + original_document[begin_byte..end_byte].chars().count();
(begin_char, end_char)
}
/// Get the byte offset into source that the string slice exists at.
///
/// These offsets are zero-based.
fn get_rust_byte_offsets(original_document: &str, subset: &str) -> (usize, usize) {
debug_assert!(is_slice_of(original_document, subset));
let offset = subset.as_ptr() as usize - original_document.as_ptr() as usize;
let end = offset + subset.len();
(offset, end)
}
/// Check if the child string slice is a slice of the parent string slice.
fn is_slice_of(parent: &str, child: &str) -> bool {
let parent_start = parent.as_ptr() as usize;
let parent_end = parent_start + parent.len();
let child_start = child.as_ptr() as usize;
let child_end = child_start + child.len();
child_start >= parent_start && child_end <= parent_end
}

View File

@@ -0,0 +1,34 @@
use std::marker::PhantomData;
use crate::types::StatisticsCookie;
use serde::Deserialize;
use serde::Serialize;
use super::macros::to_wasm;
use super::standard_properties::WasmStandardProperties;
use super::to_wasm::ToWasm;
use crate::wasm::to_wasm::ToWasmStandardProperties;
#[derive(Debug, Serialize)]
#[serde(tag = "ast_node")]
#[serde(rename = "org-data")]
pub(crate) struct WasmStatisticsCookie<'s> {
standard_properties: WasmStandardProperties,
children: Vec<()>,
phantom: PhantomData<&'s ()>,
}
to_wasm!(
WasmStatisticsCookie<'s>,
StatisticsCookie<'s>,
original,
wasm_context,
standard_properties,
{
Ok(WasmStatisticsCookie {
standard_properties,
children: Vec::new(),
phantom: PhantomData,
})
}
);

View File

@@ -0,0 +1,34 @@
use std::marker::PhantomData;
use crate::types::StrikeThrough;
use serde::Deserialize;
use serde::Serialize;
use super::macros::to_wasm;
use super::standard_properties::WasmStandardProperties;
use super::to_wasm::ToWasm;
use crate::wasm::to_wasm::ToWasmStandardProperties;
#[derive(Debug, Serialize)]
#[serde(tag = "ast_node")]
#[serde(rename = "org-data")]
pub(crate) struct WasmStrikeThrough<'s> {
standard_properties: WasmStandardProperties,
children: Vec<()>,
phantom: PhantomData<&'s ()>,
}
to_wasm!(
WasmStrikeThrough<'s>,
StrikeThrough<'s>,
original,
wasm_context,
standard_properties,
{
Ok(WasmStrikeThrough {
standard_properties,
children: Vec::new(),
phantom: PhantomData,
})
}
);

34
src/wasm/subscript.rs Normal file
View File

@@ -0,0 +1,34 @@
use std::marker::PhantomData;
use crate::types::Subscript;
use serde::Deserialize;
use serde::Serialize;
use super::macros::to_wasm;
use super::standard_properties::WasmStandardProperties;
use super::to_wasm::ToWasm;
use crate::wasm::to_wasm::ToWasmStandardProperties;
#[derive(Debug, Serialize)]
#[serde(tag = "ast_node")]
#[serde(rename = "org-data")]
pub(crate) struct WasmSubscript<'s> {
standard_properties: WasmStandardProperties,
children: Vec<()>,
phantom: PhantomData<&'s ()>,
}
to_wasm!(
WasmSubscript<'s>,
Subscript<'s>,
original,
wasm_context,
standard_properties,
{
Ok(WasmSubscript {
standard_properties,
children: Vec::new(),
phantom: PhantomData,
})
}
);

34
src/wasm/superscript.rs Normal file
View File

@@ -0,0 +1,34 @@
use std::marker::PhantomData;
use crate::types::Superscript;
use serde::Deserialize;
use serde::Serialize;
use super::macros::to_wasm;
use super::standard_properties::WasmStandardProperties;
use super::to_wasm::ToWasm;
use crate::wasm::to_wasm::ToWasmStandardProperties;
#[derive(Debug, Serialize)]
#[serde(tag = "ast_node")]
#[serde(rename = "org-data")]
pub(crate) struct WasmSuperscript<'s> {
standard_properties: WasmStandardProperties,
children: Vec<()>,
phantom: PhantomData<&'s ()>,
}
to_wasm!(
WasmSuperscript<'s>,
Superscript<'s>,
original,
wasm_context,
standard_properties,
{
Ok(WasmSuperscript {
standard_properties,
children: Vec::new(),
phantom: PhantomData,
})
}
);

34
src/wasm/table.rs Normal file
View File

@@ -0,0 +1,34 @@
use std::marker::PhantomData;
use crate::types::Table;
use serde::Deserialize;
use serde::Serialize;
use super::macros::to_wasm;
use super::standard_properties::WasmStandardProperties;
use super::to_wasm::ToWasm;
use crate::wasm::to_wasm::ToWasmStandardProperties;
#[derive(Debug, Serialize)]
#[serde(tag = "ast_node")]
#[serde(rename = "org-data")]
pub(crate) struct WasmTable<'s> {
standard_properties: WasmStandardProperties,
children: Vec<()>,
phantom: PhantomData<&'s ()>,
}
to_wasm!(
WasmTable<'s>,
Table<'s>,
original,
wasm_context,
standard_properties,
{
Ok(WasmTable {
standard_properties,
children: Vec::new(),
phantom: PhantomData,
})
}
);

34
src/wasm/table_cell.rs Normal file
View File

@@ -0,0 +1,34 @@
use std::marker::PhantomData;
use crate::types::TableCell;
use serde::Deserialize;
use serde::Serialize;
use super::macros::to_wasm;
use super::standard_properties::WasmStandardProperties;
use super::to_wasm::ToWasm;
use crate::wasm::to_wasm::ToWasmStandardProperties;
#[derive(Debug, Serialize)]
#[serde(tag = "ast_node")]
#[serde(rename = "org-data")]
pub(crate) struct WasmTableCell<'s> {
standard_properties: WasmStandardProperties,
children: Vec<()>,
phantom: PhantomData<&'s ()>,
}
to_wasm!(
WasmTableCell<'s>,
TableCell<'s>,
original,
wasm_context,
standard_properties,
{
Ok(WasmTableCell {
standard_properties,
children: Vec::new(),
phantom: PhantomData,
})
}
);

34
src/wasm/table_row.rs Normal file
View File

@@ -0,0 +1,34 @@
use std::marker::PhantomData;
use crate::types::TableRow;
use serde::Deserialize;
use serde::Serialize;
use super::macros::to_wasm;
use super::standard_properties::WasmStandardProperties;
use super::to_wasm::ToWasm;
use crate::wasm::to_wasm::ToWasmStandardProperties;
#[derive(Debug, Serialize)]
#[serde(tag = "ast_node")]
#[serde(rename = "org-data")]
pub(crate) struct WasmTableRow<'s> {
standard_properties: WasmStandardProperties,
children: Vec<()>,
phantom: PhantomData<&'s ()>,
}
to_wasm!(
WasmTableRow<'s>,
TableRow<'s>,
original,
wasm_context,
standard_properties,
{
Ok(WasmTableRow {
standard_properties,
children: Vec::new(),
phantom: PhantomData,
})
}
);

34
src/wasm/target.rs Normal file
View File

@@ -0,0 +1,34 @@
use std::marker::PhantomData;
use crate::types::Target;
use serde::Deserialize;
use serde::Serialize;
use super::macros::to_wasm;
use super::standard_properties::WasmStandardProperties;
use super::to_wasm::ToWasm;
use crate::wasm::to_wasm::ToWasmStandardProperties;
#[derive(Debug, Serialize)]
#[serde(tag = "ast_node")]
#[serde(rename = "org-data")]
pub(crate) struct WasmTarget<'s> {
standard_properties: WasmStandardProperties,
children: Vec<()>,
phantom: PhantomData<&'s ()>,
}
to_wasm!(
WasmTarget<'s>,
Target<'s>,
original,
wasm_context,
standard_properties,
{
Ok(WasmTarget {
standard_properties,
children: Vec::new(),
phantom: PhantomData,
})
}
);

34
src/wasm/timestamp.rs Normal file
View File

@@ -0,0 +1,34 @@
use std::marker::PhantomData;
use crate::types::Timestamp;
use serde::Deserialize;
use serde::Serialize;
use super::macros::to_wasm;
use super::standard_properties::WasmStandardProperties;
use super::to_wasm::ToWasm;
use crate::wasm::to_wasm::ToWasmStandardProperties;
#[derive(Debug, Serialize)]
#[serde(tag = "ast_node")]
#[serde(rename = "org-data")]
pub(crate) struct WasmTimestamp<'s> {
standard_properties: WasmStandardProperties,
children: Vec<()>,
phantom: PhantomData<&'s ()>,
}
to_wasm!(
WasmTimestamp<'s>,
Timestamp<'s>,
original,
wasm_context,
standard_properties,
{
Ok(WasmTimestamp {
standard_properties,
children: Vec::new(),
phantom: PhantomData,
})
}
);

27
src/wasm/to_wasm.rs Normal file
View File

@@ -0,0 +1,27 @@
use crate::error::CustomError;
pub(crate) trait ToWasm {
type Output;
fn to_wasm(&self, full_document: ToWasmContext<'_>) -> Result<Self::Output, CustomError>;
}
pub(crate) trait ToWasmStandardProperties {
type Output;
fn to_wasm_standard_properties(
&self,
wasm_context: ToWasmContext<'_>,
) -> Result<Self::Output, CustomError>;
}
#[derive(Debug, Clone)]
pub(crate) struct ToWasmContext<'s> {
pub(crate) full_document: &'s str,
}
impl<'s> ToWasmContext<'s> {
pub(crate) fn new(full_document: &'s str) -> ToWasmContext<'s> {
ToWasmContext { full_document }
}
}

34
src/wasm/underline.rs Normal file
View File

@@ -0,0 +1,34 @@
use std::marker::PhantomData;
use crate::types::Underline;
use serde::Deserialize;
use serde::Serialize;
use super::macros::to_wasm;
use super::standard_properties::WasmStandardProperties;
use super::to_wasm::ToWasm;
use crate::wasm::to_wasm::ToWasmStandardProperties;
#[derive(Debug, Serialize)]
#[serde(tag = "ast_node")]
#[serde(rename = "org-data")]
pub(crate) struct WasmUnderline<'s> {
standard_properties: WasmStandardProperties,
children: Vec<()>,
phantom: PhantomData<&'s ()>,
}
to_wasm!(
WasmUnderline<'s>,
Underline<'s>,
original,
wasm_context,
standard_properties,
{
Ok(WasmUnderline {
standard_properties,
children: Vec::new(),
phantom: PhantomData,
})
}
);

34
src/wasm/verbatim.rs Normal file
View File

@@ -0,0 +1,34 @@
use std::marker::PhantomData;
use crate::types::Verbatim;
use serde::Deserialize;
use serde::Serialize;
use super::macros::to_wasm;
use super::standard_properties::WasmStandardProperties;
use super::to_wasm::ToWasm;
use crate::wasm::to_wasm::ToWasmStandardProperties;
#[derive(Debug, Serialize)]
#[serde(tag = "ast_node")]
#[serde(rename = "org-data")]
pub(crate) struct WasmVerbatim<'s> {
standard_properties: WasmStandardProperties,
children: Vec<()>,
phantom: PhantomData<&'s ()>,
}
to_wasm!(
WasmVerbatim<'s>,
Verbatim<'s>,
original,
wasm_context,
standard_properties,
{
Ok(WasmVerbatim {
standard_properties,
children: Vec::new(),
phantom: PhantomData,
})
}
);

34
src/wasm/verse_block.rs Normal file
View File

@@ -0,0 +1,34 @@
use std::marker::PhantomData;
use crate::types::VerseBlock;
use serde::Deserialize;
use serde::Serialize;
use super::macros::to_wasm;
use super::standard_properties::WasmStandardProperties;
use super::to_wasm::ToWasm;
use crate::wasm::to_wasm::ToWasmStandardProperties;
#[derive(Debug, Serialize)]
#[serde(tag = "ast_node")]
#[serde(rename = "org-data")]
pub(crate) struct WasmVerseBlock<'s> {
standard_properties: WasmStandardProperties,
children: Vec<()>,
phantom: PhantomData<&'s ()>,
}
to_wasm!(
WasmVerseBlock<'s>,
VerseBlock<'s>,
original,
wasm_context,
standard_properties,
{
Ok(WasmVerseBlock {
standard_properties,
children: Vec::new(),
phantom: PhantomData,
})
}
);

4
src/wasm_test/mod.rs Normal file
View File

@@ -0,0 +1,4 @@
mod runner;
pub use runner::wasm_run_anonymous_compare;
pub use runner::wasm_run_anonymous_compare_with_settings;

60
src/wasm_test/runner.rs Normal file
View File

@@ -0,0 +1,60 @@
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;
pub async fn wasm_run_anonymous_compare<P: AsRef<str>>(
org_contents: P,
) -> Result<bool, Box<dyn std::error::Error>> {
wasm_run_anonymous_compare_with_settings(org_contents, &GlobalSettings::default(), false).await
}
pub async fn wasm_run_anonymous_compare_with_settings<'g, 's, P: AsRef<str>>(
org_contents: P,
global_settings: &GlobalSettings<'g, 's>,
silent: bool,
) -> Result<bool, Box<dyn std::error::Error>> {
// TODO: This is a work-around to pretend that dos line endings do not exist. It would be better to handle the difference in line endings.
let org_contents = org_contents.as_ref().replace("\r\n", "\n");
let org_contents = org_contents.as_str();
if !silent {
print_versions().await?;
}
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 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())?;
if !silent {
println!("{}\n\n\n", org_contents);
println!("{}", org_sexp);
println!("{:#?}", rust_parsed);
println!("{}", serde_json::to_string(&wasm_parsed)?);
}
// We do the diffing after printing out both parsed forms in case the diffing panics
// let diff_result = compare_document(&parsed_sexp, &rust_parsed)?;
// if !silent {
// diff_result.print(org_contents)?;
// }
// if diff_result.is_bad() {
// return Ok(false);
// } else if !silent {
// println!(
// "{color}Entire document passes.{reset}",
// color = DiffResult::foreground_color(0, 255, 0),
// reset = DiffResult::reset_color(),
// );
// }
Ok(true)
}