Compare commits
59 Commits
v0.1.13
...
eff5cdbf40
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
eff5cdbf40 | ||
|
|
eef3571299 | ||
|
|
f227d8405e | ||
|
|
9520e5814b | ||
|
|
28ad4fd046 | ||
|
|
7626a69fa1 | ||
|
|
121c0ce516 | ||
|
|
5a64db98fe | ||
|
|
abfae9c6c0 | ||
|
|
5272e2f1b4 | ||
|
|
90d4b11922 | ||
|
|
d552ef6569 | ||
|
|
f050e9b6a8 | ||
|
|
a5e108bc37 | ||
|
|
58290515b5 | ||
|
|
423f65046e | ||
|
|
badeaf8246 | ||
|
|
d38100581c | ||
|
|
f4eff5ca56 | ||
|
|
5b02c21ebf | ||
|
|
5f1668702a | ||
|
|
1faaeeebf1 | ||
|
|
20a7c89084 | ||
|
|
e83417b243 | ||
|
|
36b80dc093 | ||
|
|
1812b1a56e | ||
|
|
1a70b3d2c0 | ||
|
|
abf066701e | ||
|
|
4984ea4179 | ||
|
|
3cb251ea6c | ||
|
|
4bfea41291 | ||
|
|
99376515ef | ||
|
|
23f4ba4205 | ||
|
|
55ad136283 | ||
|
|
c717541099 | ||
|
|
c2e921c2dc | ||
|
|
e499169f0e | ||
|
|
84c088df67 | ||
|
|
f210f95f99 | ||
|
|
17b81c7c72 | ||
|
|
2911fce7cc | ||
|
|
e622d9fa6b | ||
|
|
8186fbb8b3 | ||
|
|
68ccff74fa | ||
|
|
9a13cb72c6 | ||
|
|
65abaa332f | ||
|
|
67e5829fd9 | ||
|
|
995b41e697 | ||
|
|
eb51bdfe2f | ||
|
|
bbb9ec637a | ||
|
|
dc012b49f5 | ||
|
|
13863a68f7 | ||
|
|
2962f76c81 | ||
|
|
b9b3ef6e74 | ||
|
|
310ab2eab2 | ||
|
|
53320070da | ||
|
|
2d5593681f | ||
|
|
b3f97dbb40 | ||
|
|
a48d76321e |
@@ -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:
|
||||||
|
|||||||
21
Cargo.toml
21
Cargo.toml
@@ -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
|
||||||
|
|||||||
9
Makefile
9
Makefile
@@ -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
|
||||||
|
|
||||||
.PHONY: clean
|
.PHONY: clean
|
||||||
clean:
|
clean:
|
||||||
> cargo clean
|
> cargo clean
|
||||||
|
|||||||
@@ -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"]
|
||||||
|
|||||||
76
scripts/build_all_feature_flag_combinations.bash
Executable file
76
scripts/build_all_feature_flag_combinations.bash
Executable 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 "${@}"
|
||||||
111
scripts/run_docker_wasm_compare.bash
Executable file
111
scripts/run_docker_wasm_compare.bash
Executable file
@@ -0,0 +1,111 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
#
|
||||||
|
set -euo pipefail
|
||||||
|
IFS=$'\n\t'
|
||||||
|
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||||
|
|
||||||
|
: ${SHELL:="NO"} # or YES to launch a shell instead of running the test
|
||||||
|
: ${TRACE:="NO"} # or YES to send traces to jaeger
|
||||||
|
: ${BACKTRACE:="NO"} # or YES to print a rust backtrace when panicking
|
||||||
|
: ${NO_COLOR:=""} # Set to anything to disable color output
|
||||||
|
: ${PROFILE:="debug"}
|
||||||
|
|
||||||
|
REALPATH=$(command -v uu-realpath || command -v realpath)
|
||||||
|
MAKE=$(command -v gmake || command -v make)
|
||||||
|
|
||||||
|
############## Setup #########################
|
||||||
|
|
||||||
|
function die {
|
||||||
|
local status_code="$1"
|
||||||
|
shift
|
||||||
|
(>&2 echo "${@}")
|
||||||
|
exit "$status_code"
|
||||||
|
}
|
||||||
|
|
||||||
|
function log {
|
||||||
|
(>&2 echo "${@}")
|
||||||
|
}
|
||||||
|
|
||||||
|
############## Program #########################
|
||||||
|
|
||||||
|
function main {
|
||||||
|
build_container
|
||||||
|
launch_container "${@}"
|
||||||
|
}
|
||||||
|
|
||||||
|
function build_container {
|
||||||
|
$MAKE -C "$DIR/../docker/organic_test"
|
||||||
|
}
|
||||||
|
|
||||||
|
function launch_container {
|
||||||
|
local additional_flags=()
|
||||||
|
local features=(wasm_test)
|
||||||
|
|
||||||
|
if [ "$NO_COLOR" != "" ]; then
|
||||||
|
additional_flags+=(--env "NO_COLOR=$NO_COLOR")
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ "$TRACE" = "YES" ]; then
|
||||||
|
# We use the host network so it can talk to jaeger hosted at 127.0.0.1
|
||||||
|
additional_flags+=(--network=host --env RUST_LOG=debug)
|
||||||
|
features+=(tracing)
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ "$SHELL" != "YES" ]; then
|
||||||
|
additional_flags+=(--read-only)
|
||||||
|
else
|
||||||
|
additional_flags+=(-t)
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ "$BACKTRACE" = "YES" ]; then
|
||||||
|
additional_flags+=(--env RUST_BACKTRACE=full)
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ "$SHELL" = "YES" ]; then
|
||||||
|
exec docker run "${additional_flags[@]}" --init --rm -i --mount type=tmpfs,destination=/tmp -v "/:/input:ro" -v "$($REALPATH "$DIR/../"):/source:ro" --mount source=cargo-cache,target=/usr/local/cargo/registry --mount source=rust-cache,target=/target --env CARGO_TARGET_DIR=/target -w /source --entrypoint "" organic-test /bin/sh
|
||||||
|
fi
|
||||||
|
|
||||||
|
local features_joined
|
||||||
|
features_joined=$(IFS=","; echo "${features[*]}")
|
||||||
|
|
||||||
|
local build_flags=()
|
||||||
|
if [ "$PROFILE" = "dev" ] || [ "$PROFILE" = "debug" ]; then
|
||||||
|
PROFILE="debug"
|
||||||
|
else
|
||||||
|
build_flags+=(--profile "$PROFILE")
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
if [ $# -gt 0 ]; then
|
||||||
|
# If we passed in args, we need to forward them along
|
||||||
|
for path in "${@}"; do
|
||||||
|
local full_path
|
||||||
|
full_path=$($REALPATH "$path")
|
||||||
|
init_script=$(cat <<EOF
|
||||||
|
set -euo pipefail
|
||||||
|
IFS=\$'\n\t'
|
||||||
|
|
||||||
|
cargo build --bin wasm_test --no-default-features --features "$features_joined" ${build_flags[@]}
|
||||||
|
exec /target/${PROFILE}/wasm_test "/input${full_path}"
|
||||||
|
EOF
|
||||||
|
)
|
||||||
|
docker run "${additional_flags[@]}" --init --rm -i --mount type=tmpfs,destination=/tmp -v "/:/input:ro" -v "$($REALPATH "$DIR/../"):/source:ro" --mount source=cargo-cache,target=/usr/local/cargo/registry --mount source=rust-cache,target=/target --env CARGO_TARGET_DIR=/target -w /source --entrypoint "" organic-test sh -c "$init_script"
|
||||||
|
done
|
||||||
|
else
|
||||||
|
local current_directory init_script
|
||||||
|
current_directory=$(pwd)
|
||||||
|
init_script=$(cat <<EOF
|
||||||
|
set -euo pipefail
|
||||||
|
IFS=\$'\n\t'
|
||||||
|
|
||||||
|
cargo build --bin wasm_test --no-default-features --features "$features_joined" ${build_flags[@]}
|
||||||
|
cd /input${current_directory}
|
||||||
|
exec /target/${PROFILE}/wasm_test
|
||||||
|
EOF
|
||||||
|
)
|
||||||
|
|
||||||
|
docker run "${additional_flags[@]}" --init --rm -i --mount type=tmpfs,destination=/tmp -v "/:/input:ro" -v "$($REALPATH "$DIR/../"):/source:ro" --mount source=cargo-cache,target=/usr/local/cargo/registry --mount source=rust-cache,target=/target --env CARGO_TARGET_DIR=/target -w /source --entrypoint "" organic-test sh -c "$init_script"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
main "${@}"
|
||||||
@@ -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;
|
||||||
|
|||||||
30
src/bin_wasm.rs
Normal file
30
src/bin_wasm.rs
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
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()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
62
src/bin_wasm_test.rs
Normal file
62
src/bin_wasm_test.rs
Normal 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;
|
||||||
|
use organic::wasm_test::wasm_run_compare_on_file;
|
||||||
|
|
||||||
|
#[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 {
|
||||||
|
for arg in args {
|
||||||
|
if wasm_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)
|
||||||
|
}
|
||||||
@@ -2,15 +2,16 @@ 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::foreground_color;
|
||||||
|
use crate::util::print_versions;
|
||||||
|
use crate::util::reset_color;
|
||||||
|
|
||||||
pub async fn run_anonymous_compare<P: AsRef<str>>(
|
pub async fn run_anonymous_compare<P: AsRef<str>>(
|
||||||
org_contents: P,
|
org_contents: P,
|
||||||
@@ -68,8 +69,8 @@ pub async fn run_anonymous_compare_with_settings<'g, 's, P: AsRef<str>>(
|
|||||||
} else if !silent {
|
} else if !silent {
|
||||||
println!(
|
println!(
|
||||||
"{color}Entire document passes.{reset}",
|
"{color}Entire document passes.{reset}",
|
||||||
color = DiffResult::foreground_color(0, 255, 0),
|
color = foreground_color(0, 255, 0),
|
||||||
reset = DiffResult::reset_color(),
|
reset = reset_color(),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -121,19 +122,10 @@ pub async fn run_compare_on_file_with_settings<'g, 's, P: AsRef<Path>>(
|
|||||||
} else if !silent {
|
} else if !silent {
|
||||||
println!(
|
println!(
|
||||||
"{color}Entire document passes.{reset}",
|
"{color}Entire document passes.{reset}",
|
||||||
color = DiffResult::foreground_color(0, 255, 0),
|
color = foreground_color(0, 255, 0),
|
||||||
reset = DiffResult::reset_color(),
|
reset = reset_color(),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
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(())
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -109,6 +109,8 @@ use crate::types::Verbatim;
|
|||||||
use crate::types::VerseBlock;
|
use crate::types::VerseBlock;
|
||||||
use crate::types::WarningDelayType;
|
use crate::types::WarningDelayType;
|
||||||
use crate::types::Year;
|
use crate::types::Year;
|
||||||
|
use crate::util::foreground_color;
|
||||||
|
use crate::util::reset_color;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum DiffEntry<'b, 's> {
|
pub enum DiffEntry<'b, 's> {
|
||||||
@@ -200,21 +202,21 @@ impl<'b, 's> DiffResult<'b, 's> {
|
|||||||
if self.has_bad_children() {
|
if self.has_bad_children() {
|
||||||
format!(
|
format!(
|
||||||
"{color}BADCHILD{reset}",
|
"{color}BADCHILD{reset}",
|
||||||
color = DiffResult::foreground_color(255, 255, 0),
|
color = foreground_color(255, 255, 0),
|
||||||
reset = DiffResult::reset_color(),
|
reset = reset_color(),
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
format!(
|
format!(
|
||||||
"{color}GOOD{reset}",
|
"{color}GOOD{reset}",
|
||||||
color = DiffResult::foreground_color(0, 255, 0),
|
color = foreground_color(0, 255, 0),
|
||||||
reset = DiffResult::reset_color(),
|
reset = reset_color(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
DiffStatus::Bad => format!(
|
DiffStatus::Bad => format!(
|
||||||
"{color}BAD{reset}",
|
"{color}BAD{reset}",
|
||||||
color = DiffResult::foreground_color(255, 0, 0),
|
color = foreground_color(255, 0, 0),
|
||||||
reset = DiffResult::reset_color(),
|
reset = reset_color(),
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -239,45 +241,6 @@ impl<'b, 's> DiffResult<'b, 's> {
|
|||||||
.iter()
|
.iter()
|
||||||
.any(|child| child.is_immediately_bad() || child.has_bad_children())
|
.any(|child| child.is_immediately_bad() || child.has_bad_children())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn foreground_color(red: u8, green: u8, blue: u8) -> String {
|
|
||||||
if DiffResult::should_use_color() {
|
|
||||||
format!(
|
|
||||||
"\x1b[38;2;{red};{green};{blue}m",
|
|
||||||
red = red,
|
|
||||||
green = green,
|
|
||||||
blue = blue
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
String::new()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[allow(dead_code)]
|
|
||||||
pub(crate) fn background_color(red: u8, green: u8, blue: u8) -> String {
|
|
||||||
if DiffResult::should_use_color() {
|
|
||||||
format!(
|
|
||||||
"\x1b[48;2;{red};{green};{blue}m",
|
|
||||||
red = red,
|
|
||||||
green = green,
|
|
||||||
blue = blue
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
String::new()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) fn reset_color() -> &'static str {
|
|
||||||
if DiffResult::should_use_color() {
|
|
||||||
"\x1b[0m"
|
|
||||||
} else {
|
|
||||||
""
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn should_use_color() -> bool {
|
|
||||||
!std::env::var("NO_COLOR").is_ok_and(|val| !val.is_empty())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'b, 's> DiffLayer<'b, 's> {
|
impl<'b, 's> DiffLayer<'b, 's> {
|
||||||
@@ -295,14 +258,14 @@ impl<'b, 's> DiffLayer<'b, 's> {
|
|||||||
let status_text = if self.has_bad_children() {
|
let status_text = if self.has_bad_children() {
|
||||||
format!(
|
format!(
|
||||||
"{color}BADCHILD{reset}",
|
"{color}BADCHILD{reset}",
|
||||||
color = DiffResult::foreground_color(255, 255, 0),
|
color = foreground_color(255, 255, 0),
|
||||||
reset = DiffResult::reset_color(),
|
reset = reset_color(),
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
format!(
|
format!(
|
||||||
"{color}GOOD{reset}",
|
"{color}GOOD{reset}",
|
||||||
color = DiffResult::foreground_color(0, 255, 0),
|
color = foreground_color(0, 255, 0),
|
||||||
reset = DiffResult::reset_color(),
|
reset = reset_color(),
|
||||||
)
|
)
|
||||||
};
|
};
|
||||||
println!(
|
println!(
|
||||||
|
|||||||
@@ -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,12 @@ 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(crate) use compare_field::EmacsField;
|
||||||
|
pub(crate) use elisp_fact::ElispFact;
|
||||||
|
pub use sexp::sexp;
|
||||||
|
pub(crate) use sexp::unquote;
|
||||||
|
pub use sexp::Token;
|
||||||
|
pub(crate) use util::get_emacs_standard_properties;
|
||||||
|
pub(crate) use util::get_property;
|
||||||
|
pub(crate) use util::get_property_quoted_string;
|
||||||
|
pub(crate) use util::EmacsStandardProperties;
|
||||||
|
|||||||
@@ -145,20 +145,20 @@ fn assert_post_blank<'b, 's, S: StandardProperties<'s> + ?Sized>(
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
struct EmacsStandardProperties {
|
pub(crate) struct EmacsStandardProperties {
|
||||||
begin: Option<usize>,
|
pub(crate) begin: Option<usize>,
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
post_affiliated: Option<usize>,
|
pub(crate) post_affiliated: Option<usize>,
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
contents_begin: Option<usize>,
|
pub(crate) contents_begin: Option<usize>,
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
contents_end: Option<usize>,
|
pub(crate) contents_end: Option<usize>,
|
||||||
end: Option<usize>,
|
pub(crate) end: Option<usize>,
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
post_blank: Option<usize>,
|
pub(crate) post_blank: Option<usize>,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_emacs_standard_properties(
|
pub(crate) fn get_emacs_standard_properties(
|
||||||
emacs: &Token<'_>,
|
emacs: &Token<'_>,
|
||||||
) -> Result<EmacsStandardProperties, Box<dyn std::error::Error>> {
|
) -> Result<EmacsStandardProperties, Box<dyn std::error::Error>> {
|
||||||
let children = emacs.as_list()?;
|
let children = emacs.as_list()?;
|
||||||
|
|||||||
@@ -8,8 +8,15 @@
|
|||||||
|
|
||||||
extern crate test;
|
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;
|
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;
|
||||||
|
|||||||
@@ -1,29 +1,55 @@
|
|||||||
|
use std::borrow::Cow;
|
||||||
use std::path::Path;
|
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 {
|
pub(crate) async fn get_emacs_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
|
||||||
}
|
(message "%s" (version))
|
||||||
if global_settings.odd_levels_only != HeadlineLevelFilter::default() {
|
)"#;
|
||||||
ret += match global_settings.odd_levels_only {
|
let mut cmd = Command::new("emacs");
|
||||||
HeadlineLevelFilter::Odd => "(setq org-odd-levels-only t)\n",
|
let cmd = cmd
|
||||||
HeadlineLevelFilter::OddEven => "(setq org-odd-levels-only nil)\n",
|
.arg("-q")
|
||||||
};
|
.arg("--no-site-file")
|
||||||
}
|
.arg("--no-splash")
|
||||||
ret
|
.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 get_org_mode_version() -> Result<String, Box<dyn std::error::Error>> {
|
||||||
|
let elisp_script = r#"(progn
|
||||||
|
(org-mode)
|
||||||
|
(message "%s" (org-version nil t nil))
|
||||||
|
)"#;
|
||||||
|
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 +170,64 @@ 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")
|
if global_settings.tab_width != crate::settings::DEFAULT_TAB_WIDTH {
|
||||||
.arg("--eval")
|
ret += format!("(setq-default tab-width {})", global_settings.tab_width).as_str();
|
||||||
.arg(elisp_script);
|
}
|
||||||
|
if global_settings.odd_levels_only != HeadlineLevelFilter::default() {
|
||||||
let out = cmd.output().await?;
|
ret += match global_settings.odd_levels_only {
|
||||||
out.status.exit_ok()?;
|
HeadlineLevelFilter::Odd => "(setq org-odd-levels-only t)\n",
|
||||||
Ok(String::from_utf8(out.stderr)?)
|
HeadlineLevelFilter::OddEven => "(setq org-odd-levels-only nil)\n",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
ret
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn get_org_mode_version() -> Result<String, Box<dyn std::error::Error>> {
|
fn should_use_color() -> bool {
|
||||||
let elisp_script = r#"(progn
|
!std::env::var("NO_COLOR").is_ok_and(|val| !val.is_empty())
|
||||||
(org-mode)
|
}
|
||||||
(message "%s" (org-version nil t nil))
|
|
||||||
)"#;
|
pub(crate) fn foreground_color(red: u8, green: u8, blue: u8) -> Cow<'static, str> {
|
||||||
let mut cmd = Command::new("emacs");
|
if should_use_color() {
|
||||||
let cmd = cmd
|
format!(
|
||||||
.arg("-q")
|
"\x1b[38;2;{red};{green};{blue}m",
|
||||||
.arg("--no-site-file")
|
red = red,
|
||||||
.arg("--no-splash")
|
green = green,
|
||||||
.arg("--batch")
|
blue = blue
|
||||||
.arg("--eval")
|
)
|
||||||
.arg(elisp_script);
|
.into()
|
||||||
|
} else {
|
||||||
let out = cmd.output().await?;
|
Cow::from("")
|
||||||
out.status.exit_ok()?;
|
}
|
||||||
Ok(String::from_utf8(out.stderr)?)
|
}
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
|
pub(crate) fn background_color(red: u8, green: u8, blue: u8) -> Cow<'static, str> {
|
||||||
|
if should_use_color() {
|
||||||
|
format!(
|
||||||
|
"\x1b[48;2;{red};{green};{blue}m",
|
||||||
|
red = red,
|
||||||
|
green = green,
|
||||||
|
blue = blue
|
||||||
|
)
|
||||||
|
.into()
|
||||||
|
} else {
|
||||||
|
Cow::from("")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) fn reset_color() -> &'static str {
|
||||||
|
if should_use_color() {
|
||||||
|
"\x1b[0m"
|
||||||
|
} else {
|
||||||
|
""
|
||||||
|
}
|
||||||
}
|
}
|
||||||
95
src/wasm/additional_property.rs
Normal file
95
src/wasm/additional_property.rs
Normal file
@@ -0,0 +1,95 @@
|
|||||||
|
use std::collections::HashMap;
|
||||||
|
|
||||||
|
use serde::Serialize;
|
||||||
|
|
||||||
|
use super::macros::to_wasm;
|
||||||
|
use super::to_wasm::ToWasm;
|
||||||
|
use super::WasmAstNode;
|
||||||
|
use crate::types::AffiliatedKeywordValue;
|
||||||
|
use crate::types::AffiliatedKeywords;
|
||||||
|
|
||||||
|
#[derive(Debug, Serialize)]
|
||||||
|
#[serde(untagged)]
|
||||||
|
pub enum AdditionalPropertyValue<'s, 'p> {
|
||||||
|
SingleString(&'s str),
|
||||||
|
ListOfStrings(Vec<&'s str>),
|
||||||
|
OptionalPair {
|
||||||
|
optval: Option<&'s str>,
|
||||||
|
val: &'s str,
|
||||||
|
},
|
||||||
|
ObjectTree(Vec<(Option<Vec<WasmAstNode<'s, 'p>>>, Vec<WasmAstNode<'s, 'p>>)>),
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Serialize, Default)]
|
||||||
|
pub struct AdditionalProperties<'s, 'p> {
|
||||||
|
#[serde(flatten)]
|
||||||
|
pub(crate) properties: HashMap<String, AdditionalPropertyValue<'s, 'p>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'s, 'p> AdditionalProperties<'s, 'p> {
|
||||||
|
pub(crate) fn get_elisp_names<'c>(&'c self) -> impl Iterator<Item = String> + 'c {
|
||||||
|
self.properties.keys().map(move |key| format!(":{}", key))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
to_wasm!(
|
||||||
|
AdditionalProperties<'s, 'p>,
|
||||||
|
AffiliatedKeywords<'s>,
|
||||||
|
original,
|
||||||
|
wasm_context,
|
||||||
|
{
|
||||||
|
let mut additional_properties = AdditionalProperties::default();
|
||||||
|
for (name, val) in original.keywords.iter() {
|
||||||
|
let converted_val = match val {
|
||||||
|
AffiliatedKeywordValue::SingleString(val) => {
|
||||||
|
AdditionalPropertyValue::SingleString(val)
|
||||||
|
}
|
||||||
|
AffiliatedKeywordValue::ListOfStrings(val) => {
|
||||||
|
AdditionalPropertyValue::ListOfStrings(val.clone())
|
||||||
|
}
|
||||||
|
AffiliatedKeywordValue::OptionalPair { optval, val } => {
|
||||||
|
AdditionalPropertyValue::OptionalPair {
|
||||||
|
optval: optval.clone(),
|
||||||
|
val: val,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
AffiliatedKeywordValue::ObjectTree(val) => {
|
||||||
|
let mut ret = Vec::with_capacity(val.len());
|
||||||
|
|
||||||
|
for (optval, value) in val {
|
||||||
|
let converted_optval = if let Some(optval) = optval {
|
||||||
|
Some(
|
||||||
|
optval
|
||||||
|
.iter()
|
||||||
|
.map(|child| {
|
||||||
|
child
|
||||||
|
.to_wasm(wasm_context.clone())
|
||||||
|
.map(Into::<WasmAstNode<'_, '_>>::into)
|
||||||
|
})
|
||||||
|
.collect::<Result<Vec<_>, _>>()?,
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
};
|
||||||
|
let converted_value = value
|
||||||
|
.iter()
|
||||||
|
.map(|child| {
|
||||||
|
child
|
||||||
|
.to_wasm(wasm_context.clone())
|
||||||
|
.map(Into::<WasmAstNode<'_, '_>>::into)
|
||||||
|
})
|
||||||
|
.collect::<Result<Vec<_>, _>>()?;
|
||||||
|
|
||||||
|
ret.push((converted_optval, converted_value));
|
||||||
|
}
|
||||||
|
|
||||||
|
AdditionalPropertyValue::ObjectTree(ret)
|
||||||
|
}
|
||||||
|
};
|
||||||
|
additional_properties
|
||||||
|
.properties
|
||||||
|
.insert(name.clone(), converted_val);
|
||||||
|
}
|
||||||
|
Ok(additional_properties)
|
||||||
|
}
|
||||||
|
);
|
||||||
36
src/wasm/angle_link.rs
Normal file
36
src/wasm/angle_link.rs
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
use serde::Serialize;
|
||||||
|
|
||||||
|
use super::macros::to_wasm;
|
||||||
|
use super::standard_properties::WasmStandardProperties;
|
||||||
|
use super::to_wasm::ToWasm;
|
||||||
|
use crate::types::AngleLink;
|
||||||
|
use crate::wasm::to_wasm::ToWasmStandardProperties;
|
||||||
|
use crate::wasm::WasmAstNode;
|
||||||
|
|
||||||
|
#[derive(Debug, Serialize)]
|
||||||
|
#[serde(tag = "ast_node")]
|
||||||
|
#[serde(rename = "org-data")]
|
||||||
|
pub struct WasmAngleLink<'s, 'p> {
|
||||||
|
standard_properties: WasmStandardProperties,
|
||||||
|
children: Vec<WasmAstNode<'s, 'p>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
to_wasm!(
|
||||||
|
WasmAngleLink<'s, 'p>,
|
||||||
|
AngleLink<'s>,
|
||||||
|
original,
|
||||||
|
wasm_context,
|
||||||
|
standard_properties,
|
||||||
|
{
|
||||||
|
Ok(WasmAngleLink {
|
||||||
|
standard_properties,
|
||||||
|
children: Vec::new(),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
impl<'s, 'p> Into<WasmAstNode<'s, 'p>> for WasmAngleLink<'s, 'p> {
|
||||||
|
fn into(self) -> WasmAstNode<'s, 'p> {
|
||||||
|
WasmAstNode::AngleLink(self)
|
||||||
|
}
|
||||||
|
}
|
||||||
128
src/wasm/ast_node.rs
Normal file
128
src/wasm/ast_node.rs
Normal 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, 'p> {
|
||||||
|
// Document Nodes
|
||||||
|
Document(WasmDocument<'s, 'p>),
|
||||||
|
Headline(WasmHeadline<'s, 'p>),
|
||||||
|
Section(WasmSection<'s, 'p>),
|
||||||
|
// Elements
|
||||||
|
Paragraph(WasmParagraph<'s, 'p>),
|
||||||
|
PlainList(WasmPlainList<'s, 'p>),
|
||||||
|
PlainListItem(WasmPlainListItem<'s, 'p>),
|
||||||
|
CenterBlock(WasmCenterBlock<'s, 'p>),
|
||||||
|
QuoteBlock(WasmQuoteBlock<'s, 'p>),
|
||||||
|
SpecialBlock(WasmSpecialBlock<'s, 'p>),
|
||||||
|
DynamicBlock(WasmDynamicBlock<'s, 'p>),
|
||||||
|
FootnoteDefinition(WasmFootnoteDefinition<'s, 'p>),
|
||||||
|
Comment(WasmComment<'s, 'p>),
|
||||||
|
Drawer(WasmDrawer<'s, 'p>),
|
||||||
|
PropertyDrawer(WasmPropertyDrawer<'s, 'p>),
|
||||||
|
NodeProperty(WasmNodeProperty<'s, 'p>),
|
||||||
|
Table(WasmTable<'s, 'p>),
|
||||||
|
TableRow(WasmTableRow<'s, 'p>),
|
||||||
|
VerseBlock(WasmVerseBlock<'s, 'p>),
|
||||||
|
CommentBlock(WasmCommentBlock<'s, 'p>),
|
||||||
|
ExampleBlock(WasmExampleBlock<'s, 'p>),
|
||||||
|
ExportBlock(WasmExportBlock<'s, 'p>),
|
||||||
|
SrcBlock(WasmSrcBlock<'s, 'p>),
|
||||||
|
Clock(WasmClock<'s, 'p>),
|
||||||
|
DiarySexp(WasmDiarySexp<'s, 'p>),
|
||||||
|
Planning(WasmPlanning<'s, 'p>),
|
||||||
|
FixedWidthArea(WasmFixedWidthArea<'s, 'p>),
|
||||||
|
HorizontalRule(WasmHorizontalRule<'s, 'p>),
|
||||||
|
Keyword(WasmKeyword<'s, 'p>),
|
||||||
|
BabelCall(WasmBabelCall<'s, 'p>),
|
||||||
|
LatexEnvironment(WasmLatexEnvironment<'s, 'p>),
|
||||||
|
// Objects
|
||||||
|
Bold(WasmBold<'s, 'p>),
|
||||||
|
Italic(WasmItalic<'s, 'p>),
|
||||||
|
Underline(WasmUnderline<'s, 'p>),
|
||||||
|
StrikeThrough(WasmStrikeThrough<'s, 'p>),
|
||||||
|
Code(WasmCode<'s, 'p>),
|
||||||
|
Verbatim(WasmVerbatim<'s, 'p>),
|
||||||
|
PlainText(WasmPlainText<'s, 'p>),
|
||||||
|
RegularLink(WasmRegularLink<'s, 'p>),
|
||||||
|
RadioLink(WasmRadioLink<'s, 'p>),
|
||||||
|
RadioTarget(WasmRadioTarget<'s, 'p>),
|
||||||
|
PlainLink(WasmPlainLink<'s, 'p>),
|
||||||
|
AngleLink(WasmAngleLink<'s, 'p>),
|
||||||
|
OrgMacro(WasmOrgMacro<'s, 'p>),
|
||||||
|
Entity(WasmEntity<'s, 'p>),
|
||||||
|
LatexFragment(WasmLatexFragment<'s, 'p>),
|
||||||
|
ExportSnippet(WasmExportSnippet<'s, 'p>),
|
||||||
|
FootnoteReference(WasmFootnoteReference<'s, 'p>),
|
||||||
|
Citation(WasmCitation<'s, 'p>),
|
||||||
|
CitationReference(WasmCitationReference<'s, 'p>),
|
||||||
|
InlineBabelCall(WasmInlineBabelCall<'s, 'p>),
|
||||||
|
InlineSourceBlock(WasmInlineSourceBlock<'s, 'p>),
|
||||||
|
LineBreak(WasmLineBreak<'s, 'p>),
|
||||||
|
Target(WasmTarget<'s, 'p>),
|
||||||
|
StatisticsCookie(WasmStatisticsCookie<'s, 'p>),
|
||||||
|
Subscript(WasmSubscript<'s, 'p>),
|
||||||
|
Superscript(WasmSuperscript<'s, 'p>),
|
||||||
|
TableCell(WasmTableCell<'s, 'p>),
|
||||||
|
Timestamp(WasmTimestamp<'s, 'p>),
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'s, 'p> WasmAstNode<'s, 'p> {}
|
||||||
36
src/wasm/babel_call.rs
Normal file
36
src/wasm/babel_call.rs
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
use serde::Serialize;
|
||||||
|
|
||||||
|
use super::macros::to_wasm;
|
||||||
|
use super::standard_properties::WasmStandardProperties;
|
||||||
|
use super::to_wasm::ToWasm;
|
||||||
|
use crate::types::BabelCall;
|
||||||
|
use crate::wasm::to_wasm::ToWasmStandardProperties;
|
||||||
|
use crate::wasm::WasmAstNode;
|
||||||
|
|
||||||
|
#[derive(Debug, Serialize)]
|
||||||
|
#[serde(tag = "ast_node")]
|
||||||
|
#[serde(rename = "org-data")]
|
||||||
|
pub struct WasmBabelCall<'s, 'p> {
|
||||||
|
standard_properties: WasmStandardProperties,
|
||||||
|
children: Vec<WasmAstNode<'s, 'p>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
to_wasm!(
|
||||||
|
WasmBabelCall<'s, 'p>,
|
||||||
|
BabelCall<'s>,
|
||||||
|
original,
|
||||||
|
wasm_context,
|
||||||
|
standard_properties,
|
||||||
|
{
|
||||||
|
Ok(WasmBabelCall {
|
||||||
|
standard_properties,
|
||||||
|
children: Vec::new(),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
impl<'s, 'p> Into<WasmAstNode<'s, 'p>> for WasmBabelCall<'s, 'p> {
|
||||||
|
fn into(self) -> WasmAstNode<'s, 'p> {
|
||||||
|
WasmAstNode::BabelCall(self)
|
||||||
|
}
|
||||||
|
}
|
||||||
36
src/wasm/bold.rs
Normal file
36
src/wasm/bold.rs
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
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;
|
||||||
|
use crate::wasm::WasmAstNode;
|
||||||
|
|
||||||
|
#[derive(Debug, Serialize)]
|
||||||
|
#[serde(tag = "ast_node")]
|
||||||
|
#[serde(rename = "org-data")]
|
||||||
|
pub struct WasmBold<'s, 'p> {
|
||||||
|
standard_properties: WasmStandardProperties,
|
||||||
|
children: Vec<WasmAstNode<'s, 'p>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
to_wasm!(
|
||||||
|
WasmBold<'s, 'p>,
|
||||||
|
Bold<'s>,
|
||||||
|
original,
|
||||||
|
wasm_context,
|
||||||
|
standard_properties,
|
||||||
|
{
|
||||||
|
Ok(WasmBold {
|
||||||
|
standard_properties,
|
||||||
|
children: Vec::new(),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
impl<'s, 'p> Into<WasmAstNode<'s, 'p>> for WasmBold<'s, 'p> {
|
||||||
|
fn into(self) -> WasmAstNode<'s, 'p> {
|
||||||
|
WasmAstNode::Bold(self)
|
||||||
|
}
|
||||||
|
}
|
||||||
36
src/wasm/center_block.rs
Normal file
36
src/wasm/center_block.rs
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
use serde::Serialize;
|
||||||
|
|
||||||
|
use super::macros::to_wasm;
|
||||||
|
use super::standard_properties::WasmStandardProperties;
|
||||||
|
use super::to_wasm::ToWasm;
|
||||||
|
use crate::types::CenterBlock;
|
||||||
|
use crate::wasm::to_wasm::ToWasmStandardProperties;
|
||||||
|
use crate::wasm::WasmAstNode;
|
||||||
|
|
||||||
|
#[derive(Debug, Serialize)]
|
||||||
|
#[serde(tag = "ast_node")]
|
||||||
|
#[serde(rename = "org-data")]
|
||||||
|
pub struct WasmCenterBlock<'s, 'p> {
|
||||||
|
standard_properties: WasmStandardProperties,
|
||||||
|
children: Vec<WasmAstNode<'s, 'p>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
to_wasm!(
|
||||||
|
WasmCenterBlock<'s, 'p>,
|
||||||
|
CenterBlock<'s>,
|
||||||
|
original,
|
||||||
|
wasm_context,
|
||||||
|
standard_properties,
|
||||||
|
{
|
||||||
|
Ok(WasmCenterBlock {
|
||||||
|
standard_properties,
|
||||||
|
children: Vec::new(),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
impl<'s, 'p> Into<WasmAstNode<'s, 'p>> for WasmCenterBlock<'s, 'p> {
|
||||||
|
fn into(self) -> WasmAstNode<'s, 'p> {
|
||||||
|
WasmAstNode::CenterBlock(self)
|
||||||
|
}
|
||||||
|
}
|
||||||
36
src/wasm/citation.rs
Normal file
36
src/wasm/citation.rs
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
use serde::Serialize;
|
||||||
|
|
||||||
|
use super::macros::to_wasm;
|
||||||
|
use super::standard_properties::WasmStandardProperties;
|
||||||
|
use super::to_wasm::ToWasm;
|
||||||
|
use crate::types::Citation;
|
||||||
|
use crate::wasm::to_wasm::ToWasmStandardProperties;
|
||||||
|
use crate::wasm::WasmAstNode;
|
||||||
|
|
||||||
|
#[derive(Debug, Serialize)]
|
||||||
|
#[serde(tag = "ast_node")]
|
||||||
|
#[serde(rename = "org-data")]
|
||||||
|
pub struct WasmCitation<'s, 'p> {
|
||||||
|
standard_properties: WasmStandardProperties,
|
||||||
|
children: Vec<WasmAstNode<'s, 'p>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
to_wasm!(
|
||||||
|
WasmCitation<'s, 'p>,
|
||||||
|
Citation<'s>,
|
||||||
|
original,
|
||||||
|
wasm_context,
|
||||||
|
standard_properties,
|
||||||
|
{
|
||||||
|
Ok(WasmCitation {
|
||||||
|
standard_properties,
|
||||||
|
children: Vec::new(),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
impl<'s, 'p> Into<WasmAstNode<'s, 'p>> for WasmCitation<'s, 'p> {
|
||||||
|
fn into(self) -> WasmAstNode<'s, 'p> {
|
||||||
|
WasmAstNode::Citation(self)
|
||||||
|
}
|
||||||
|
}
|
||||||
36
src/wasm/citation_reference.rs
Normal file
36
src/wasm/citation_reference.rs
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
use serde::Serialize;
|
||||||
|
|
||||||
|
use super::macros::to_wasm;
|
||||||
|
use super::standard_properties::WasmStandardProperties;
|
||||||
|
use super::to_wasm::ToWasm;
|
||||||
|
use crate::types::CitationReference;
|
||||||
|
use crate::wasm::to_wasm::ToWasmStandardProperties;
|
||||||
|
use crate::wasm::WasmAstNode;
|
||||||
|
|
||||||
|
#[derive(Debug, Serialize)]
|
||||||
|
#[serde(tag = "ast_node")]
|
||||||
|
#[serde(rename = "org-data")]
|
||||||
|
pub struct WasmCitationReference<'s, 'p> {
|
||||||
|
standard_properties: WasmStandardProperties,
|
||||||
|
children: Vec<WasmAstNode<'s, 'p>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
to_wasm!(
|
||||||
|
WasmCitationReference<'s, 'p>,
|
||||||
|
CitationReference<'s>,
|
||||||
|
original,
|
||||||
|
wasm_context,
|
||||||
|
standard_properties,
|
||||||
|
{
|
||||||
|
Ok(WasmCitationReference {
|
||||||
|
standard_properties,
|
||||||
|
children: Vec::new(),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
impl<'s, 'p> Into<WasmAstNode<'s, 'p>> for WasmCitationReference<'s, 'p> {
|
||||||
|
fn into(self) -> WasmAstNode<'s, 'p> {
|
||||||
|
WasmAstNode::CitationReference(self)
|
||||||
|
}
|
||||||
|
}
|
||||||
36
src/wasm/clock.rs
Normal file
36
src/wasm/clock.rs
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
use serde::Serialize;
|
||||||
|
|
||||||
|
use super::macros::to_wasm;
|
||||||
|
use super::standard_properties::WasmStandardProperties;
|
||||||
|
use super::to_wasm::ToWasm;
|
||||||
|
use crate::types::Clock;
|
||||||
|
use crate::wasm::to_wasm::ToWasmStandardProperties;
|
||||||
|
use crate::wasm::WasmAstNode;
|
||||||
|
|
||||||
|
#[derive(Debug, Serialize)]
|
||||||
|
#[serde(tag = "ast_node")]
|
||||||
|
#[serde(rename = "org-data")]
|
||||||
|
pub struct WasmClock<'s, 'p> {
|
||||||
|
standard_properties: WasmStandardProperties,
|
||||||
|
children: Vec<WasmAstNode<'s, 'p>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
to_wasm!(
|
||||||
|
WasmClock<'s, 'p>,
|
||||||
|
Clock<'s>,
|
||||||
|
original,
|
||||||
|
wasm_context,
|
||||||
|
standard_properties,
|
||||||
|
{
|
||||||
|
Ok(WasmClock {
|
||||||
|
standard_properties,
|
||||||
|
children: Vec::new(),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
impl<'s, 'p> Into<WasmAstNode<'s, 'p>> for WasmClock<'s, 'p> {
|
||||||
|
fn into(self) -> WasmAstNode<'s, 'p> {
|
||||||
|
WasmAstNode::Clock(self)
|
||||||
|
}
|
||||||
|
}
|
||||||
36
src/wasm/code.rs
Normal file
36
src/wasm/code.rs
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
use serde::Serialize;
|
||||||
|
|
||||||
|
use super::macros::to_wasm;
|
||||||
|
use super::standard_properties::WasmStandardProperties;
|
||||||
|
use super::to_wasm::ToWasm;
|
||||||
|
use crate::types::Code;
|
||||||
|
use crate::wasm::to_wasm::ToWasmStandardProperties;
|
||||||
|
use crate::wasm::WasmAstNode;
|
||||||
|
|
||||||
|
#[derive(Debug, Serialize)]
|
||||||
|
#[serde(tag = "ast_node")]
|
||||||
|
#[serde(rename = "org-data")]
|
||||||
|
pub struct WasmCode<'s, 'p> {
|
||||||
|
standard_properties: WasmStandardProperties,
|
||||||
|
children: Vec<WasmAstNode<'s, 'p>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
to_wasm!(
|
||||||
|
WasmCode<'s, 'p>,
|
||||||
|
Code<'s>,
|
||||||
|
original,
|
||||||
|
wasm_context,
|
||||||
|
standard_properties,
|
||||||
|
{
|
||||||
|
Ok(WasmCode {
|
||||||
|
standard_properties,
|
||||||
|
children: Vec::new(),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
impl<'s, 'p> Into<WasmAstNode<'s, 'p>> for WasmCode<'s, 'p> {
|
||||||
|
fn into(self) -> WasmAstNode<'s, 'p> {
|
||||||
|
WasmAstNode::Code(self)
|
||||||
|
}
|
||||||
|
}
|
||||||
36
src/wasm/comment.rs
Normal file
36
src/wasm/comment.rs
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
use serde::Serialize;
|
||||||
|
|
||||||
|
use super::macros::to_wasm;
|
||||||
|
use super::standard_properties::WasmStandardProperties;
|
||||||
|
use super::to_wasm::ToWasm;
|
||||||
|
use crate::types::Comment;
|
||||||
|
use crate::wasm::to_wasm::ToWasmStandardProperties;
|
||||||
|
use crate::wasm::WasmAstNode;
|
||||||
|
|
||||||
|
#[derive(Debug, Serialize)]
|
||||||
|
#[serde(tag = "ast_node")]
|
||||||
|
#[serde(rename = "org-data")]
|
||||||
|
pub struct WasmComment<'s, 'p> {
|
||||||
|
standard_properties: WasmStandardProperties,
|
||||||
|
children: Vec<WasmAstNode<'s, 'p>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
to_wasm!(
|
||||||
|
WasmComment<'s, 'p>,
|
||||||
|
Comment<'s>,
|
||||||
|
original,
|
||||||
|
wasm_context,
|
||||||
|
standard_properties,
|
||||||
|
{
|
||||||
|
Ok(WasmComment {
|
||||||
|
standard_properties,
|
||||||
|
children: Vec::new(),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
impl<'s, 'p> Into<WasmAstNode<'s, 'p>> for WasmComment<'s, 'p> {
|
||||||
|
fn into(self) -> WasmAstNode<'s, 'p> {
|
||||||
|
WasmAstNode::Comment(self)
|
||||||
|
}
|
||||||
|
}
|
||||||
36
src/wasm/comment_block.rs
Normal file
36
src/wasm/comment_block.rs
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
use serde::Serialize;
|
||||||
|
|
||||||
|
use super::macros::to_wasm;
|
||||||
|
use super::standard_properties::WasmStandardProperties;
|
||||||
|
use super::to_wasm::ToWasm;
|
||||||
|
use crate::types::CommentBlock;
|
||||||
|
use crate::wasm::to_wasm::ToWasmStandardProperties;
|
||||||
|
use crate::wasm::WasmAstNode;
|
||||||
|
|
||||||
|
#[derive(Debug, Serialize)]
|
||||||
|
#[serde(tag = "ast_node")]
|
||||||
|
#[serde(rename = "org-data")]
|
||||||
|
pub struct WasmCommentBlock<'s, 'p> {
|
||||||
|
standard_properties: WasmStandardProperties,
|
||||||
|
children: Vec<WasmAstNode<'s, 'p>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
to_wasm!(
|
||||||
|
WasmCommentBlock<'s, 'p>,
|
||||||
|
CommentBlock<'s>,
|
||||||
|
original,
|
||||||
|
wasm_context,
|
||||||
|
standard_properties,
|
||||||
|
{
|
||||||
|
Ok(WasmCommentBlock {
|
||||||
|
standard_properties,
|
||||||
|
children: Vec::new(),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
impl<'s, 'p> Into<WasmAstNode<'s, 'p>> for WasmCommentBlock<'s, 'p> {
|
||||||
|
fn into(self) -> WasmAstNode<'s, 'p> {
|
||||||
|
WasmAstNode::CommentBlock(self)
|
||||||
|
}
|
||||||
|
}
|
||||||
36
src/wasm/diary_sexp.rs
Normal file
36
src/wasm/diary_sexp.rs
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
use serde::Serialize;
|
||||||
|
|
||||||
|
use super::macros::to_wasm;
|
||||||
|
use super::standard_properties::WasmStandardProperties;
|
||||||
|
use super::to_wasm::ToWasm;
|
||||||
|
use crate::types::DiarySexp;
|
||||||
|
use crate::wasm::to_wasm::ToWasmStandardProperties;
|
||||||
|
use crate::wasm::WasmAstNode;
|
||||||
|
|
||||||
|
#[derive(Debug, Serialize)]
|
||||||
|
#[serde(tag = "ast_node")]
|
||||||
|
#[serde(rename = "org-data")]
|
||||||
|
pub struct WasmDiarySexp<'s, 'p> {
|
||||||
|
standard_properties: WasmStandardProperties,
|
||||||
|
children: Vec<WasmAstNode<'s, 'p>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
to_wasm!(
|
||||||
|
WasmDiarySexp<'s, 'p>,
|
||||||
|
DiarySexp<'s>,
|
||||||
|
original,
|
||||||
|
wasm_context,
|
||||||
|
standard_properties,
|
||||||
|
{
|
||||||
|
Ok(WasmDiarySexp {
|
||||||
|
standard_properties,
|
||||||
|
children: Vec::new(),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
impl<'s, 'p> Into<WasmAstNode<'s, 'p>> for WasmDiarySexp<'s, 'p> {
|
||||||
|
fn into(self) -> WasmAstNode<'s, 'p> {
|
||||||
|
WasmAstNode::DiarySexp(self)
|
||||||
|
}
|
||||||
|
}
|
||||||
84
src/wasm/document.rs
Normal file
84
src/wasm/document.rs
Normal file
@@ -0,0 +1,84 @@
|
|||||||
|
use std::path::PathBuf;
|
||||||
|
|
||||||
|
use serde::Serialize;
|
||||||
|
|
||||||
|
use super::additional_property::AdditionalProperties;
|
||||||
|
use super::additional_property::AdditionalPropertyValue;
|
||||||
|
use super::ast_node::WasmAstNode;
|
||||||
|
use super::macros::to_wasm;
|
||||||
|
use super::standard_properties::WasmStandardProperties;
|
||||||
|
use super::to_wasm::ToWasm;
|
||||||
|
#[cfg(feature = "wasm_test")]
|
||||||
|
use crate::compare::ElispFact;
|
||||||
|
use crate::types::Document;
|
||||||
|
use crate::wasm::to_wasm::ToWasmStandardProperties;
|
||||||
|
|
||||||
|
#[derive(Debug, Serialize)]
|
||||||
|
#[serde(tag = "ast_node")]
|
||||||
|
#[serde(rename = "org-data")]
|
||||||
|
pub struct WasmDocument<'s, 'p> {
|
||||||
|
pub(crate) standard_properties: WasmStandardProperties,
|
||||||
|
#[serde(flatten)]
|
||||||
|
pub(crate) additional_properties: AdditionalProperties<'s, 'p>,
|
||||||
|
pub(crate) children: Vec<WasmAstNode<'s, 'p>>,
|
||||||
|
pub(crate) category: Option<&'p str>,
|
||||||
|
pub(crate) path: Option<PathBuf>,
|
||||||
|
}
|
||||||
|
|
||||||
|
to_wasm!(
|
||||||
|
WasmDocument<'s, 'p>,
|
||||||
|
Document<'s>,
|
||||||
|
original,
|
||||||
|
wasm_context,
|
||||||
|
standard_properties,
|
||||||
|
{
|
||||||
|
let category = original.category.as_ref().map(String::as_str);
|
||||||
|
let path = original.path.clone();
|
||||||
|
|
||||||
|
let mut additional_properties = AdditionalProperties::default();
|
||||||
|
for (name, val) in original.get_additional_properties().map(|node_property| {
|
||||||
|
(
|
||||||
|
node_property.property_name.to_uppercase(),
|
||||||
|
AdditionalPropertyValue::SingleString(node_property.value.unwrap_or("")),
|
||||||
|
)
|
||||||
|
}) {
|
||||||
|
additional_properties.properties.insert(name, val);
|
||||||
|
}
|
||||||
|
|
||||||
|
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<_>, _>>()?;
|
||||||
|
|
||||||
|
Ok(WasmDocument {
|
||||||
|
standard_properties,
|
||||||
|
additional_properties,
|
||||||
|
children,
|
||||||
|
category,
|
||||||
|
path,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
impl<'s, 'p> Into<WasmAstNode<'s, 'p>> for WasmDocument<'s, 'p> {
|
||||||
|
fn into(self) -> WasmAstNode<'s, 'p> {
|
||||||
|
WasmAstNode::Document(self)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "wasm_test")]
|
||||||
|
impl<'s, 'p> ElispFact<'s> for WasmDocument<'s, 'p> {
|
||||||
|
fn get_elisp_name<'b>(&'b self) -> std::borrow::Cow<'s, str> {
|
||||||
|
"org-data".into()
|
||||||
|
}
|
||||||
|
}
|
||||||
36
src/wasm/drawer.rs
Normal file
36
src/wasm/drawer.rs
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
use serde::Serialize;
|
||||||
|
|
||||||
|
use super::macros::to_wasm;
|
||||||
|
use super::standard_properties::WasmStandardProperties;
|
||||||
|
use super::to_wasm::ToWasm;
|
||||||
|
use crate::types::Drawer;
|
||||||
|
use crate::wasm::to_wasm::ToWasmStandardProperties;
|
||||||
|
use crate::wasm::WasmAstNode;
|
||||||
|
|
||||||
|
#[derive(Debug, Serialize)]
|
||||||
|
#[serde(tag = "ast_node")]
|
||||||
|
#[serde(rename = "org-data")]
|
||||||
|
pub struct WasmDrawer<'s, 'p> {
|
||||||
|
standard_properties: WasmStandardProperties,
|
||||||
|
children: Vec<WasmAstNode<'s, 'p>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
to_wasm!(
|
||||||
|
WasmDrawer<'s, 'p>,
|
||||||
|
Drawer<'s>,
|
||||||
|
original,
|
||||||
|
wasm_context,
|
||||||
|
standard_properties,
|
||||||
|
{
|
||||||
|
Ok(WasmDrawer {
|
||||||
|
standard_properties,
|
||||||
|
children: Vec::new(),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
impl<'s, 'p> Into<WasmAstNode<'s, 'p>> for WasmDrawer<'s, 'p> {
|
||||||
|
fn into(self) -> WasmAstNode<'s, 'p> {
|
||||||
|
WasmAstNode::Drawer(self)
|
||||||
|
}
|
||||||
|
}
|
||||||
36
src/wasm/dynamic_block.rs
Normal file
36
src/wasm/dynamic_block.rs
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
use serde::Serialize;
|
||||||
|
|
||||||
|
use super::macros::to_wasm;
|
||||||
|
use super::standard_properties::WasmStandardProperties;
|
||||||
|
use super::to_wasm::ToWasm;
|
||||||
|
use crate::types::DynamicBlock;
|
||||||
|
use crate::wasm::to_wasm::ToWasmStandardProperties;
|
||||||
|
use crate::wasm::WasmAstNode;
|
||||||
|
|
||||||
|
#[derive(Debug, Serialize)]
|
||||||
|
#[serde(tag = "ast_node")]
|
||||||
|
#[serde(rename = "org-data")]
|
||||||
|
pub struct WasmDynamicBlock<'s, 'p> {
|
||||||
|
standard_properties: WasmStandardProperties,
|
||||||
|
children: Vec<WasmAstNode<'s, 'p>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
to_wasm!(
|
||||||
|
WasmDynamicBlock<'s, 'p>,
|
||||||
|
DynamicBlock<'s>,
|
||||||
|
original,
|
||||||
|
wasm_context,
|
||||||
|
standard_properties,
|
||||||
|
{
|
||||||
|
Ok(WasmDynamicBlock {
|
||||||
|
standard_properties,
|
||||||
|
children: Vec::new(),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
impl<'s, 'p> Into<WasmAstNode<'s, 'p>> for WasmDynamicBlock<'s, 'p> {
|
||||||
|
fn into(self) -> WasmAstNode<'s, 'p> {
|
||||||
|
WasmAstNode::DynamicBlock(self)
|
||||||
|
}
|
||||||
|
}
|
||||||
36
src/wasm/entity.rs
Normal file
36
src/wasm/entity.rs
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
use serde::Serialize;
|
||||||
|
|
||||||
|
use super::macros::to_wasm;
|
||||||
|
use super::standard_properties::WasmStandardProperties;
|
||||||
|
use super::to_wasm::ToWasm;
|
||||||
|
use crate::types::Entity;
|
||||||
|
use crate::wasm::to_wasm::ToWasmStandardProperties;
|
||||||
|
use crate::wasm::WasmAstNode;
|
||||||
|
|
||||||
|
#[derive(Debug, Serialize)]
|
||||||
|
#[serde(tag = "ast_node")]
|
||||||
|
#[serde(rename = "org-data")]
|
||||||
|
pub struct WasmEntity<'s, 'p> {
|
||||||
|
standard_properties: WasmStandardProperties,
|
||||||
|
children: Vec<WasmAstNode<'s, 'p>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
to_wasm!(
|
||||||
|
WasmEntity<'s, 'p>,
|
||||||
|
Entity<'s>,
|
||||||
|
original,
|
||||||
|
wasm_context,
|
||||||
|
standard_properties,
|
||||||
|
{
|
||||||
|
Ok(WasmEntity {
|
||||||
|
standard_properties,
|
||||||
|
children: Vec::new(),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
impl<'s, 'p> Into<WasmAstNode<'s, 'p>> for WasmEntity<'s, 'p> {
|
||||||
|
fn into(self) -> WasmAstNode<'s, 'p> {
|
||||||
|
WasmAstNode::Entity(self)
|
||||||
|
}
|
||||||
|
}
|
||||||
36
src/wasm/example_block.rs
Normal file
36
src/wasm/example_block.rs
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
use serde::Serialize;
|
||||||
|
|
||||||
|
use super::macros::to_wasm;
|
||||||
|
use super::standard_properties::WasmStandardProperties;
|
||||||
|
use super::to_wasm::ToWasm;
|
||||||
|
use crate::types::ExampleBlock;
|
||||||
|
use crate::wasm::to_wasm::ToWasmStandardProperties;
|
||||||
|
use crate::wasm::WasmAstNode;
|
||||||
|
|
||||||
|
#[derive(Debug, Serialize)]
|
||||||
|
#[serde(tag = "ast_node")]
|
||||||
|
#[serde(rename = "org-data")]
|
||||||
|
pub struct WasmExampleBlock<'s, 'p> {
|
||||||
|
standard_properties: WasmStandardProperties,
|
||||||
|
children: Vec<WasmAstNode<'s, 'p>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
to_wasm!(
|
||||||
|
WasmExampleBlock<'s, 'p>,
|
||||||
|
ExampleBlock<'s>,
|
||||||
|
original,
|
||||||
|
wasm_context,
|
||||||
|
standard_properties,
|
||||||
|
{
|
||||||
|
Ok(WasmExampleBlock {
|
||||||
|
standard_properties,
|
||||||
|
children: Vec::new(),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
impl<'s, 'p> Into<WasmAstNode<'s, 'p>> for WasmExampleBlock<'s, 'p> {
|
||||||
|
fn into(self) -> WasmAstNode<'s, 'p> {
|
||||||
|
WasmAstNode::ExampleBlock(self)
|
||||||
|
}
|
||||||
|
}
|
||||||
36
src/wasm/export_block.rs
Normal file
36
src/wasm/export_block.rs
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
use serde::Serialize;
|
||||||
|
|
||||||
|
use super::macros::to_wasm;
|
||||||
|
use super::standard_properties::WasmStandardProperties;
|
||||||
|
use super::to_wasm::ToWasm;
|
||||||
|
use crate::types::ExportBlock;
|
||||||
|
use crate::wasm::to_wasm::ToWasmStandardProperties;
|
||||||
|
use crate::wasm::WasmAstNode;
|
||||||
|
|
||||||
|
#[derive(Debug, Serialize)]
|
||||||
|
#[serde(tag = "ast_node")]
|
||||||
|
#[serde(rename = "org-data")]
|
||||||
|
pub struct WasmExportBlock<'s, 'p> {
|
||||||
|
standard_properties: WasmStandardProperties,
|
||||||
|
children: Vec<WasmAstNode<'s, 'p>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
to_wasm!(
|
||||||
|
WasmExportBlock<'s, 'p>,
|
||||||
|
ExportBlock<'s>,
|
||||||
|
original,
|
||||||
|
wasm_context,
|
||||||
|
standard_properties,
|
||||||
|
{
|
||||||
|
Ok(WasmExportBlock {
|
||||||
|
standard_properties,
|
||||||
|
children: Vec::new(),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
impl<'s, 'p> Into<WasmAstNode<'s, 'p>> for WasmExportBlock<'s, 'p> {
|
||||||
|
fn into(self) -> WasmAstNode<'s, 'p> {
|
||||||
|
WasmAstNode::ExportBlock(self)
|
||||||
|
}
|
||||||
|
}
|
||||||
36
src/wasm/export_snippet.rs
Normal file
36
src/wasm/export_snippet.rs
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
use serde::Serialize;
|
||||||
|
|
||||||
|
use super::macros::to_wasm;
|
||||||
|
use super::standard_properties::WasmStandardProperties;
|
||||||
|
use super::to_wasm::ToWasm;
|
||||||
|
use crate::types::ExportSnippet;
|
||||||
|
use crate::wasm::to_wasm::ToWasmStandardProperties;
|
||||||
|
use crate::wasm::WasmAstNode;
|
||||||
|
|
||||||
|
#[derive(Debug, Serialize)]
|
||||||
|
#[serde(tag = "ast_node")]
|
||||||
|
#[serde(rename = "org-data")]
|
||||||
|
pub struct WasmExportSnippet<'s, 'p> {
|
||||||
|
standard_properties: WasmStandardProperties,
|
||||||
|
children: Vec<WasmAstNode<'s, 'p>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
to_wasm!(
|
||||||
|
WasmExportSnippet<'s, 'p>,
|
||||||
|
ExportSnippet<'s>,
|
||||||
|
original,
|
||||||
|
wasm_context,
|
||||||
|
standard_properties,
|
||||||
|
{
|
||||||
|
Ok(WasmExportSnippet {
|
||||||
|
standard_properties,
|
||||||
|
children: Vec::new(),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
impl<'s, 'p> Into<WasmAstNode<'s, 'p>> for WasmExportSnippet<'s, 'p> {
|
||||||
|
fn into(self) -> WasmAstNode<'s, 'p> {
|
||||||
|
WasmAstNode::ExportSnippet(self)
|
||||||
|
}
|
||||||
|
}
|
||||||
36
src/wasm/fixed_width_area.rs
Normal file
36
src/wasm/fixed_width_area.rs
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
use serde::Serialize;
|
||||||
|
|
||||||
|
use super::macros::to_wasm;
|
||||||
|
use super::standard_properties::WasmStandardProperties;
|
||||||
|
use super::to_wasm::ToWasm;
|
||||||
|
use crate::types::FixedWidthArea;
|
||||||
|
use crate::wasm::to_wasm::ToWasmStandardProperties;
|
||||||
|
use crate::wasm::WasmAstNode;
|
||||||
|
|
||||||
|
#[derive(Debug, Serialize)]
|
||||||
|
#[serde(tag = "ast_node")]
|
||||||
|
#[serde(rename = "org-data")]
|
||||||
|
pub struct WasmFixedWidthArea<'s, 'p> {
|
||||||
|
standard_properties: WasmStandardProperties,
|
||||||
|
children: Vec<WasmAstNode<'s, 'p>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
to_wasm!(
|
||||||
|
WasmFixedWidthArea<'s, 'p>,
|
||||||
|
FixedWidthArea<'s>,
|
||||||
|
original,
|
||||||
|
wasm_context,
|
||||||
|
standard_properties,
|
||||||
|
{
|
||||||
|
Ok(WasmFixedWidthArea {
|
||||||
|
standard_properties,
|
||||||
|
children: Vec::new(),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
impl<'s, 'p> Into<WasmAstNode<'s, 'p>> for WasmFixedWidthArea<'s, 'p> {
|
||||||
|
fn into(self) -> WasmAstNode<'s, 'p> {
|
||||||
|
WasmAstNode::FixedWidthArea(self)
|
||||||
|
}
|
||||||
|
}
|
||||||
36
src/wasm/footnote_definition.rs
Normal file
36
src/wasm/footnote_definition.rs
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
use serde::Serialize;
|
||||||
|
|
||||||
|
use super::macros::to_wasm;
|
||||||
|
use super::standard_properties::WasmStandardProperties;
|
||||||
|
use super::to_wasm::ToWasm;
|
||||||
|
use crate::types::FootnoteDefinition;
|
||||||
|
use crate::wasm::to_wasm::ToWasmStandardProperties;
|
||||||
|
use crate::wasm::WasmAstNode;
|
||||||
|
|
||||||
|
#[derive(Debug, Serialize)]
|
||||||
|
#[serde(tag = "ast_node")]
|
||||||
|
#[serde(rename = "org-data")]
|
||||||
|
pub struct WasmFootnoteDefinition<'s, 'p> {
|
||||||
|
standard_properties: WasmStandardProperties,
|
||||||
|
children: Vec<WasmAstNode<'s, 'p>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
to_wasm!(
|
||||||
|
WasmFootnoteDefinition<'s, 'p>,
|
||||||
|
FootnoteDefinition<'s>,
|
||||||
|
original,
|
||||||
|
wasm_context,
|
||||||
|
standard_properties,
|
||||||
|
{
|
||||||
|
Ok(WasmFootnoteDefinition {
|
||||||
|
standard_properties,
|
||||||
|
children: Vec::new(),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
impl<'s, 'p> Into<WasmAstNode<'s, 'p>> for WasmFootnoteDefinition<'s, 'p> {
|
||||||
|
fn into(self) -> WasmAstNode<'s, 'p> {
|
||||||
|
WasmAstNode::FootnoteDefinition(self)
|
||||||
|
}
|
||||||
|
}
|
||||||
36
src/wasm/footnote_reference.rs
Normal file
36
src/wasm/footnote_reference.rs
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
use serde::Serialize;
|
||||||
|
|
||||||
|
use super::macros::to_wasm;
|
||||||
|
use super::standard_properties::WasmStandardProperties;
|
||||||
|
use super::to_wasm::ToWasm;
|
||||||
|
use crate::types::FootnoteReference;
|
||||||
|
use crate::wasm::to_wasm::ToWasmStandardProperties;
|
||||||
|
use crate::wasm::WasmAstNode;
|
||||||
|
|
||||||
|
#[derive(Debug, Serialize)]
|
||||||
|
#[serde(tag = "ast_node")]
|
||||||
|
#[serde(rename = "org-data")]
|
||||||
|
pub struct WasmFootnoteReference<'s, 'p> {
|
||||||
|
standard_properties: WasmStandardProperties,
|
||||||
|
children: Vec<WasmAstNode<'s, 'p>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
to_wasm!(
|
||||||
|
WasmFootnoteReference<'s, 'p>,
|
||||||
|
FootnoteReference<'s>,
|
||||||
|
original,
|
||||||
|
wasm_context,
|
||||||
|
standard_properties,
|
||||||
|
{
|
||||||
|
Ok(WasmFootnoteReference {
|
||||||
|
standard_properties,
|
||||||
|
children: Vec::new(),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
impl<'s, 'p> Into<WasmAstNode<'s, 'p>> for WasmFootnoteReference<'s, 'p> {
|
||||||
|
fn into(self) -> WasmAstNode<'s, 'p> {
|
||||||
|
WasmAstNode::FootnoteReference(self)
|
||||||
|
}
|
||||||
|
}
|
||||||
36
src/wasm/headline.rs
Normal file
36
src/wasm/headline.rs
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
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::Heading;
|
||||||
|
use crate::wasm::to_wasm::ToWasmStandardProperties;
|
||||||
|
|
||||||
|
#[derive(Debug, Serialize)]
|
||||||
|
#[serde(tag = "ast_node")]
|
||||||
|
#[serde(rename = "headline")]
|
||||||
|
pub struct WasmHeadline<'s, 'p> {
|
||||||
|
standard_properties: WasmStandardProperties,
|
||||||
|
children: Vec<WasmAstNode<'s, 'p>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
to_wasm!(
|
||||||
|
WasmHeadline<'s, 'p>,
|
||||||
|
Heading<'s>,
|
||||||
|
original,
|
||||||
|
wasm_context,
|
||||||
|
standard_properties,
|
||||||
|
{
|
||||||
|
Ok(WasmHeadline {
|
||||||
|
standard_properties,
|
||||||
|
children: Vec::new(),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
impl<'s, 'p> Into<WasmAstNode<'s, 'p>> for WasmHeadline<'s, 'p> {
|
||||||
|
fn into(self) -> WasmAstNode<'s, 'p> {
|
||||||
|
WasmAstNode::Headline(self)
|
||||||
|
}
|
||||||
|
}
|
||||||
36
src/wasm/horizontal_rule.rs
Normal file
36
src/wasm/horizontal_rule.rs
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
use serde::Serialize;
|
||||||
|
|
||||||
|
use super::macros::to_wasm;
|
||||||
|
use super::standard_properties::WasmStandardProperties;
|
||||||
|
use super::to_wasm::ToWasm;
|
||||||
|
use crate::types::HorizontalRule;
|
||||||
|
use crate::wasm::to_wasm::ToWasmStandardProperties;
|
||||||
|
use crate::wasm::WasmAstNode;
|
||||||
|
|
||||||
|
#[derive(Debug, Serialize)]
|
||||||
|
#[serde(tag = "ast_node")]
|
||||||
|
#[serde(rename = "org-data")]
|
||||||
|
pub struct WasmHorizontalRule<'s, 'p> {
|
||||||
|
standard_properties: WasmStandardProperties,
|
||||||
|
children: Vec<WasmAstNode<'s, 'p>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
to_wasm!(
|
||||||
|
WasmHorizontalRule<'s, 'p>,
|
||||||
|
HorizontalRule<'s>,
|
||||||
|
original,
|
||||||
|
wasm_context,
|
||||||
|
standard_properties,
|
||||||
|
{
|
||||||
|
Ok(WasmHorizontalRule {
|
||||||
|
standard_properties,
|
||||||
|
children: Vec::new(),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
impl<'s, 'p> Into<WasmAstNode<'s, 'p>> for WasmHorizontalRule<'s, 'p> {
|
||||||
|
fn into(self) -> WasmAstNode<'s, 'p> {
|
||||||
|
WasmAstNode::HorizontalRule(self)
|
||||||
|
}
|
||||||
|
}
|
||||||
36
src/wasm/inline_babel_call.rs
Normal file
36
src/wasm/inline_babel_call.rs
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
use serde::Serialize;
|
||||||
|
|
||||||
|
use super::macros::to_wasm;
|
||||||
|
use super::standard_properties::WasmStandardProperties;
|
||||||
|
use super::to_wasm::ToWasm;
|
||||||
|
use crate::types::InlineBabelCall;
|
||||||
|
use crate::wasm::to_wasm::ToWasmStandardProperties;
|
||||||
|
use crate::wasm::WasmAstNode;
|
||||||
|
|
||||||
|
#[derive(Debug, Serialize)]
|
||||||
|
#[serde(tag = "ast_node")]
|
||||||
|
#[serde(rename = "org-data")]
|
||||||
|
pub struct WasmInlineBabelCall<'s, 'p> {
|
||||||
|
standard_properties: WasmStandardProperties,
|
||||||
|
children: Vec<WasmAstNode<'s, 'p>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
to_wasm!(
|
||||||
|
WasmInlineBabelCall<'s, 'p>,
|
||||||
|
InlineBabelCall<'s>,
|
||||||
|
original,
|
||||||
|
wasm_context,
|
||||||
|
standard_properties,
|
||||||
|
{
|
||||||
|
Ok(WasmInlineBabelCall {
|
||||||
|
standard_properties,
|
||||||
|
children: Vec::new(),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
impl<'s, 'p> Into<WasmAstNode<'s, 'p>> for WasmInlineBabelCall<'s, 'p> {
|
||||||
|
fn into(self) -> WasmAstNode<'s, 'p> {
|
||||||
|
WasmAstNode::InlineBabelCall(self)
|
||||||
|
}
|
||||||
|
}
|
||||||
36
src/wasm/inline_source_block.rs
Normal file
36
src/wasm/inline_source_block.rs
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
use serde::Serialize;
|
||||||
|
|
||||||
|
use super::macros::to_wasm;
|
||||||
|
use super::standard_properties::WasmStandardProperties;
|
||||||
|
use super::to_wasm::ToWasm;
|
||||||
|
use crate::types::InlineSourceBlock;
|
||||||
|
use crate::wasm::to_wasm::ToWasmStandardProperties;
|
||||||
|
use crate::wasm::WasmAstNode;
|
||||||
|
|
||||||
|
#[derive(Debug, Serialize)]
|
||||||
|
#[serde(tag = "ast_node")]
|
||||||
|
#[serde(rename = "org-data")]
|
||||||
|
pub struct WasmInlineSourceBlock<'s, 'p> {
|
||||||
|
standard_properties: WasmStandardProperties,
|
||||||
|
children: Vec<WasmAstNode<'s, 'p>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
to_wasm!(
|
||||||
|
WasmInlineSourceBlock<'s, 'p>,
|
||||||
|
InlineSourceBlock<'s>,
|
||||||
|
original,
|
||||||
|
wasm_context,
|
||||||
|
standard_properties,
|
||||||
|
{
|
||||||
|
Ok(WasmInlineSourceBlock {
|
||||||
|
standard_properties,
|
||||||
|
children: Vec::new(),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
impl<'s, 'p> Into<WasmAstNode<'s, 'p>> for WasmInlineSourceBlock<'s, 'p> {
|
||||||
|
fn into(self) -> WasmAstNode<'s, 'p> {
|
||||||
|
WasmAstNode::InlineSourceBlock(self)
|
||||||
|
}
|
||||||
|
}
|
||||||
36
src/wasm/italic.rs
Normal file
36
src/wasm/italic.rs
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
use serde::Serialize;
|
||||||
|
|
||||||
|
use super::macros::to_wasm;
|
||||||
|
use super::standard_properties::WasmStandardProperties;
|
||||||
|
use super::to_wasm::ToWasm;
|
||||||
|
use crate::types::Italic;
|
||||||
|
use crate::wasm::to_wasm::ToWasmStandardProperties;
|
||||||
|
use crate::wasm::WasmAstNode;
|
||||||
|
|
||||||
|
#[derive(Debug, Serialize)]
|
||||||
|
#[serde(tag = "ast_node")]
|
||||||
|
#[serde(rename = "org-data")]
|
||||||
|
pub struct WasmItalic<'s, 'p> {
|
||||||
|
standard_properties: WasmStandardProperties,
|
||||||
|
children: Vec<WasmAstNode<'s, 'p>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
to_wasm!(
|
||||||
|
WasmItalic<'s, 'p>,
|
||||||
|
Italic<'s>,
|
||||||
|
original,
|
||||||
|
wasm_context,
|
||||||
|
standard_properties,
|
||||||
|
{
|
||||||
|
Ok(WasmItalic {
|
||||||
|
standard_properties,
|
||||||
|
children: Vec::new(),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
impl<'s, 'p> Into<WasmAstNode<'s, 'p>> for WasmItalic<'s, 'p> {
|
||||||
|
fn into(self) -> WasmAstNode<'s, 'p> {
|
||||||
|
WasmAstNode::Italic(self)
|
||||||
|
}
|
||||||
|
}
|
||||||
36
src/wasm/keyword.rs
Normal file
36
src/wasm/keyword.rs
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
use serde::Serialize;
|
||||||
|
|
||||||
|
use super::macros::to_wasm;
|
||||||
|
use super::standard_properties::WasmStandardProperties;
|
||||||
|
use super::to_wasm::ToWasm;
|
||||||
|
use crate::types::Keyword;
|
||||||
|
use crate::wasm::to_wasm::ToWasmStandardProperties;
|
||||||
|
use crate::wasm::WasmAstNode;
|
||||||
|
|
||||||
|
#[derive(Debug, Serialize)]
|
||||||
|
#[serde(tag = "ast_node")]
|
||||||
|
#[serde(rename = "org-data")]
|
||||||
|
pub struct WasmKeyword<'s, 'p> {
|
||||||
|
standard_properties: WasmStandardProperties,
|
||||||
|
children: Vec<WasmAstNode<'s, 'p>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
to_wasm!(
|
||||||
|
WasmKeyword<'s, 'p>,
|
||||||
|
Keyword<'s>,
|
||||||
|
original,
|
||||||
|
wasm_context,
|
||||||
|
standard_properties,
|
||||||
|
{
|
||||||
|
Ok(WasmKeyword {
|
||||||
|
standard_properties,
|
||||||
|
children: Vec::new(),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
impl<'s, 'p> Into<WasmAstNode<'s, 'p>> for WasmKeyword<'s, 'p> {
|
||||||
|
fn into(self) -> WasmAstNode<'s, 'p> {
|
||||||
|
WasmAstNode::Keyword(self)
|
||||||
|
}
|
||||||
|
}
|
||||||
36
src/wasm/latex_environment.rs
Normal file
36
src/wasm/latex_environment.rs
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
use serde::Serialize;
|
||||||
|
|
||||||
|
use super::macros::to_wasm;
|
||||||
|
use super::standard_properties::WasmStandardProperties;
|
||||||
|
use super::to_wasm::ToWasm;
|
||||||
|
use crate::types::LatexEnvironment;
|
||||||
|
use crate::wasm::to_wasm::ToWasmStandardProperties;
|
||||||
|
use crate::wasm::WasmAstNode;
|
||||||
|
|
||||||
|
#[derive(Debug, Serialize)]
|
||||||
|
#[serde(tag = "ast_node")]
|
||||||
|
#[serde(rename = "org-data")]
|
||||||
|
pub struct WasmLatexEnvironment<'s, 'p> {
|
||||||
|
standard_properties: WasmStandardProperties,
|
||||||
|
children: Vec<WasmAstNode<'s, 'p>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
to_wasm!(
|
||||||
|
WasmLatexEnvironment<'s, 'p>,
|
||||||
|
LatexEnvironment<'s>,
|
||||||
|
original,
|
||||||
|
wasm_context,
|
||||||
|
standard_properties,
|
||||||
|
{
|
||||||
|
Ok(WasmLatexEnvironment {
|
||||||
|
standard_properties,
|
||||||
|
children: Vec::new(),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
impl<'s, 'p> Into<WasmAstNode<'s, 'p>> for WasmLatexEnvironment<'s, 'p> {
|
||||||
|
fn into(self) -> WasmAstNode<'s, 'p> {
|
||||||
|
WasmAstNode::LatexEnvironment(self)
|
||||||
|
}
|
||||||
|
}
|
||||||
36
src/wasm/latex_fragment.rs
Normal file
36
src/wasm/latex_fragment.rs
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
use serde::Serialize;
|
||||||
|
|
||||||
|
use super::macros::to_wasm;
|
||||||
|
use super::standard_properties::WasmStandardProperties;
|
||||||
|
use super::to_wasm::ToWasm;
|
||||||
|
use crate::types::LatexFragment;
|
||||||
|
use crate::wasm::to_wasm::ToWasmStandardProperties;
|
||||||
|
use crate::wasm::WasmAstNode;
|
||||||
|
|
||||||
|
#[derive(Debug, Serialize)]
|
||||||
|
#[serde(tag = "ast_node")]
|
||||||
|
#[serde(rename = "org-data")]
|
||||||
|
pub struct WasmLatexFragment<'s, 'p> {
|
||||||
|
standard_properties: WasmStandardProperties,
|
||||||
|
children: Vec<WasmAstNode<'s, 'p>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
to_wasm!(
|
||||||
|
WasmLatexFragment<'s, 'p>,
|
||||||
|
LatexFragment<'s>,
|
||||||
|
original,
|
||||||
|
wasm_context,
|
||||||
|
standard_properties,
|
||||||
|
{
|
||||||
|
Ok(WasmLatexFragment {
|
||||||
|
standard_properties,
|
||||||
|
children: Vec::new(),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
impl<'s, 'p> Into<WasmAstNode<'s, 'p>> for WasmLatexFragment<'s, 'p> {
|
||||||
|
fn into(self) -> WasmAstNode<'s, 'p> {
|
||||||
|
WasmAstNode::LatexFragment(self)
|
||||||
|
}
|
||||||
|
}
|
||||||
36
src/wasm/line_break.rs
Normal file
36
src/wasm/line_break.rs
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
use serde::Serialize;
|
||||||
|
|
||||||
|
use super::macros::to_wasm;
|
||||||
|
use super::standard_properties::WasmStandardProperties;
|
||||||
|
use super::to_wasm::ToWasm;
|
||||||
|
use crate::types::LineBreak;
|
||||||
|
use crate::wasm::to_wasm::ToWasmStandardProperties;
|
||||||
|
use crate::wasm::WasmAstNode;
|
||||||
|
|
||||||
|
#[derive(Debug, Serialize)]
|
||||||
|
#[serde(tag = "ast_node")]
|
||||||
|
#[serde(rename = "org-data")]
|
||||||
|
pub struct WasmLineBreak<'s, 'p> {
|
||||||
|
standard_properties: WasmStandardProperties,
|
||||||
|
children: Vec<WasmAstNode<'s, 'p>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
to_wasm!(
|
||||||
|
WasmLineBreak<'s, 'p>,
|
||||||
|
LineBreak<'s>,
|
||||||
|
original,
|
||||||
|
wasm_context,
|
||||||
|
standard_properties,
|
||||||
|
{
|
||||||
|
Ok(WasmLineBreak {
|
||||||
|
standard_properties,
|
||||||
|
children: Vec::new(),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
impl<'s, 'p> Into<WasmAstNode<'s, 'p>> for WasmLineBreak<'s, 'p> {
|
||||||
|
fn into(self) -> WasmAstNode<'s, 'p> {
|
||||||
|
WasmAstNode::LineBreak(self)
|
||||||
|
}
|
||||||
|
}
|
||||||
35
src/wasm/macros.rs
Normal file
35
src/wasm/macros.rs
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
/// 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, $fnbody:tt) => {
|
||||||
|
impl<'s, 'p> ToWasm<'p> for $istruct {
|
||||||
|
type Output = $ostruct;
|
||||||
|
|
||||||
|
fn to_wasm(
|
||||||
|
&'p self,
|
||||||
|
$wasm_context: crate::wasm::to_wasm::ToWasmContext<'_>,
|
||||||
|
) -> Result<Self::Output, crate::error::CustomError> {
|
||||||
|
let $original = self;
|
||||||
|
$fnbody
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
($ostruct:ty, $istruct:ty, $original:ident, $wasm_context:ident, $standard_properties:ident, $fnbody:tt) => {
|
||||||
|
impl<'s, 'p> ToWasm<'p> for $istruct {
|
||||||
|
type Output = $ostruct;
|
||||||
|
|
||||||
|
fn to_wasm(
|
||||||
|
&'p 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;
|
||||||
130
src/wasm/mod.rs
Normal file
130
src/wasm/mod.rs
Normal file
@@ -0,0 +1,130 @@
|
|||||||
|
mod additional_property;
|
||||||
|
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 additional_property::AdditionalProperties;
|
||||||
|
pub use additional_property::AdditionalPropertyValue;
|
||||||
|
pub(crate) use angle_link::WasmAngleLink;
|
||||||
|
pub use ast_node::WasmAstNode;
|
||||||
|
pub(crate) use babel_call::WasmBabelCall;
|
||||||
|
pub(crate) use bold::WasmBold;
|
||||||
|
pub(crate) use center_block::WasmCenterBlock;
|
||||||
|
pub(crate) use citation::WasmCitation;
|
||||||
|
pub(crate) use citation_reference::WasmCitationReference;
|
||||||
|
pub(crate) use clock::WasmClock;
|
||||||
|
pub(crate) use code::WasmCode;
|
||||||
|
pub(crate) use comment::WasmComment;
|
||||||
|
pub(crate) use comment_block::WasmCommentBlock;
|
||||||
|
pub(crate) use diary_sexp::WasmDiarySexp;
|
||||||
|
pub use document::WasmDocument;
|
||||||
|
pub(crate) use drawer::WasmDrawer;
|
||||||
|
pub(crate) use dynamic_block::WasmDynamicBlock;
|
||||||
|
pub(crate) use entity::WasmEntity;
|
||||||
|
pub(crate) use example_block::WasmExampleBlock;
|
||||||
|
pub(crate) use export_block::WasmExportBlock;
|
||||||
|
pub(crate) use export_snippet::WasmExportSnippet;
|
||||||
|
pub(crate) use fixed_width_area::WasmFixedWidthArea;
|
||||||
|
pub(crate) use footnote_definition::WasmFootnoteDefinition;
|
||||||
|
pub(crate) use footnote_reference::WasmFootnoteReference;
|
||||||
|
pub(crate) use headline::WasmHeadline;
|
||||||
|
pub(crate) use horizontal_rule::WasmHorizontalRule;
|
||||||
|
pub(crate) use inline_babel_call::WasmInlineBabelCall;
|
||||||
|
pub(crate) use inline_source_block::WasmInlineSourceBlock;
|
||||||
|
pub(crate) use italic::WasmItalic;
|
||||||
|
pub(crate) use keyword::WasmKeyword;
|
||||||
|
pub(crate) use latex_environment::WasmLatexEnvironment;
|
||||||
|
pub(crate) use latex_fragment::WasmLatexFragment;
|
||||||
|
pub(crate) use line_break::WasmLineBreak;
|
||||||
|
pub(crate) use node_property::WasmNodeProperty;
|
||||||
|
pub(crate) use org_macro::WasmOrgMacro;
|
||||||
|
pub(crate) use paragraph::WasmParagraph;
|
||||||
|
pub use parse_result::ParseResult;
|
||||||
|
pub(crate) use plain_link::WasmPlainLink;
|
||||||
|
pub(crate) use plain_list::WasmPlainList;
|
||||||
|
pub(crate) use plain_list_item::WasmPlainListItem;
|
||||||
|
pub(crate) use plain_text::WasmPlainText;
|
||||||
|
pub(crate) use planning::WasmPlanning;
|
||||||
|
pub(crate) use property_drawer::WasmPropertyDrawer;
|
||||||
|
pub(crate) use quote_block::WasmQuoteBlock;
|
||||||
|
pub(crate) use radio_link::WasmRadioLink;
|
||||||
|
pub(crate) use radio_target::WasmRadioTarget;
|
||||||
|
pub(crate) use regular_link::WasmRegularLink;
|
||||||
|
pub(crate) use section::WasmSection;
|
||||||
|
pub(crate) use special_block::WasmSpecialBlock;
|
||||||
|
pub(crate) use src_block::WasmSrcBlock;
|
||||||
|
pub(crate) use standard_properties::WasmStandardProperties;
|
||||||
|
pub(crate) use statistics_cookie::WasmStatisticsCookie;
|
||||||
|
pub(crate) use strike_through::WasmStrikeThrough;
|
||||||
|
pub(crate) use subscript::WasmSubscript;
|
||||||
|
pub(crate) use superscript::WasmSuperscript;
|
||||||
|
pub(crate) use table::WasmTable;
|
||||||
|
pub(crate) use table_cell::WasmTableCell;
|
||||||
|
pub(crate) use table_row::WasmTableRow;
|
||||||
|
pub(crate) use target::WasmTarget;
|
||||||
|
pub(crate) use timestamp::WasmTimestamp;
|
||||||
|
pub use to_wasm::ToWasm;
|
||||||
|
pub use to_wasm::ToWasmContext;
|
||||||
|
pub(crate) use underline::WasmUnderline;
|
||||||
|
pub(crate) use verbatim::WasmVerbatim;
|
||||||
|
pub(crate) use verse_block::WasmVerseBlock;
|
||||||
30
src/wasm/node_property.rs
Normal file
30
src/wasm/node_property.rs
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
use serde::Serialize;
|
||||||
|
|
||||||
|
use super::macros::to_wasm;
|
||||||
|
use super::standard_properties::WasmStandardProperties;
|
||||||
|
use super::to_wasm::ToWasm;
|
||||||
|
use crate::types::NodeProperty;
|
||||||
|
use crate::wasm::to_wasm::ToWasmStandardProperties;
|
||||||
|
use crate::wasm::WasmAstNode;
|
||||||
|
|
||||||
|
#[derive(Debug, Serialize)]
|
||||||
|
#[serde(tag = "ast_node")]
|
||||||
|
#[serde(rename = "org-data")]
|
||||||
|
pub struct WasmNodeProperty<'s, 'p> {
|
||||||
|
standard_properties: WasmStandardProperties,
|
||||||
|
children: Vec<WasmAstNode<'s, 'p>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
to_wasm!(
|
||||||
|
WasmNodeProperty<'s, 'p>,
|
||||||
|
NodeProperty<'s>,
|
||||||
|
original,
|
||||||
|
wasm_context,
|
||||||
|
standard_properties,
|
||||||
|
{
|
||||||
|
Ok(WasmNodeProperty {
|
||||||
|
standard_properties,
|
||||||
|
children: Vec::new(),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
);
|
||||||
36
src/wasm/org_macro.rs
Normal file
36
src/wasm/org_macro.rs
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
use serde::Serialize;
|
||||||
|
|
||||||
|
use super::macros::to_wasm;
|
||||||
|
use super::standard_properties::WasmStandardProperties;
|
||||||
|
use super::to_wasm::ToWasm;
|
||||||
|
use crate::types::OrgMacro;
|
||||||
|
use crate::wasm::to_wasm::ToWasmStandardProperties;
|
||||||
|
use crate::wasm::WasmAstNode;
|
||||||
|
|
||||||
|
#[derive(Debug, Serialize)]
|
||||||
|
#[serde(tag = "ast_node")]
|
||||||
|
#[serde(rename = "org-data")]
|
||||||
|
pub struct WasmOrgMacro<'s, 'p> {
|
||||||
|
standard_properties: WasmStandardProperties,
|
||||||
|
children: Vec<WasmAstNode<'s, 'p>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
to_wasm!(
|
||||||
|
WasmOrgMacro<'s, 'p>,
|
||||||
|
OrgMacro<'s>,
|
||||||
|
original,
|
||||||
|
wasm_context,
|
||||||
|
standard_properties,
|
||||||
|
{
|
||||||
|
Ok(WasmOrgMacro {
|
||||||
|
standard_properties,
|
||||||
|
children: Vec::new(),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
impl<'s, 'p> Into<WasmAstNode<'s, 'p>> for WasmOrgMacro<'s, 'p> {
|
||||||
|
fn into(self) -> WasmAstNode<'s, 'p> {
|
||||||
|
WasmAstNode::OrgMacro(self)
|
||||||
|
}
|
||||||
|
}
|
||||||
64
src/wasm/paragraph.rs
Normal file
64
src/wasm/paragraph.rs
Normal file
@@ -0,0 +1,64 @@
|
|||||||
|
use serde::Serialize;
|
||||||
|
|
||||||
|
use super::macros::to_wasm;
|
||||||
|
use super::standard_properties::WasmStandardProperties;
|
||||||
|
use super::to_wasm::ToWasm;
|
||||||
|
use super::AdditionalProperties;
|
||||||
|
#[cfg(feature = "wasm_test")]
|
||||||
|
use crate::compare::ElispFact;
|
||||||
|
use crate::types::GetAffiliatedKeywords;
|
||||||
|
use crate::types::Paragraph;
|
||||||
|
use crate::wasm::to_wasm::ToWasmStandardProperties;
|
||||||
|
use crate::wasm::WasmAstNode;
|
||||||
|
|
||||||
|
#[derive(Debug, Serialize)]
|
||||||
|
#[serde(tag = "ast_node")]
|
||||||
|
#[serde(rename = "paragraph")]
|
||||||
|
pub struct WasmParagraph<'s, 'p> {
|
||||||
|
pub(crate) standard_properties: WasmStandardProperties,
|
||||||
|
#[serde(flatten)]
|
||||||
|
pub(crate) additional_properties: AdditionalProperties<'s, 'p>,
|
||||||
|
pub(crate) children: Vec<WasmAstNode<'s, 'p>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
to_wasm!(
|
||||||
|
WasmParagraph<'s, 'p>,
|
||||||
|
Paragraph<'s>,
|
||||||
|
original,
|
||||||
|
wasm_context,
|
||||||
|
standard_properties,
|
||||||
|
{
|
||||||
|
let additional_properties = original
|
||||||
|
.get_affiliated_keywords()
|
||||||
|
.to_wasm(wasm_context.clone())?;
|
||||||
|
|
||||||
|
let children = original
|
||||||
|
.children
|
||||||
|
.iter()
|
||||||
|
.map(|child| {
|
||||||
|
child
|
||||||
|
.to_wasm(wasm_context.clone())
|
||||||
|
.map(Into::<WasmAstNode<'_, '_>>::into)
|
||||||
|
})
|
||||||
|
.collect::<Result<Vec<_>, _>>()?;
|
||||||
|
|
||||||
|
Ok(WasmParagraph {
|
||||||
|
standard_properties,
|
||||||
|
additional_properties,
|
||||||
|
children,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
impl<'s, 'p> Into<WasmAstNode<'s, 'p>> for WasmParagraph<'s, 'p> {
|
||||||
|
fn into(self) -> WasmAstNode<'s, 'p> {
|
||||||
|
WasmAstNode::Paragraph(self)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "wasm_test")]
|
||||||
|
impl<'s, 'p> ElispFact<'s> for WasmParagraph<'s, 'p> {
|
||||||
|
fn get_elisp_name<'b>(&'b self) -> std::borrow::Cow<'s, str> {
|
||||||
|
"paragraph".into()
|
||||||
|
}
|
||||||
|
}
|
||||||
13
src/wasm/parse_result.rs
Normal file
13
src/wasm/parse_result.rs
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
use serde::Serialize;
|
||||||
|
|
||||||
|
use super::document::WasmDocument;
|
||||||
|
|
||||||
|
#[derive(Debug, Serialize)]
|
||||||
|
#[serde(tag = "status", content = "content")]
|
||||||
|
pub enum ParseResult<'s, 'p> {
|
||||||
|
#[serde(rename = "success")]
|
||||||
|
Success(WasmDocument<'s, 'p>),
|
||||||
|
|
||||||
|
#[serde(rename = "error")]
|
||||||
|
Error(String),
|
||||||
|
}
|
||||||
36
src/wasm/plain_link.rs
Normal file
36
src/wasm/plain_link.rs
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
use serde::Serialize;
|
||||||
|
|
||||||
|
use super::macros::to_wasm;
|
||||||
|
use super::standard_properties::WasmStandardProperties;
|
||||||
|
use super::to_wasm::ToWasm;
|
||||||
|
use crate::types::PlainLink;
|
||||||
|
use crate::wasm::to_wasm::ToWasmStandardProperties;
|
||||||
|
use crate::wasm::WasmAstNode;
|
||||||
|
|
||||||
|
#[derive(Debug, Serialize)]
|
||||||
|
#[serde(tag = "ast_node")]
|
||||||
|
#[serde(rename = "org-data")]
|
||||||
|
pub struct WasmPlainLink<'s, 'p> {
|
||||||
|
standard_properties: WasmStandardProperties,
|
||||||
|
children: Vec<WasmAstNode<'s, 'p>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
to_wasm!(
|
||||||
|
WasmPlainLink<'s, 'p>,
|
||||||
|
PlainLink<'s>,
|
||||||
|
original,
|
||||||
|
wasm_context,
|
||||||
|
standard_properties,
|
||||||
|
{
|
||||||
|
Ok(WasmPlainLink {
|
||||||
|
standard_properties,
|
||||||
|
children: Vec::new(),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
impl<'s, 'p> Into<WasmAstNode<'s, 'p>> for WasmPlainLink<'s, 'p> {
|
||||||
|
fn into(self) -> WasmAstNode<'s, 'p> {
|
||||||
|
WasmAstNode::PlainLink(self)
|
||||||
|
}
|
||||||
|
}
|
||||||
36
src/wasm/plain_list.rs
Normal file
36
src/wasm/plain_list.rs
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
use serde::Serialize;
|
||||||
|
|
||||||
|
use super::macros::to_wasm;
|
||||||
|
use super::standard_properties::WasmStandardProperties;
|
||||||
|
use super::to_wasm::ToWasm;
|
||||||
|
use crate::types::PlainList;
|
||||||
|
use crate::wasm::to_wasm::ToWasmStandardProperties;
|
||||||
|
use crate::wasm::WasmAstNode;
|
||||||
|
|
||||||
|
#[derive(Debug, Serialize)]
|
||||||
|
#[serde(tag = "ast_node")]
|
||||||
|
#[serde(rename = "org-data")]
|
||||||
|
pub struct WasmPlainList<'s, 'p> {
|
||||||
|
standard_properties: WasmStandardProperties,
|
||||||
|
children: Vec<WasmAstNode<'s, 'p>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
to_wasm!(
|
||||||
|
WasmPlainList<'s, 'p>,
|
||||||
|
PlainList<'s>,
|
||||||
|
original,
|
||||||
|
wasm_context,
|
||||||
|
standard_properties,
|
||||||
|
{
|
||||||
|
Ok(WasmPlainList {
|
||||||
|
standard_properties,
|
||||||
|
children: Vec::new(),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
impl<'s, 'p> Into<WasmAstNode<'s, 'p>> for WasmPlainList<'s, 'p> {
|
||||||
|
fn into(self) -> WasmAstNode<'s, 'p> {
|
||||||
|
WasmAstNode::PlainList(self)
|
||||||
|
}
|
||||||
|
}
|
||||||
30
src/wasm/plain_list_item.rs
Normal file
30
src/wasm/plain_list_item.rs
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
use serde::Serialize;
|
||||||
|
|
||||||
|
use super::macros::to_wasm;
|
||||||
|
use super::standard_properties::WasmStandardProperties;
|
||||||
|
use super::to_wasm::ToWasm;
|
||||||
|
use crate::types::PlainListItem;
|
||||||
|
use crate::wasm::to_wasm::ToWasmStandardProperties;
|
||||||
|
use crate::wasm::WasmAstNode;
|
||||||
|
|
||||||
|
#[derive(Debug, Serialize)]
|
||||||
|
#[serde(tag = "ast_node")]
|
||||||
|
#[serde(rename = "org-data")]
|
||||||
|
pub struct WasmPlainListItem<'s, 'p> {
|
||||||
|
standard_properties: WasmStandardProperties,
|
||||||
|
children: Vec<WasmAstNode<'s, 'p>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
to_wasm!(
|
||||||
|
WasmPlainListItem<'s, 'p>,
|
||||||
|
PlainListItem<'s>,
|
||||||
|
original,
|
||||||
|
wasm_context,
|
||||||
|
standard_properties,
|
||||||
|
{
|
||||||
|
Ok(WasmPlainListItem {
|
||||||
|
standard_properties,
|
||||||
|
children: Vec::new(),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
);
|
||||||
36
src/wasm/plain_text.rs
Normal file
36
src/wasm/plain_text.rs
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
use serde::Serialize;
|
||||||
|
|
||||||
|
use super::macros::to_wasm;
|
||||||
|
use super::standard_properties::WasmStandardProperties;
|
||||||
|
use super::to_wasm::ToWasm;
|
||||||
|
use crate::types::PlainText;
|
||||||
|
use crate::wasm::to_wasm::ToWasmStandardProperties;
|
||||||
|
use crate::wasm::WasmAstNode;
|
||||||
|
|
||||||
|
#[derive(Debug, Serialize)]
|
||||||
|
#[serde(tag = "ast_node")]
|
||||||
|
#[serde(rename = "org-data")]
|
||||||
|
pub struct WasmPlainText<'s, 'p> {
|
||||||
|
standard_properties: WasmStandardProperties,
|
||||||
|
children: Vec<WasmAstNode<'s, 'p>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
to_wasm!(
|
||||||
|
WasmPlainText<'s, 'p>,
|
||||||
|
PlainText<'s>,
|
||||||
|
original,
|
||||||
|
wasm_context,
|
||||||
|
standard_properties,
|
||||||
|
{
|
||||||
|
Ok(WasmPlainText {
|
||||||
|
standard_properties,
|
||||||
|
children: Vec::new(),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
impl<'s, 'p> Into<WasmAstNode<'s, 'p>> for WasmPlainText<'s, 'p> {
|
||||||
|
fn into(self) -> WasmAstNode<'s, 'p> {
|
||||||
|
WasmAstNode::PlainText(self)
|
||||||
|
}
|
||||||
|
}
|
||||||
36
src/wasm/planning.rs
Normal file
36
src/wasm/planning.rs
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
use serde::Serialize;
|
||||||
|
|
||||||
|
use super::macros::to_wasm;
|
||||||
|
use super::standard_properties::WasmStandardProperties;
|
||||||
|
use super::to_wasm::ToWasm;
|
||||||
|
use crate::types::Planning;
|
||||||
|
use crate::wasm::to_wasm::ToWasmStandardProperties;
|
||||||
|
use crate::wasm::WasmAstNode;
|
||||||
|
|
||||||
|
#[derive(Debug, Serialize)]
|
||||||
|
#[serde(tag = "ast_node")]
|
||||||
|
#[serde(rename = "org-data")]
|
||||||
|
pub struct WasmPlanning<'s, 'p> {
|
||||||
|
standard_properties: WasmStandardProperties,
|
||||||
|
children: Vec<WasmAstNode<'s, 'p>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
to_wasm!(
|
||||||
|
WasmPlanning<'s, 'p>,
|
||||||
|
Planning<'s>,
|
||||||
|
original,
|
||||||
|
wasm_context,
|
||||||
|
standard_properties,
|
||||||
|
{
|
||||||
|
Ok(WasmPlanning {
|
||||||
|
standard_properties,
|
||||||
|
children: Vec::new(),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
impl<'s, 'p> Into<WasmAstNode<'s, 'p>> for WasmPlanning<'s, 'p> {
|
||||||
|
fn into(self) -> WasmAstNode<'s, 'p> {
|
||||||
|
WasmAstNode::Planning(self)
|
||||||
|
}
|
||||||
|
}
|
||||||
36
src/wasm/property_drawer.rs
Normal file
36
src/wasm/property_drawer.rs
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
use serde::Serialize;
|
||||||
|
|
||||||
|
use super::macros::to_wasm;
|
||||||
|
use super::standard_properties::WasmStandardProperties;
|
||||||
|
use super::to_wasm::ToWasm;
|
||||||
|
use crate::types::PropertyDrawer;
|
||||||
|
use crate::wasm::to_wasm::ToWasmStandardProperties;
|
||||||
|
use crate::wasm::WasmAstNode;
|
||||||
|
|
||||||
|
#[derive(Debug, Serialize)]
|
||||||
|
#[serde(tag = "ast_node")]
|
||||||
|
#[serde(rename = "org-data")]
|
||||||
|
pub struct WasmPropertyDrawer<'s, 'p> {
|
||||||
|
standard_properties: WasmStandardProperties,
|
||||||
|
children: Vec<WasmAstNode<'s, 'p>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
to_wasm!(
|
||||||
|
WasmPropertyDrawer<'s, 'p>,
|
||||||
|
PropertyDrawer<'s>,
|
||||||
|
original,
|
||||||
|
wasm_context,
|
||||||
|
standard_properties,
|
||||||
|
{
|
||||||
|
Ok(WasmPropertyDrawer {
|
||||||
|
standard_properties,
|
||||||
|
children: Vec::new(),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
impl<'s, 'p> Into<WasmAstNode<'s, 'p>> for WasmPropertyDrawer<'s, 'p> {
|
||||||
|
fn into(self) -> WasmAstNode<'s, 'p> {
|
||||||
|
WasmAstNode::PropertyDrawer(self)
|
||||||
|
}
|
||||||
|
}
|
||||||
36
src/wasm/quote_block.rs
Normal file
36
src/wasm/quote_block.rs
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
use serde::Serialize;
|
||||||
|
|
||||||
|
use super::macros::to_wasm;
|
||||||
|
use super::standard_properties::WasmStandardProperties;
|
||||||
|
use super::to_wasm::ToWasm;
|
||||||
|
use crate::types::QuoteBlock;
|
||||||
|
use crate::wasm::to_wasm::ToWasmStandardProperties;
|
||||||
|
use crate::wasm::WasmAstNode;
|
||||||
|
|
||||||
|
#[derive(Debug, Serialize)]
|
||||||
|
#[serde(tag = "ast_node")]
|
||||||
|
#[serde(rename = "org-data")]
|
||||||
|
pub struct WasmQuoteBlock<'s, 'p> {
|
||||||
|
standard_properties: WasmStandardProperties,
|
||||||
|
children: Vec<WasmAstNode<'s, 'p>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
to_wasm!(
|
||||||
|
WasmQuoteBlock<'s, 'p>,
|
||||||
|
QuoteBlock<'s>,
|
||||||
|
original,
|
||||||
|
wasm_context,
|
||||||
|
standard_properties,
|
||||||
|
{
|
||||||
|
Ok(WasmQuoteBlock {
|
||||||
|
standard_properties,
|
||||||
|
children: Vec::new(),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
impl<'s, 'p> Into<WasmAstNode<'s, 'p>> for WasmQuoteBlock<'s, 'p> {
|
||||||
|
fn into(self) -> WasmAstNode<'s, 'p> {
|
||||||
|
WasmAstNode::QuoteBlock(self)
|
||||||
|
}
|
||||||
|
}
|
||||||
36
src/wasm/radio_link.rs
Normal file
36
src/wasm/radio_link.rs
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
use serde::Serialize;
|
||||||
|
|
||||||
|
use super::macros::to_wasm;
|
||||||
|
use super::standard_properties::WasmStandardProperties;
|
||||||
|
use super::to_wasm::ToWasm;
|
||||||
|
use crate::types::RadioLink;
|
||||||
|
use crate::wasm::to_wasm::ToWasmStandardProperties;
|
||||||
|
use crate::wasm::WasmAstNode;
|
||||||
|
|
||||||
|
#[derive(Debug, Serialize)]
|
||||||
|
#[serde(tag = "ast_node")]
|
||||||
|
#[serde(rename = "org-data")]
|
||||||
|
pub struct WasmRadioLink<'s, 'p> {
|
||||||
|
standard_properties: WasmStandardProperties,
|
||||||
|
children: Vec<WasmAstNode<'s, 'p>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
to_wasm!(
|
||||||
|
WasmRadioLink<'s, 'p>,
|
||||||
|
RadioLink<'s>,
|
||||||
|
original,
|
||||||
|
wasm_context,
|
||||||
|
standard_properties,
|
||||||
|
{
|
||||||
|
Ok(WasmRadioLink {
|
||||||
|
standard_properties,
|
||||||
|
children: Vec::new(),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
impl<'s, 'p> Into<WasmAstNode<'s, 'p>> for WasmRadioLink<'s, 'p> {
|
||||||
|
fn into(self) -> WasmAstNode<'s, 'p> {
|
||||||
|
WasmAstNode::RadioLink(self)
|
||||||
|
}
|
||||||
|
}
|
||||||
36
src/wasm/radio_target.rs
Normal file
36
src/wasm/radio_target.rs
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
use serde::Serialize;
|
||||||
|
|
||||||
|
use super::macros::to_wasm;
|
||||||
|
use super::standard_properties::WasmStandardProperties;
|
||||||
|
use super::to_wasm::ToWasm;
|
||||||
|
use crate::types::RadioTarget;
|
||||||
|
use crate::wasm::to_wasm::ToWasmStandardProperties;
|
||||||
|
use crate::wasm::WasmAstNode;
|
||||||
|
|
||||||
|
#[derive(Debug, Serialize)]
|
||||||
|
#[serde(tag = "ast_node")]
|
||||||
|
#[serde(rename = "org-data")]
|
||||||
|
pub struct WasmRadioTarget<'s, 'p> {
|
||||||
|
standard_properties: WasmStandardProperties,
|
||||||
|
children: Vec<WasmAstNode<'s, 'p>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
to_wasm!(
|
||||||
|
WasmRadioTarget<'s, 'p>,
|
||||||
|
RadioTarget<'s>,
|
||||||
|
original,
|
||||||
|
wasm_context,
|
||||||
|
standard_properties,
|
||||||
|
{
|
||||||
|
Ok(WasmRadioTarget {
|
||||||
|
standard_properties,
|
||||||
|
children: Vec::new(),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
impl<'s, 'p> Into<WasmAstNode<'s, 'p>> for WasmRadioTarget<'s, 'p> {
|
||||||
|
fn into(self) -> WasmAstNode<'s, 'p> {
|
||||||
|
WasmAstNode::RadioTarget(self)
|
||||||
|
}
|
||||||
|
}
|
||||||
36
src/wasm/regular_link.rs
Normal file
36
src/wasm/regular_link.rs
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
use serde::Serialize;
|
||||||
|
|
||||||
|
use super::macros::to_wasm;
|
||||||
|
use super::standard_properties::WasmStandardProperties;
|
||||||
|
use super::to_wasm::ToWasm;
|
||||||
|
use crate::types::RegularLink;
|
||||||
|
use crate::wasm::to_wasm::ToWasmStandardProperties;
|
||||||
|
use crate::wasm::WasmAstNode;
|
||||||
|
|
||||||
|
#[derive(Debug, Serialize)]
|
||||||
|
#[serde(tag = "ast_node")]
|
||||||
|
#[serde(rename = "org-data")]
|
||||||
|
pub struct WasmRegularLink<'s, 'p> {
|
||||||
|
standard_properties: WasmStandardProperties,
|
||||||
|
children: Vec<WasmAstNode<'s, 'p>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
to_wasm!(
|
||||||
|
WasmRegularLink<'s, 'p>,
|
||||||
|
RegularLink<'s>,
|
||||||
|
original,
|
||||||
|
wasm_context,
|
||||||
|
standard_properties,
|
||||||
|
{
|
||||||
|
Ok(WasmRegularLink {
|
||||||
|
standard_properties,
|
||||||
|
children: Vec::new(),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
impl<'s, 'p> Into<WasmAstNode<'s, 'p>> for WasmRegularLink<'s, 'p> {
|
||||||
|
fn into(self) -> WasmAstNode<'s, 'p> {
|
||||||
|
WasmAstNode::RegularLink(self)
|
||||||
|
}
|
||||||
|
}
|
||||||
59
src/wasm/section.rs
Normal file
59
src/wasm/section.rs
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
use serde::Serialize;
|
||||||
|
|
||||||
|
use super::ast_node::WasmAstNode;
|
||||||
|
use super::macros::to_wasm;
|
||||||
|
use super::standard_properties::WasmStandardProperties;
|
||||||
|
use super::to_wasm::ToWasm;
|
||||||
|
use super::AdditionalProperties;
|
||||||
|
#[cfg(feature = "wasm_test")]
|
||||||
|
use crate::compare::ElispFact;
|
||||||
|
use crate::types::Section;
|
||||||
|
use crate::wasm::to_wasm::ToWasmStandardProperties;
|
||||||
|
|
||||||
|
#[derive(Debug, Serialize)]
|
||||||
|
#[serde(tag = "ast_node")]
|
||||||
|
#[serde(rename = "section")]
|
||||||
|
pub struct WasmSection<'s, 'p> {
|
||||||
|
pub(crate) standard_properties: WasmStandardProperties,
|
||||||
|
#[serde(flatten)]
|
||||||
|
pub(crate) additional_properties: AdditionalProperties<'s, 'p>,
|
||||||
|
pub(crate) children: Vec<WasmAstNode<'s, 'p>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
to_wasm!(
|
||||||
|
WasmSection<'s, 'p>,
|
||||||
|
Section<'s>,
|
||||||
|
original,
|
||||||
|
wasm_context,
|
||||||
|
standard_properties,
|
||||||
|
{
|
||||||
|
let children = original
|
||||||
|
.children
|
||||||
|
.iter()
|
||||||
|
.map(|child| {
|
||||||
|
child
|
||||||
|
.to_wasm(wasm_context.clone())
|
||||||
|
.map(Into::<WasmAstNode<'_, '_>>::into)
|
||||||
|
})
|
||||||
|
.collect::<Result<Vec<_>, _>>()?;
|
||||||
|
|
||||||
|
Ok(WasmSection {
|
||||||
|
standard_properties,
|
||||||
|
additional_properties: AdditionalProperties::default(),
|
||||||
|
children,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
impl<'s, 'p> Into<WasmAstNode<'s, 'p>> for WasmSection<'s, 'p> {
|
||||||
|
fn into(self) -> WasmAstNode<'s, 'p> {
|
||||||
|
WasmAstNode::Section(self)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "wasm_test")]
|
||||||
|
impl<'s, 'p> ElispFact<'s> for WasmSection<'s, 'p> {
|
||||||
|
fn get_elisp_name<'b>(&'b self) -> std::borrow::Cow<'s, str> {
|
||||||
|
"section".into()
|
||||||
|
}
|
||||||
|
}
|
||||||
36
src/wasm/special_block.rs
Normal file
36
src/wasm/special_block.rs
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
use serde::Serialize;
|
||||||
|
|
||||||
|
use super::macros::to_wasm;
|
||||||
|
use super::standard_properties::WasmStandardProperties;
|
||||||
|
use super::to_wasm::ToWasm;
|
||||||
|
use crate::types::SpecialBlock;
|
||||||
|
use crate::wasm::to_wasm::ToWasmStandardProperties;
|
||||||
|
use crate::wasm::WasmAstNode;
|
||||||
|
|
||||||
|
#[derive(Debug, Serialize)]
|
||||||
|
#[serde(tag = "ast_node")]
|
||||||
|
#[serde(rename = "org-data")]
|
||||||
|
pub struct WasmSpecialBlock<'s, 'p> {
|
||||||
|
standard_properties: WasmStandardProperties,
|
||||||
|
children: Vec<WasmAstNode<'s, 'p>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
to_wasm!(
|
||||||
|
WasmSpecialBlock<'s, 'p>,
|
||||||
|
SpecialBlock<'s>,
|
||||||
|
original,
|
||||||
|
wasm_context,
|
||||||
|
standard_properties,
|
||||||
|
{
|
||||||
|
Ok(WasmSpecialBlock {
|
||||||
|
standard_properties,
|
||||||
|
children: Vec::new(),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
impl<'s, 'p> Into<WasmAstNode<'s, 'p>> for WasmSpecialBlock<'s, 'p> {
|
||||||
|
fn into(self) -> WasmAstNode<'s, 'p> {
|
||||||
|
WasmAstNode::SpecialBlock(self)
|
||||||
|
}
|
||||||
|
}
|
||||||
36
src/wasm/src_block.rs
Normal file
36
src/wasm/src_block.rs
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
use serde::Serialize;
|
||||||
|
|
||||||
|
use super::macros::to_wasm;
|
||||||
|
use super::standard_properties::WasmStandardProperties;
|
||||||
|
use super::to_wasm::ToWasm;
|
||||||
|
use crate::types::SrcBlock;
|
||||||
|
use crate::wasm::to_wasm::ToWasmStandardProperties;
|
||||||
|
use crate::wasm::WasmAstNode;
|
||||||
|
|
||||||
|
#[derive(Debug, Serialize)]
|
||||||
|
#[serde(tag = "ast_node")]
|
||||||
|
#[serde(rename = "org-data")]
|
||||||
|
pub struct WasmSrcBlock<'s, 'p> {
|
||||||
|
standard_properties: WasmStandardProperties,
|
||||||
|
children: Vec<WasmAstNode<'s, 'p>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
to_wasm!(
|
||||||
|
WasmSrcBlock<'s, 'p>,
|
||||||
|
SrcBlock<'s>,
|
||||||
|
original,
|
||||||
|
wasm_context,
|
||||||
|
standard_properties,
|
||||||
|
{
|
||||||
|
Ok(WasmSrcBlock {
|
||||||
|
standard_properties,
|
||||||
|
children: Vec::new(),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
impl<'s, 'p> Into<WasmAstNode<'s, 'p>> for WasmSrcBlock<'s, 'p> {
|
||||||
|
fn into(self) -> WasmAstNode<'s, 'p> {
|
||||||
|
WasmAstNode::SrcBlock(self)
|
||||||
|
}
|
||||||
|
}
|
||||||
70
src/wasm/standard_properties.rs
Normal file
70
src/wasm/standard_properties.rs
Normal file
@@ -0,0 +1,70 @@
|
|||||||
|
use serde::Serialize;
|
||||||
|
|
||||||
|
use super::to_wasm::ToWasmContext;
|
||||||
|
use super::to_wasm::ToWasmStandardProperties;
|
||||||
|
use crate::types::PostBlank;
|
||||||
|
use crate::types::StandardProperties;
|
||||||
|
|
||||||
|
#[derive(Debug, Serialize)]
|
||||||
|
pub(crate) struct WasmStandardProperties {
|
||||||
|
pub(crate) begin: usize,
|
||||||
|
pub(crate) end: usize,
|
||||||
|
pub(crate) contents_begin: Option<usize>,
|
||||||
|
pub(crate) contents_end: Option<usize>,
|
||||||
|
pub(crate) 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
|
||||||
|
}
|
||||||
36
src/wasm/statistics_cookie.rs
Normal file
36
src/wasm/statistics_cookie.rs
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
use serde::Serialize;
|
||||||
|
|
||||||
|
use super::macros::to_wasm;
|
||||||
|
use super::standard_properties::WasmStandardProperties;
|
||||||
|
use super::to_wasm::ToWasm;
|
||||||
|
use crate::types::StatisticsCookie;
|
||||||
|
use crate::wasm::to_wasm::ToWasmStandardProperties;
|
||||||
|
use crate::wasm::WasmAstNode;
|
||||||
|
|
||||||
|
#[derive(Debug, Serialize)]
|
||||||
|
#[serde(tag = "ast_node")]
|
||||||
|
#[serde(rename = "org-data")]
|
||||||
|
pub struct WasmStatisticsCookie<'s, 'p> {
|
||||||
|
standard_properties: WasmStandardProperties,
|
||||||
|
children: Vec<WasmAstNode<'s, 'p>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
to_wasm!(
|
||||||
|
WasmStatisticsCookie<'s, 'p>,
|
||||||
|
StatisticsCookie<'s>,
|
||||||
|
original,
|
||||||
|
wasm_context,
|
||||||
|
standard_properties,
|
||||||
|
{
|
||||||
|
Ok(WasmStatisticsCookie {
|
||||||
|
standard_properties,
|
||||||
|
children: Vec::new(),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
impl<'s, 'p> Into<WasmAstNode<'s, 'p>> for WasmStatisticsCookie<'s, 'p> {
|
||||||
|
fn into(self) -> WasmAstNode<'s, 'p> {
|
||||||
|
WasmAstNode::StatisticsCookie(self)
|
||||||
|
}
|
||||||
|
}
|
||||||
36
src/wasm/strike_through.rs
Normal file
36
src/wasm/strike_through.rs
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
use serde::Serialize;
|
||||||
|
|
||||||
|
use super::macros::to_wasm;
|
||||||
|
use super::standard_properties::WasmStandardProperties;
|
||||||
|
use super::to_wasm::ToWasm;
|
||||||
|
use crate::types::StrikeThrough;
|
||||||
|
use crate::wasm::to_wasm::ToWasmStandardProperties;
|
||||||
|
use crate::wasm::WasmAstNode;
|
||||||
|
|
||||||
|
#[derive(Debug, Serialize)]
|
||||||
|
#[serde(tag = "ast_node")]
|
||||||
|
#[serde(rename = "org-data")]
|
||||||
|
pub struct WasmStrikeThrough<'s, 'p> {
|
||||||
|
standard_properties: WasmStandardProperties,
|
||||||
|
children: Vec<WasmAstNode<'s, 'p>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
to_wasm!(
|
||||||
|
WasmStrikeThrough<'s, 'p>,
|
||||||
|
StrikeThrough<'s>,
|
||||||
|
original,
|
||||||
|
wasm_context,
|
||||||
|
standard_properties,
|
||||||
|
{
|
||||||
|
Ok(WasmStrikeThrough {
|
||||||
|
standard_properties,
|
||||||
|
children: Vec::new(),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
impl<'s, 'p> Into<WasmAstNode<'s, 'p>> for WasmStrikeThrough<'s, 'p> {
|
||||||
|
fn into(self) -> WasmAstNode<'s, 'p> {
|
||||||
|
WasmAstNode::StrikeThrough(self)
|
||||||
|
}
|
||||||
|
}
|
||||||
36
src/wasm/subscript.rs
Normal file
36
src/wasm/subscript.rs
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
use serde::Serialize;
|
||||||
|
|
||||||
|
use super::macros::to_wasm;
|
||||||
|
use super::standard_properties::WasmStandardProperties;
|
||||||
|
use super::to_wasm::ToWasm;
|
||||||
|
use crate::types::Subscript;
|
||||||
|
use crate::wasm::to_wasm::ToWasmStandardProperties;
|
||||||
|
use crate::wasm::WasmAstNode;
|
||||||
|
|
||||||
|
#[derive(Debug, Serialize)]
|
||||||
|
#[serde(tag = "ast_node")]
|
||||||
|
#[serde(rename = "org-data")]
|
||||||
|
pub struct WasmSubscript<'s, 'p> {
|
||||||
|
standard_properties: WasmStandardProperties,
|
||||||
|
children: Vec<WasmAstNode<'s, 'p>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
to_wasm!(
|
||||||
|
WasmSubscript<'s, 'p>,
|
||||||
|
Subscript<'s>,
|
||||||
|
original,
|
||||||
|
wasm_context,
|
||||||
|
standard_properties,
|
||||||
|
{
|
||||||
|
Ok(WasmSubscript {
|
||||||
|
standard_properties,
|
||||||
|
children: Vec::new(),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
impl<'s, 'p> Into<WasmAstNode<'s, 'p>> for WasmSubscript<'s, 'p> {
|
||||||
|
fn into(self) -> WasmAstNode<'s, 'p> {
|
||||||
|
WasmAstNode::Subscript(self)
|
||||||
|
}
|
||||||
|
}
|
||||||
36
src/wasm/superscript.rs
Normal file
36
src/wasm/superscript.rs
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
use serde::Serialize;
|
||||||
|
|
||||||
|
use super::macros::to_wasm;
|
||||||
|
use super::standard_properties::WasmStandardProperties;
|
||||||
|
use super::to_wasm::ToWasm;
|
||||||
|
use crate::types::Superscript;
|
||||||
|
use crate::wasm::to_wasm::ToWasmStandardProperties;
|
||||||
|
use crate::wasm::WasmAstNode;
|
||||||
|
|
||||||
|
#[derive(Debug, Serialize)]
|
||||||
|
#[serde(tag = "ast_node")]
|
||||||
|
#[serde(rename = "org-data")]
|
||||||
|
pub struct WasmSuperscript<'s, 'p> {
|
||||||
|
standard_properties: WasmStandardProperties,
|
||||||
|
children: Vec<WasmAstNode<'s, 'p>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
to_wasm!(
|
||||||
|
WasmSuperscript<'s, 'p>,
|
||||||
|
Superscript<'s>,
|
||||||
|
original,
|
||||||
|
wasm_context,
|
||||||
|
standard_properties,
|
||||||
|
{
|
||||||
|
Ok(WasmSuperscript {
|
||||||
|
standard_properties,
|
||||||
|
children: Vec::new(),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
impl<'s, 'p> Into<WasmAstNode<'s, 'p>> for WasmSuperscript<'s, 'p> {
|
||||||
|
fn into(self) -> WasmAstNode<'s, 'p> {
|
||||||
|
WasmAstNode::Superscript(self)
|
||||||
|
}
|
||||||
|
}
|
||||||
36
src/wasm/table.rs
Normal file
36
src/wasm/table.rs
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
use serde::Serialize;
|
||||||
|
|
||||||
|
use super::macros::to_wasm;
|
||||||
|
use super::standard_properties::WasmStandardProperties;
|
||||||
|
use super::to_wasm::ToWasm;
|
||||||
|
use crate::types::Table;
|
||||||
|
use crate::wasm::to_wasm::ToWasmStandardProperties;
|
||||||
|
use crate::wasm::WasmAstNode;
|
||||||
|
|
||||||
|
#[derive(Debug, Serialize)]
|
||||||
|
#[serde(tag = "ast_node")]
|
||||||
|
#[serde(rename = "org-data")]
|
||||||
|
pub struct WasmTable<'s, 'p> {
|
||||||
|
standard_properties: WasmStandardProperties,
|
||||||
|
children: Vec<WasmAstNode<'s, 'p>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
to_wasm!(
|
||||||
|
WasmTable<'s, 'p>,
|
||||||
|
Table<'s>,
|
||||||
|
original,
|
||||||
|
wasm_context,
|
||||||
|
standard_properties,
|
||||||
|
{
|
||||||
|
Ok(WasmTable {
|
||||||
|
standard_properties,
|
||||||
|
children: Vec::new(),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
impl<'s, 'p> Into<WasmAstNode<'s, 'p>> for WasmTable<'s, 'p> {
|
||||||
|
fn into(self) -> WasmAstNode<'s, 'p> {
|
||||||
|
WasmAstNode::Table(self)
|
||||||
|
}
|
||||||
|
}
|
||||||
30
src/wasm/table_cell.rs
Normal file
30
src/wasm/table_cell.rs
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
use serde::Serialize;
|
||||||
|
|
||||||
|
use super::macros::to_wasm;
|
||||||
|
use super::standard_properties::WasmStandardProperties;
|
||||||
|
use super::to_wasm::ToWasm;
|
||||||
|
use crate::types::TableCell;
|
||||||
|
use crate::wasm::to_wasm::ToWasmStandardProperties;
|
||||||
|
use crate::wasm::WasmAstNode;
|
||||||
|
|
||||||
|
#[derive(Debug, Serialize)]
|
||||||
|
#[serde(tag = "ast_node")]
|
||||||
|
#[serde(rename = "org-data")]
|
||||||
|
pub struct WasmTableCell<'s, 'p> {
|
||||||
|
standard_properties: WasmStandardProperties,
|
||||||
|
children: Vec<WasmAstNode<'s, 'p>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
to_wasm!(
|
||||||
|
WasmTableCell<'s, 'p>,
|
||||||
|
TableCell<'s>,
|
||||||
|
original,
|
||||||
|
wasm_context,
|
||||||
|
standard_properties,
|
||||||
|
{
|
||||||
|
Ok(WasmTableCell {
|
||||||
|
standard_properties,
|
||||||
|
children: Vec::new(),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
);
|
||||||
30
src/wasm/table_row.rs
Normal file
30
src/wasm/table_row.rs
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
use serde::Serialize;
|
||||||
|
|
||||||
|
use super::macros::to_wasm;
|
||||||
|
use super::standard_properties::WasmStandardProperties;
|
||||||
|
use super::to_wasm::ToWasm;
|
||||||
|
use crate::types::TableRow;
|
||||||
|
use crate::wasm::to_wasm::ToWasmStandardProperties;
|
||||||
|
use crate::wasm::WasmAstNode;
|
||||||
|
|
||||||
|
#[derive(Debug, Serialize)]
|
||||||
|
#[serde(tag = "ast_node")]
|
||||||
|
#[serde(rename = "org-data")]
|
||||||
|
pub struct WasmTableRow<'s, 'p> {
|
||||||
|
standard_properties: WasmStandardProperties,
|
||||||
|
children: Vec<WasmAstNode<'s, 'p>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
to_wasm!(
|
||||||
|
WasmTableRow<'s, 'p>,
|
||||||
|
TableRow<'s>,
|
||||||
|
original,
|
||||||
|
wasm_context,
|
||||||
|
standard_properties,
|
||||||
|
{
|
||||||
|
Ok(WasmTableRow {
|
||||||
|
standard_properties,
|
||||||
|
children: Vec::new(),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
);
|
||||||
36
src/wasm/target.rs
Normal file
36
src/wasm/target.rs
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
use serde::Serialize;
|
||||||
|
|
||||||
|
use super::macros::to_wasm;
|
||||||
|
use super::standard_properties::WasmStandardProperties;
|
||||||
|
use super::to_wasm::ToWasm;
|
||||||
|
use crate::types::Target;
|
||||||
|
use crate::wasm::to_wasm::ToWasmStandardProperties;
|
||||||
|
use crate::wasm::WasmAstNode;
|
||||||
|
|
||||||
|
#[derive(Debug, Serialize)]
|
||||||
|
#[serde(tag = "ast_node")]
|
||||||
|
#[serde(rename = "org-data")]
|
||||||
|
pub struct WasmTarget<'s, 'p> {
|
||||||
|
standard_properties: WasmStandardProperties,
|
||||||
|
children: Vec<WasmAstNode<'s, 'p>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
to_wasm!(
|
||||||
|
WasmTarget<'s, 'p>,
|
||||||
|
Target<'s>,
|
||||||
|
original,
|
||||||
|
wasm_context,
|
||||||
|
standard_properties,
|
||||||
|
{
|
||||||
|
Ok(WasmTarget {
|
||||||
|
standard_properties,
|
||||||
|
children: Vec::new(),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
impl<'s, 'p> Into<WasmAstNode<'s, 'p>> for WasmTarget<'s, 'p> {
|
||||||
|
fn into(self) -> WasmAstNode<'s, 'p> {
|
||||||
|
WasmAstNode::Target(self)
|
||||||
|
}
|
||||||
|
}
|
||||||
36
src/wasm/timestamp.rs
Normal file
36
src/wasm/timestamp.rs
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
use serde::Serialize;
|
||||||
|
|
||||||
|
use super::macros::to_wasm;
|
||||||
|
use super::standard_properties::WasmStandardProperties;
|
||||||
|
use super::to_wasm::ToWasm;
|
||||||
|
use crate::types::Timestamp;
|
||||||
|
use crate::wasm::to_wasm::ToWasmStandardProperties;
|
||||||
|
use crate::wasm::WasmAstNode;
|
||||||
|
|
||||||
|
#[derive(Debug, Serialize)]
|
||||||
|
#[serde(tag = "ast_node")]
|
||||||
|
#[serde(rename = "org-data")]
|
||||||
|
pub struct WasmTimestamp<'s, 'p> {
|
||||||
|
standard_properties: WasmStandardProperties,
|
||||||
|
children: Vec<WasmAstNode<'s, 'p>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
to_wasm!(
|
||||||
|
WasmTimestamp<'s, 'p>,
|
||||||
|
Timestamp<'s>,
|
||||||
|
original,
|
||||||
|
wasm_context,
|
||||||
|
standard_properties,
|
||||||
|
{
|
||||||
|
Ok(WasmTimestamp {
|
||||||
|
standard_properties,
|
||||||
|
children: Vec::new(),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
impl<'s, 'p> Into<WasmAstNode<'s, 'p>> for WasmTimestamp<'s, 'p> {
|
||||||
|
fn into(self) -> WasmAstNode<'s, 'p> {
|
||||||
|
WasmAstNode::Timestamp(self)
|
||||||
|
}
|
||||||
|
}
|
||||||
154
src/wasm/to_wasm.rs
Normal file
154
src/wasm/to_wasm.rs
Normal file
@@ -0,0 +1,154 @@
|
|||||||
|
use super::macros::to_wasm;
|
||||||
|
use super::WasmAstNode;
|
||||||
|
use crate::error::CustomError;
|
||||||
|
use crate::types::Element;
|
||||||
|
use crate::types::Object;
|
||||||
|
|
||||||
|
pub trait ToWasm<'p> {
|
||||||
|
type Output;
|
||||||
|
|
||||||
|
fn to_wasm(&'p 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 struct ToWasmContext<'s> {
|
||||||
|
pub(crate) full_document: &'s str,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'s> ToWasmContext<'s> {
|
||||||
|
pub fn new(full_document: &'s str) -> ToWasmContext<'s> {
|
||||||
|
ToWasmContext { full_document }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
to_wasm!(
|
||||||
|
WasmAstNode<'s, 'p>,
|
||||||
|
Element<'s>,
|
||||||
|
original,
|
||||||
|
wasm_context,
|
||||||
|
standard_properties,
|
||||||
|
{
|
||||||
|
match original {
|
||||||
|
Element::Paragraph(inner) => inner.to_wasm(wasm_context).map(Into::<WasmAstNode>::into),
|
||||||
|
Element::PlainList(inner) => inner.to_wasm(wasm_context).map(Into::<WasmAstNode>::into),
|
||||||
|
Element::CenterBlock(inner) => {
|
||||||
|
inner.to_wasm(wasm_context).map(Into::<WasmAstNode>::into)
|
||||||
|
}
|
||||||
|
Element::QuoteBlock(inner) => {
|
||||||
|
inner.to_wasm(wasm_context).map(Into::<WasmAstNode>::into)
|
||||||
|
}
|
||||||
|
Element::SpecialBlock(inner) => {
|
||||||
|
inner.to_wasm(wasm_context).map(Into::<WasmAstNode>::into)
|
||||||
|
}
|
||||||
|
Element::DynamicBlock(inner) => {
|
||||||
|
inner.to_wasm(wasm_context).map(Into::<WasmAstNode>::into)
|
||||||
|
}
|
||||||
|
Element::FootnoteDefinition(inner) => {
|
||||||
|
inner.to_wasm(wasm_context).map(Into::<WasmAstNode>::into)
|
||||||
|
}
|
||||||
|
Element::Comment(inner) => inner.to_wasm(wasm_context).map(Into::<WasmAstNode>::into),
|
||||||
|
Element::Drawer(inner) => inner.to_wasm(wasm_context).map(Into::<WasmAstNode>::into),
|
||||||
|
Element::PropertyDrawer(inner) => {
|
||||||
|
inner.to_wasm(wasm_context).map(Into::<WasmAstNode>::into)
|
||||||
|
}
|
||||||
|
Element::Table(inner) => inner.to_wasm(wasm_context).map(Into::<WasmAstNode>::into),
|
||||||
|
Element::VerseBlock(inner) => {
|
||||||
|
inner.to_wasm(wasm_context).map(Into::<WasmAstNode>::into)
|
||||||
|
}
|
||||||
|
Element::CommentBlock(inner) => {
|
||||||
|
inner.to_wasm(wasm_context).map(Into::<WasmAstNode>::into)
|
||||||
|
}
|
||||||
|
Element::ExampleBlock(inner) => {
|
||||||
|
inner.to_wasm(wasm_context).map(Into::<WasmAstNode>::into)
|
||||||
|
}
|
||||||
|
Element::ExportBlock(inner) => {
|
||||||
|
inner.to_wasm(wasm_context).map(Into::<WasmAstNode>::into)
|
||||||
|
}
|
||||||
|
Element::SrcBlock(inner) => inner.to_wasm(wasm_context).map(Into::<WasmAstNode>::into),
|
||||||
|
Element::Clock(inner) => inner.to_wasm(wasm_context).map(Into::<WasmAstNode>::into),
|
||||||
|
Element::DiarySexp(inner) => inner.to_wasm(wasm_context).map(Into::<WasmAstNode>::into),
|
||||||
|
Element::Planning(inner) => inner.to_wasm(wasm_context).map(Into::<WasmAstNode>::into),
|
||||||
|
Element::FixedWidthArea(inner) => {
|
||||||
|
inner.to_wasm(wasm_context).map(Into::<WasmAstNode>::into)
|
||||||
|
}
|
||||||
|
Element::HorizontalRule(inner) => {
|
||||||
|
inner.to_wasm(wasm_context).map(Into::<WasmAstNode>::into)
|
||||||
|
}
|
||||||
|
Element::Keyword(inner) => inner.to_wasm(wasm_context).map(Into::<WasmAstNode>::into),
|
||||||
|
Element::BabelCall(inner) => inner.to_wasm(wasm_context).map(Into::<WasmAstNode>::into),
|
||||||
|
Element::LatexEnvironment(inner) => {
|
||||||
|
inner.to_wasm(wasm_context).map(Into::<WasmAstNode>::into)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
to_wasm!(
|
||||||
|
WasmAstNode<'s, 'p>,
|
||||||
|
Object<'s>,
|
||||||
|
original,
|
||||||
|
wasm_context,
|
||||||
|
standard_properties,
|
||||||
|
{
|
||||||
|
match original {
|
||||||
|
Object::Bold(inner) => inner.to_wasm(wasm_context).map(Into::<WasmAstNode>::into),
|
||||||
|
Object::Italic(inner) => inner.to_wasm(wasm_context).map(Into::<WasmAstNode>::into),
|
||||||
|
Object::Underline(inner) => inner.to_wasm(wasm_context).map(Into::<WasmAstNode>::into),
|
||||||
|
Object::StrikeThrough(inner) => {
|
||||||
|
inner.to_wasm(wasm_context).map(Into::<WasmAstNode>::into)
|
||||||
|
}
|
||||||
|
Object::Code(inner) => inner.to_wasm(wasm_context).map(Into::<WasmAstNode>::into),
|
||||||
|
Object::Verbatim(inner) => inner.to_wasm(wasm_context).map(Into::<WasmAstNode>::into),
|
||||||
|
Object::PlainText(inner) => inner.to_wasm(wasm_context).map(Into::<WasmAstNode>::into),
|
||||||
|
Object::RegularLink(inner) => {
|
||||||
|
inner.to_wasm(wasm_context).map(Into::<WasmAstNode>::into)
|
||||||
|
}
|
||||||
|
Object::RadioLink(inner) => inner.to_wasm(wasm_context).map(Into::<WasmAstNode>::into),
|
||||||
|
Object::RadioTarget(inner) => {
|
||||||
|
inner.to_wasm(wasm_context).map(Into::<WasmAstNode>::into)
|
||||||
|
}
|
||||||
|
Object::PlainLink(inner) => inner.to_wasm(wasm_context).map(Into::<WasmAstNode>::into),
|
||||||
|
Object::AngleLink(inner) => inner.to_wasm(wasm_context).map(Into::<WasmAstNode>::into),
|
||||||
|
Object::OrgMacro(inner) => inner.to_wasm(wasm_context).map(Into::<WasmAstNode>::into),
|
||||||
|
Object::Entity(inner) => inner.to_wasm(wasm_context).map(Into::<WasmAstNode>::into),
|
||||||
|
Object::LatexFragment(inner) => {
|
||||||
|
inner.to_wasm(wasm_context).map(Into::<WasmAstNode>::into)
|
||||||
|
}
|
||||||
|
Object::ExportSnippet(inner) => {
|
||||||
|
inner.to_wasm(wasm_context).map(Into::<WasmAstNode>::into)
|
||||||
|
}
|
||||||
|
Object::FootnoteReference(inner) => {
|
||||||
|
inner.to_wasm(wasm_context).map(Into::<WasmAstNode>::into)
|
||||||
|
}
|
||||||
|
Object::Citation(inner) => inner.to_wasm(wasm_context).map(Into::<WasmAstNode>::into),
|
||||||
|
Object::CitationReference(inner) => {
|
||||||
|
inner.to_wasm(wasm_context).map(Into::<WasmAstNode>::into)
|
||||||
|
}
|
||||||
|
Object::InlineBabelCall(inner) => {
|
||||||
|
inner.to_wasm(wasm_context).map(Into::<WasmAstNode>::into)
|
||||||
|
}
|
||||||
|
Object::InlineSourceBlock(inner) => {
|
||||||
|
inner.to_wasm(wasm_context).map(Into::<WasmAstNode>::into)
|
||||||
|
}
|
||||||
|
Object::LineBreak(inner) => inner.to_wasm(wasm_context).map(Into::<WasmAstNode>::into),
|
||||||
|
Object::Target(inner) => inner.to_wasm(wasm_context).map(Into::<WasmAstNode>::into),
|
||||||
|
Object::StatisticsCookie(inner) => {
|
||||||
|
inner.to_wasm(wasm_context).map(Into::<WasmAstNode>::into)
|
||||||
|
}
|
||||||
|
Object::Subscript(inner) => inner.to_wasm(wasm_context).map(Into::<WasmAstNode>::into),
|
||||||
|
Object::Superscript(inner) => {
|
||||||
|
inner.to_wasm(wasm_context).map(Into::<WasmAstNode>::into)
|
||||||
|
}
|
||||||
|
Object::Timestamp(inner) => inner.to_wasm(wasm_context).map(Into::<WasmAstNode>::into),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
36
src/wasm/underline.rs
Normal file
36
src/wasm/underline.rs
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
use serde::Serialize;
|
||||||
|
|
||||||
|
use super::macros::to_wasm;
|
||||||
|
use super::standard_properties::WasmStandardProperties;
|
||||||
|
use super::to_wasm::ToWasm;
|
||||||
|
use crate::types::Underline;
|
||||||
|
use crate::wasm::to_wasm::ToWasmStandardProperties;
|
||||||
|
use crate::wasm::WasmAstNode;
|
||||||
|
|
||||||
|
#[derive(Debug, Serialize)]
|
||||||
|
#[serde(tag = "ast_node")]
|
||||||
|
#[serde(rename = "org-data")]
|
||||||
|
pub struct WasmUnderline<'s, 'p> {
|
||||||
|
standard_properties: WasmStandardProperties,
|
||||||
|
children: Vec<WasmAstNode<'s, 'p>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
to_wasm!(
|
||||||
|
WasmUnderline<'s, 'p>,
|
||||||
|
Underline<'s>,
|
||||||
|
original,
|
||||||
|
wasm_context,
|
||||||
|
standard_properties,
|
||||||
|
{
|
||||||
|
Ok(WasmUnderline {
|
||||||
|
standard_properties,
|
||||||
|
children: Vec::new(),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
impl<'s, 'p> Into<WasmAstNode<'s, 'p>> for WasmUnderline<'s, 'p> {
|
||||||
|
fn into(self) -> WasmAstNode<'s, 'p> {
|
||||||
|
WasmAstNode::Underline(self)
|
||||||
|
}
|
||||||
|
}
|
||||||
36
src/wasm/verbatim.rs
Normal file
36
src/wasm/verbatim.rs
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
use serde::Serialize;
|
||||||
|
|
||||||
|
use super::macros::to_wasm;
|
||||||
|
use super::standard_properties::WasmStandardProperties;
|
||||||
|
use super::to_wasm::ToWasm;
|
||||||
|
use crate::types::Verbatim;
|
||||||
|
use crate::wasm::to_wasm::ToWasmStandardProperties;
|
||||||
|
use crate::wasm::WasmAstNode;
|
||||||
|
|
||||||
|
#[derive(Debug, Serialize)]
|
||||||
|
#[serde(tag = "ast_node")]
|
||||||
|
#[serde(rename = "org-data")]
|
||||||
|
pub struct WasmVerbatim<'s, 'p> {
|
||||||
|
standard_properties: WasmStandardProperties,
|
||||||
|
children: Vec<WasmAstNode<'s, 'p>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
to_wasm!(
|
||||||
|
WasmVerbatim<'s, 'p>,
|
||||||
|
Verbatim<'s>,
|
||||||
|
original,
|
||||||
|
wasm_context,
|
||||||
|
standard_properties,
|
||||||
|
{
|
||||||
|
Ok(WasmVerbatim {
|
||||||
|
standard_properties,
|
||||||
|
children: Vec::new(),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
impl<'s, 'p> Into<WasmAstNode<'s, 'p>> for WasmVerbatim<'s, 'p> {
|
||||||
|
fn into(self) -> WasmAstNode<'s, 'p> {
|
||||||
|
WasmAstNode::Verbatim(self)
|
||||||
|
}
|
||||||
|
}
|
||||||
36
src/wasm/verse_block.rs
Normal file
36
src/wasm/verse_block.rs
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
use serde::Serialize;
|
||||||
|
|
||||||
|
use super::macros::to_wasm;
|
||||||
|
use super::standard_properties::WasmStandardProperties;
|
||||||
|
use super::to_wasm::ToWasm;
|
||||||
|
use crate::types::VerseBlock;
|
||||||
|
use crate::wasm::to_wasm::ToWasmStandardProperties;
|
||||||
|
use crate::wasm::WasmAstNode;
|
||||||
|
|
||||||
|
#[derive(Debug, Serialize)]
|
||||||
|
#[serde(tag = "ast_node")]
|
||||||
|
#[serde(rename = "org-data")]
|
||||||
|
pub struct WasmVerseBlock<'s, 'p> {
|
||||||
|
standard_properties: WasmStandardProperties,
|
||||||
|
children: Vec<WasmAstNode<'s, 'p>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
to_wasm!(
|
||||||
|
WasmVerseBlock<'s, 'p>,
|
||||||
|
VerseBlock<'s>,
|
||||||
|
original,
|
||||||
|
wasm_context,
|
||||||
|
standard_properties,
|
||||||
|
{
|
||||||
|
Ok(WasmVerseBlock {
|
||||||
|
standard_properties,
|
||||||
|
children: Vec::new(),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
impl<'s, 'p> Into<WasmAstNode<'s, 'p>> for WasmVerseBlock<'s, 'p> {
|
||||||
|
fn into(self) -> WasmAstNode<'s, 'p> {
|
||||||
|
WasmAstNode::VerseBlock(self)
|
||||||
|
}
|
||||||
|
}
|
||||||
1731
src/wasm_test/compare.rs
Normal file
1731
src/wasm_test/compare.rs
Normal file
File diff suppressed because it is too large
Load Diff
110
src/wasm_test/diff.rs
Normal file
110
src/wasm_test/diff.rs
Normal file
@@ -0,0 +1,110 @@
|
|||||||
|
use std::borrow::Cow;
|
||||||
|
|
||||||
|
use crate::util::foreground_color;
|
||||||
|
use crate::util::reset_color;
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub struct WasmDiffResult<'s> {
|
||||||
|
pub(crate) status: Vec<WasmDiffStatus>,
|
||||||
|
pub(crate) name: Cow<'s, str>,
|
||||||
|
pub(crate) children: Vec<WasmDiffResult<'s>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub(crate) enum WasmDiffStatus {
|
||||||
|
Good,
|
||||||
|
Bad(Cow<'static, str>),
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'s> WasmDiffResult<'s> {
|
||||||
|
pub(crate) fn extend(
|
||||||
|
&mut self,
|
||||||
|
other: WasmDiffResult<'s>,
|
||||||
|
) -> Result<&mut WasmDiffResult<'s>, Box<dyn std::error::Error>> {
|
||||||
|
if self.name.is_empty() {
|
||||||
|
self.name = other.name;
|
||||||
|
}
|
||||||
|
self.status.extend(other.status);
|
||||||
|
self.children.extend(other.children);
|
||||||
|
Ok(self)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn is_bad(&self) -> bool {
|
||||||
|
self.is_self_bad() || self.has_bad_children()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn is_self_bad(&self) -> bool {
|
||||||
|
self.status
|
||||||
|
.iter()
|
||||||
|
.any(|status| matches!(status, WasmDiffStatus::Bad(_)))
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn has_bad_children(&self) -> bool {
|
||||||
|
self.children.iter().any(WasmDiffResult::is_bad)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn print(&self, original_document: &str) -> Result<(), Box<dyn std::error::Error>> {
|
||||||
|
self.print_indented(0, original_document)
|
||||||
|
// println!("{:#?}", self);
|
||||||
|
// todo!()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn print_indented(
|
||||||
|
&self,
|
||||||
|
indentation: usize,
|
||||||
|
original_document: &str,
|
||||||
|
) -> Result<(), Box<dyn std::error::Error>> {
|
||||||
|
let status_text = {
|
||||||
|
if self.is_bad() {
|
||||||
|
format!(
|
||||||
|
"{color}BAD{reset}",
|
||||||
|
color = foreground_color(255, 0, 0),
|
||||||
|
reset = reset_color(),
|
||||||
|
)
|
||||||
|
} else if self.has_bad_children() {
|
||||||
|
format!(
|
||||||
|
"{color}BADCHILD{reset}",
|
||||||
|
color = foreground_color(255, 255, 0),
|
||||||
|
reset = reset_color(),
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
format!(
|
||||||
|
"{color}GOOD{reset}",
|
||||||
|
color = foreground_color(0, 255, 0),
|
||||||
|
reset = reset_color(),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
};
|
||||||
|
let message = self
|
||||||
|
.status
|
||||||
|
.iter()
|
||||||
|
.filter_map(|status| match status {
|
||||||
|
WasmDiffStatus::Good => None,
|
||||||
|
WasmDiffStatus::Bad(message) => Some(message),
|
||||||
|
})
|
||||||
|
.next();
|
||||||
|
println!(
|
||||||
|
"{indentation}{status_text} {name} {message}",
|
||||||
|
indentation = " ".repeat(indentation),
|
||||||
|
status_text = status_text,
|
||||||
|
name = self.name,
|
||||||
|
message = message.unwrap_or(&Cow::Borrowed(""))
|
||||||
|
);
|
||||||
|
|
||||||
|
for child in self.children.iter() {
|
||||||
|
child.print_indented(indentation + 1, original_document)?;
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'s> Default for WasmDiffResult<'s> {
|
||||||
|
fn default() -> Self {
|
||||||
|
WasmDiffResult {
|
||||||
|
status: Vec::new(),
|
||||||
|
name: "".into(),
|
||||||
|
children: Vec::new(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
10
src/wasm_test/elisp_compare.rs
Normal file
10
src/wasm_test/elisp_compare.rs
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
use super::diff::WasmDiffResult;
|
||||||
|
use crate::compare::Token;
|
||||||
|
|
||||||
|
pub trait WasmElispCompare<'s, 'p> {
|
||||||
|
fn compare_ast_node<'b>(
|
||||||
|
&self,
|
||||||
|
source: &'s str,
|
||||||
|
emacs: &'b Token<'s>,
|
||||||
|
) -> Result<WasmDiffResult<'s>, Box<dyn std::error::Error>>;
|
||||||
|
}
|
||||||
387
src/wasm_test/logic.rs
Normal file
387
src/wasm_test/logic.rs
Normal file
@@ -0,0 +1,387 @@
|
|||||||
|
use super::diff::WasmDiffResult;
|
||||||
|
use super::diff::WasmDiffStatus;
|
||||||
|
use super::elisp_compare::WasmElispCompare;
|
||||||
|
use crate::compare::get_emacs_standard_properties;
|
||||||
|
use crate::compare::get_property;
|
||||||
|
use crate::compare::get_property_quoted_string;
|
||||||
|
use crate::compare::unquote;
|
||||||
|
use crate::compare::Token;
|
||||||
|
use crate::wasm::AdditionalProperties;
|
||||||
|
use crate::wasm::AdditionalPropertyValue;
|
||||||
|
use crate::wasm::WasmStandardProperties;
|
||||||
|
|
||||||
|
pub(crate) fn wasm_compare_list<'b, 's: 'b, 'p, EI, WI, WC>(
|
||||||
|
source: &'s str,
|
||||||
|
emacs: EI,
|
||||||
|
wasm: WI,
|
||||||
|
) -> Result<WasmDiffResult<'s>, Box<dyn std::error::Error>>
|
||||||
|
where
|
||||||
|
EI: Iterator<Item = &'b Token<'s>> + ExactSizeIterator,
|
||||||
|
WI: Iterator<Item = WC> + ExactSizeIterator,
|
||||||
|
WC: WasmElispCompare<'s, 'p>,
|
||||||
|
{
|
||||||
|
let status = Vec::new();
|
||||||
|
let emacs_length = emacs.len();
|
||||||
|
let wasm_length = wasm.len();
|
||||||
|
if emacs_length != wasm_length {
|
||||||
|
return Ok(WasmDiffResult {
|
||||||
|
status: vec![WasmDiffStatus::Bad(
|
||||||
|
format!(
|
||||||
|
"Child length mismatch (emacs != rust) {:?} != {:?}",
|
||||||
|
emacs_length, wasm_length
|
||||||
|
)
|
||||||
|
.into(),
|
||||||
|
)],
|
||||||
|
children: Vec::new(),
|
||||||
|
name: "".into(),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut child_status = Vec::with_capacity(emacs_length);
|
||||||
|
for (emacs_child, wasm_child) in emacs.zip(wasm) {
|
||||||
|
child_status.push(wasm_child.compare_ast_node(source, emacs_child)?);
|
||||||
|
}
|
||||||
|
Ok(WasmDiffResult {
|
||||||
|
status,
|
||||||
|
children: child_status,
|
||||||
|
name: "".into(),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) fn wasm_compare_property_quoted_string<
|
||||||
|
'b,
|
||||||
|
's,
|
||||||
|
W,
|
||||||
|
WV: AsRef<str> + std::fmt::Debug,
|
||||||
|
WG: Fn(W) -> Option<WV>,
|
||||||
|
>(
|
||||||
|
_source: &'s str,
|
||||||
|
emacs: &'b Token<'s>,
|
||||||
|
wasm_node: W,
|
||||||
|
emacs_field: &str,
|
||||||
|
wasm_value_getter: WG,
|
||||||
|
) -> Result<WasmDiffResult<'s>, Box<dyn std::error::Error>> {
|
||||||
|
let mut result = WasmDiffResult::default();
|
||||||
|
let emacs_value = get_property_quoted_string(emacs, emacs_field)?;
|
||||||
|
let wasm_value = wasm_value_getter(wasm_node);
|
||||||
|
if wasm_value.as_ref().map(|s| s.as_ref()) != emacs_value.as_deref() {
|
||||||
|
result.status.push(WasmDiffStatus::Bad(
|
||||||
|
format!(
|
||||||
|
"Property mismatch. Property=({property}) Emacs=({emacs:?}) Wasm=({wasm:?}).",
|
||||||
|
property = emacs_field,
|
||||||
|
emacs = emacs_value,
|
||||||
|
wasm = wasm_value,
|
||||||
|
)
|
||||||
|
.into(),
|
||||||
|
))
|
||||||
|
}
|
||||||
|
Ok(result)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) fn wasm_compare_property_list_of_quoted_string<
|
||||||
|
'b,
|
||||||
|
's,
|
||||||
|
WI: Iterator<Item = WV> + ExactSizeIterator,
|
||||||
|
W,
|
||||||
|
WV: AsRef<str> + std::fmt::Debug,
|
||||||
|
WG: Fn(W) -> Option<WI>,
|
||||||
|
>(
|
||||||
|
_source: &'s str,
|
||||||
|
emacs: &'b Token<'s>,
|
||||||
|
wasm_node: W,
|
||||||
|
emacs_field: &str,
|
||||||
|
wasm_value_getter: WG,
|
||||||
|
) -> Result<WasmDiffResult<'s>, Box<dyn std::error::Error>> {
|
||||||
|
let mut result = WasmDiffResult::default();
|
||||||
|
let emacs_value = get_property(emacs, emacs_field)?
|
||||||
|
.map(Token::as_list)
|
||||||
|
.map_or(Ok(None), |r| r.map(Some))?;
|
||||||
|
let wasm_value = wasm_value_getter(wasm_node);
|
||||||
|
match (emacs_value, wasm_value) {
|
||||||
|
(None, None) => {}
|
||||||
|
(None, Some(_)) | (Some(_), None) => {
|
||||||
|
return Ok(WasmDiffResult {
|
||||||
|
status: vec![WasmDiffStatus::Bad(
|
||||||
|
format!(
|
||||||
|
"Property list length mismatch. Property=({property}) Emacs=({emacs:?}) Wasm=({wasm:?}).",
|
||||||
|
property = emacs_field,
|
||||||
|
emacs = if emacs_value.is_some() {"Some"} else {"None"},
|
||||||
|
wasm = if !emacs_value.is_some() {"Some"} else {"None"}
|
||||||
|
)
|
||||||
|
.into(),
|
||||||
|
)],
|
||||||
|
children: Vec::new(),
|
||||||
|
name: "".into(),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
(Some(el), Some(wl)) if el.len() != wl.len() => {
|
||||||
|
return Ok(WasmDiffResult {
|
||||||
|
status: vec![WasmDiffStatus::Bad(
|
||||||
|
format!(
|
||||||
|
"Property list length mismatch. Property=({property}) Emacs=({emacs:?}) Wasm=({wasm:?}).",
|
||||||
|
property = emacs_field,
|
||||||
|
emacs = el.len(),
|
||||||
|
wasm = wl.len()
|
||||||
|
)
|
||||||
|
.into(),
|
||||||
|
)],
|
||||||
|
children: Vec::new(),
|
||||||
|
name: "".into(),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
(Some(el), Some(wl)) => {
|
||||||
|
for (e, w) in el.iter().zip(wl) {
|
||||||
|
let e = unquote(e.as_atom()?)?;
|
||||||
|
let w = w.as_ref();
|
||||||
|
if e != w {
|
||||||
|
result.status.push(WasmDiffStatus::Bad(
|
||||||
|
format!(
|
||||||
|
"Property list value mismatch. Property=({property}) Emacs=({emacs:?}) Wasm=({wasm:?}).",
|
||||||
|
property = emacs_field,
|
||||||
|
emacs = e,
|
||||||
|
wasm = w
|
||||||
|
)
|
||||||
|
.into(),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
Ok(result)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) fn wasm_compare_property_optional_pair<
|
||||||
|
'b,
|
||||||
|
's,
|
||||||
|
W,
|
||||||
|
WV: AsRef<str> + std::fmt::Debug,
|
||||||
|
WOV: AsRef<str> + std::fmt::Debug,
|
||||||
|
WG: Fn(W) -> Option<(Option<WOV>, WV)>,
|
||||||
|
>(
|
||||||
|
_source: &'s str,
|
||||||
|
emacs: &'b Token<'s>,
|
||||||
|
wasm_node: W,
|
||||||
|
emacs_field: &str,
|
||||||
|
wasm_value_getter: WG,
|
||||||
|
) -> Result<WasmDiffResult<'s>, Box<dyn std::error::Error>> {
|
||||||
|
let mut result = WasmDiffResult::default();
|
||||||
|
let emacs_value = get_property(emacs, emacs_field)?
|
||||||
|
.map(Token::as_list)
|
||||||
|
.map_or(Ok(None), |r| r.map(Some))?;
|
||||||
|
let wasm_value = wasm_value_getter(wasm_node);
|
||||||
|
match (emacs_value, &wasm_value) {
|
||||||
|
(None, None) => {}
|
||||||
|
(None, Some(_)) | (Some(_), None) => {
|
||||||
|
return Ok(WasmDiffResult {
|
||||||
|
status: vec![WasmDiffStatus::Bad(
|
||||||
|
format!(
|
||||||
|
"Property list length mismatch. Property=({property}) Emacs=({emacs:?}) Wasm=({wasm:?}).",
|
||||||
|
property = emacs_field,
|
||||||
|
emacs = if emacs_value.is_some() {"Some"} else {"None"},
|
||||||
|
wasm = if !emacs_value.is_some() {"Some"} else {"None"}
|
||||||
|
)
|
||||||
|
.into(),
|
||||||
|
)],
|
||||||
|
children: Vec::new(),
|
||||||
|
name: "".into(),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
(Some(el), Some((Some(owl), wl))) if el.len() == 3 => {
|
||||||
|
let e = el
|
||||||
|
.first()
|
||||||
|
.map(Token::as_atom)
|
||||||
|
.map_or(Ok(None), |r| r.map(Some))?
|
||||||
|
.map(unquote)
|
||||||
|
.map_or(Ok(None), |r| r.map(Some))?
|
||||||
|
.expect("Above match proved length to be 3.");
|
||||||
|
let oe = el
|
||||||
|
.get(2)
|
||||||
|
.map(Token::as_atom)
|
||||||
|
.map_or(Ok(None), |r| r.map(Some))?
|
||||||
|
.map(unquote)
|
||||||
|
.map_or(Ok(None), |r| r.map(Some))?
|
||||||
|
.expect("Above match proved length to be 3.");
|
||||||
|
let w = wl.as_ref();
|
||||||
|
let ow = owl.as_ref();
|
||||||
|
if e != w {
|
||||||
|
result.status.push(WasmDiffStatus::Bad(
|
||||||
|
format!(
|
||||||
|
"Property mismatch. Property=({property}) Emacs=({emacs:?}) Wasm=({wasm:?}).",
|
||||||
|
property = "end",
|
||||||
|
emacs = e,
|
||||||
|
wasm = w,
|
||||||
|
)
|
||||||
|
.into(),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
if oe != ow {
|
||||||
|
result.status.push(WasmDiffStatus::Bad(
|
||||||
|
format!(
|
||||||
|
"Property mismatch. Property=({property}) Emacs=({emacs:?}) Wasm=({wasm:?}).",
|
||||||
|
property = "end",
|
||||||
|
emacs = oe,
|
||||||
|
wasm = ow,
|
||||||
|
)
|
||||||
|
.into(),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
(Some(el), Some((None, wl))) if el.len() == 1 => {
|
||||||
|
let e = el
|
||||||
|
.first()
|
||||||
|
.map(Token::as_atom)
|
||||||
|
.map_or(Ok(None), |r| r.map(Some))?
|
||||||
|
.map(unquote)
|
||||||
|
.map_or(Ok(None), |r| r.map(Some))?
|
||||||
|
.expect("Above match proved length to be 3.");
|
||||||
|
let w = wl.as_ref();
|
||||||
|
if e != w {
|
||||||
|
result.status.push(WasmDiffStatus::Bad(
|
||||||
|
format!(
|
||||||
|
"Property mismatch. Property=({property}) Emacs=({emacs:?}) Wasm=({wasm:?}).",
|
||||||
|
property = "end",
|
||||||
|
emacs = e,
|
||||||
|
wasm = w,
|
||||||
|
)
|
||||||
|
.into(),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
(Some(el), Some(_)) => {
|
||||||
|
return Ok(WasmDiffResult {
|
||||||
|
status: vec![WasmDiffStatus::Bad(
|
||||||
|
format!(
|
||||||
|
"Property list length mismatch. Property=({property}) Emacs=({emacs:?}) Wasm=({wasm:?}).",
|
||||||
|
property = emacs_field,
|
||||||
|
emacs = el.len(),
|
||||||
|
wasm = wasm_value
|
||||||
|
)
|
||||||
|
.into(),
|
||||||
|
)],
|
||||||
|
children: Vec::new(),
|
||||||
|
name: "".into(),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Ok(result)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) fn wasm_compare_standard_properties<'b, 's>(
|
||||||
|
_source: &'s str,
|
||||||
|
emacs: &'b Token<'s>,
|
||||||
|
wasm: &WasmStandardProperties,
|
||||||
|
) -> Result<WasmDiffResult<'s>, Box<dyn std::error::Error>> {
|
||||||
|
let mut result = WasmDiffResult::default();
|
||||||
|
let mut layer = WasmDiffResult::default();
|
||||||
|
layer.name = "standard-properties".into();
|
||||||
|
let standard_properties = get_emacs_standard_properties(emacs)?;
|
||||||
|
|
||||||
|
if Some(wasm.begin) != standard_properties.begin {
|
||||||
|
layer.status.push(WasmDiffStatus::Bad(
|
||||||
|
format!(
|
||||||
|
"Property mismatch. Property=({property}) Emacs=({emacs:?}) Wasm=({wasm:?}).",
|
||||||
|
property = "begin",
|
||||||
|
emacs = standard_properties.begin,
|
||||||
|
wasm = Some(wasm.begin),
|
||||||
|
)
|
||||||
|
.into(),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
if Some(wasm.end) != standard_properties.end {
|
||||||
|
layer.status.push(WasmDiffStatus::Bad(
|
||||||
|
format!(
|
||||||
|
"Property mismatch. Property=({property}) Emacs=({emacs:?}) Wasm=({wasm:?}).",
|
||||||
|
property = "end",
|
||||||
|
emacs = standard_properties.end,
|
||||||
|
wasm = Some(wasm.end),
|
||||||
|
)
|
||||||
|
.into(),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
if wasm.contents_begin != standard_properties.contents_begin {
|
||||||
|
layer.status.push(WasmDiffStatus::Bad(
|
||||||
|
format!(
|
||||||
|
"Property mismatch. Property=({property}) Emacs=({emacs:?}) Wasm=({wasm:?}).",
|
||||||
|
property = "contents-begin",
|
||||||
|
emacs = standard_properties.contents_begin,
|
||||||
|
wasm = wasm.contents_begin,
|
||||||
|
)
|
||||||
|
.into(),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
if wasm.contents_end != standard_properties.contents_end {
|
||||||
|
layer.status.push(WasmDiffStatus::Bad(
|
||||||
|
format!(
|
||||||
|
"Property mismatch. Property=({property}) Emacs=({emacs:?}) Wasm=({wasm:?}).",
|
||||||
|
property = "contents-end",
|
||||||
|
emacs = standard_properties.contents_end,
|
||||||
|
wasm = wasm.contents_end,
|
||||||
|
)
|
||||||
|
.into(),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
if Some(wasm.post_blank).map(|post_blank| post_blank as usize) != standard_properties.post_blank
|
||||||
|
{
|
||||||
|
layer.status.push(WasmDiffStatus::Bad(
|
||||||
|
format!(
|
||||||
|
"Property mismatch. Property=({property}) Emacs=({emacs:?}) Wasm=({wasm:?}).",
|
||||||
|
property = "post-blank",
|
||||||
|
emacs = standard_properties.post_blank,
|
||||||
|
wasm = Some(wasm.post_blank),
|
||||||
|
)
|
||||||
|
.into(),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
result.children.push(layer);
|
||||||
|
Ok(result)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) fn wasm_compare_additional_properties<'b, 's>(
|
||||||
|
source: &'s str,
|
||||||
|
emacs: &'b Token<'s>,
|
||||||
|
wasm: &AdditionalProperties<'_, '_>,
|
||||||
|
) -> Result<WasmDiffResult<'s>, Box<dyn std::error::Error>> {
|
||||||
|
let mut result = WasmDiffResult::default();
|
||||||
|
let mut layer = WasmDiffResult::default();
|
||||||
|
layer.name = "additional-properties".into();
|
||||||
|
|
||||||
|
for (property_name, property_value) in wasm.properties.iter() {
|
||||||
|
let emacs_property_name = format!(":{property_name}", property_name = property_name);
|
||||||
|
match property_value {
|
||||||
|
AdditionalPropertyValue::SingleString(wasm_value) => {
|
||||||
|
layer.extend(wasm_compare_property_quoted_string(
|
||||||
|
source,
|
||||||
|
emacs,
|
||||||
|
wasm,
|
||||||
|
&emacs_property_name,
|
||||||
|
|_| Some(wasm_value),
|
||||||
|
)?)?;
|
||||||
|
}
|
||||||
|
AdditionalPropertyValue::ListOfStrings(wasm_value) => {
|
||||||
|
layer.extend(wasm_compare_property_list_of_quoted_string(
|
||||||
|
source,
|
||||||
|
emacs,
|
||||||
|
wasm,
|
||||||
|
&emacs_property_name,
|
||||||
|
|_| Some(wasm_value.iter()),
|
||||||
|
)?)?;
|
||||||
|
}
|
||||||
|
// TODO: similar to compare_affiliated_keywords
|
||||||
|
AdditionalPropertyValue::OptionalPair { optval, val } => {
|
||||||
|
layer.extend(wasm_compare_property_optional_pair(
|
||||||
|
source,
|
||||||
|
emacs,
|
||||||
|
wasm,
|
||||||
|
&emacs_property_name,
|
||||||
|
|_| Some((*optval, *val)),
|
||||||
|
)?)?;
|
||||||
|
}
|
||||||
|
AdditionalPropertyValue::ObjectTree(_) => todo!(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
result.children.push(layer);
|
||||||
|
Ok(result)
|
||||||
|
}
|
||||||
143
src/wasm_test/macros.rs
Normal file
143
src/wasm_test/macros.rs
Normal file
@@ -0,0 +1,143 @@
|
|||||||
|
macro_rules! wasm_compare {
|
||||||
|
($source:expr, $emacs:expr, $wasm:expr, $(($emacs_field:expr, $wasm_value_getter:expr, $compare_fn: expr)),*) => {{
|
||||||
|
let mut result = WasmDiffResult::default();
|
||||||
|
let emacs_list = $emacs.as_list()?;
|
||||||
|
let mut emacs_list_iter = emacs_list.iter();
|
||||||
|
let emacs_name = emacs_list_iter
|
||||||
|
.next()
|
||||||
|
.ok_or("Should have an attributes child.")?
|
||||||
|
.as_atom()?;
|
||||||
|
result.name = emacs_name.into();
|
||||||
|
let emacs_attributes_map = emacs_list_iter
|
||||||
|
.next()
|
||||||
|
.ok_or("Should have an attributes child.")?
|
||||||
|
.as_map()?;
|
||||||
|
let mut emacs_keys: std::collections::BTreeSet<&str> =
|
||||||
|
emacs_attributes_map.keys().map(|s| *s).collect();
|
||||||
|
|
||||||
|
// Mark :standard-properties as seen because it will be handled separately.
|
||||||
|
if emacs_keys.contains(":standard-properties") {
|
||||||
|
emacs_keys.remove(":standard-properties");
|
||||||
|
} else {
|
||||||
|
result.status.push(WasmDiffStatus::Bad(
|
||||||
|
"Emacs node lacked :standard-properties field.".into(),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
// Compare name.
|
||||||
|
let wasm_name = $wasm.get_elisp_name();
|
||||||
|
|
||||||
|
if emacs_name != wasm_name {
|
||||||
|
result.status.push(WasmDiffStatus::Bad(
|
||||||
|
format!(
|
||||||
|
"AST node name mismatch. Emacs=({emacs}) Wasm=({wasm}).",
|
||||||
|
emacs = emacs_name,
|
||||||
|
wasm = wasm_name,
|
||||||
|
)
|
||||||
|
.into(),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
// Compare standard properties.
|
||||||
|
result.extend(wasm_compare_standard_properties($source, $emacs, &$wasm.standard_properties)?)?;
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
// Compare additional properties.
|
||||||
|
let additional_property_names: Vec<String> = $wasm.additional_properties.get_elisp_names().collect();
|
||||||
|
for additional_property in additional_property_names.iter().map(String::as_str).map(EmacsField::Required) {
|
||||||
|
match additional_property {
|
||||||
|
EmacsField::Required(name) if emacs_keys.contains(name) => {
|
||||||
|
emacs_keys.remove(name);
|
||||||
|
}
|
||||||
|
EmacsField::Optional(name) if emacs_keys.contains(name) => {
|
||||||
|
emacs_keys.remove(name);
|
||||||
|
}
|
||||||
|
EmacsField::Required(name) => {
|
||||||
|
result.status.push(WasmDiffStatus::Bad(
|
||||||
|
format!(
|
||||||
|
"Emacs node lacked required field ({name}).",
|
||||||
|
name = name,
|
||||||
|
)
|
||||||
|
.into(),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
EmacsField::Optional(_name) => {}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
result.extend(wasm_compare_additional_properties($source, $emacs, &$wasm.additional_properties)?)?;
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
// Compare children.
|
||||||
|
result.extend(wasm_compare_list(
|
||||||
|
$source,
|
||||||
|
emacs_list_iter,
|
||||||
|
$wasm.children.iter(),
|
||||||
|
)?)?;
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
// Check for properties that are missing from the elisp node.
|
||||||
|
$(
|
||||||
|
match $emacs_field {
|
||||||
|
EmacsField::Required(name) if emacs_keys.contains(name) => {
|
||||||
|
emacs_keys.remove(name);
|
||||||
|
}
|
||||||
|
EmacsField::Optional(name) if emacs_keys.contains(name) => {
|
||||||
|
emacs_keys.remove(name);
|
||||||
|
}
|
||||||
|
EmacsField::Required(name) => {
|
||||||
|
result.status.push(WasmDiffStatus::Bad(
|
||||||
|
format!(
|
||||||
|
"Emacs node lacked required field ({name}).",
|
||||||
|
name = name,
|
||||||
|
)
|
||||||
|
.into(),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
EmacsField::Optional(_name) => {}
|
||||||
|
}
|
||||||
|
)*
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
// Check for elisp properties that were not compared.
|
||||||
|
if !emacs_keys.is_empty() {
|
||||||
|
let unexpected_keys: Vec<&str> = emacs_keys.into_iter().collect();
|
||||||
|
let unexpected_keys = unexpected_keys.join(", ");
|
||||||
|
result.status.push(WasmDiffStatus::Bad(
|
||||||
|
format!(
|
||||||
|
"Emacs node had extra field(s): ({field_names}).",
|
||||||
|
field_names = unexpected_keys,
|
||||||
|
)
|
||||||
|
.into(),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
// Compare properties.
|
||||||
|
$(
|
||||||
|
let emacs_name = match $emacs_field {
|
||||||
|
EmacsField::Required(name) => {
|
||||||
|
name
|
||||||
|
},
|
||||||
|
EmacsField::Optional(name) => {
|
||||||
|
name
|
||||||
|
},
|
||||||
|
};
|
||||||
|
result.extend($compare_fn($source, $emacs, $wasm, emacs_name, $wasm_value_getter)?)?;
|
||||||
|
)*
|
||||||
|
}
|
||||||
|
|
||||||
|
result
|
||||||
|
}};
|
||||||
|
}
|
||||||
|
pub(crate) use wasm_compare;
|
||||||
11
src/wasm_test/mod.rs
Normal file
11
src/wasm_test/mod.rs
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
mod compare;
|
||||||
|
mod diff;
|
||||||
|
mod elisp_compare;
|
||||||
|
mod logic;
|
||||||
|
mod macros;
|
||||||
|
mod runner;
|
||||||
|
|
||||||
|
pub use runner::wasm_run_anonymous_compare;
|
||||||
|
pub use runner::wasm_run_anonymous_compare_with_settings;
|
||||||
|
pub use runner::wasm_run_compare_on_file;
|
||||||
|
pub use runner::wasm_run_compare_on_file_with_settings;
|
||||||
131
src/wasm_test/runner.rs
Normal file
131
src/wasm_test/runner.rs
Normal file
@@ -0,0 +1,131 @@
|
|||||||
|
use std::path::Path;
|
||||||
|
|
||||||
|
use super::compare::wasm_compare_document;
|
||||||
|
use crate::compare::sexp;
|
||||||
|
use crate::context::GlobalSettings;
|
||||||
|
use crate::parser::parse_file_with_settings;
|
||||||
|
use crate::parser::parse_with_settings;
|
||||||
|
use crate::settings::LocalFileAccessInterface;
|
||||||
|
use crate::util::emacs_parse_anonymous_org_document;
|
||||||
|
use crate::util::emacs_parse_file_org_document;
|
||||||
|
use crate::util::foreground_color;
|
||||||
|
use crate::util::print_versions;
|
||||||
|
use crate::util::reset_color;
|
||||||
|
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 = 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())?;
|
||||||
|
|
||||||
|
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 = wasm_compare_document(org_contents, &parsed_sexp, wasm_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 = foreground_color(0, 255, 0),
|
||||||
|
reset = reset_color(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(true)
|
||||||
|
}
|
||||||
|
|
||||||
|
//wasm_run_compare_on_file
|
||||||
|
pub async fn wasm_run_compare_on_file<P: AsRef<Path>>(
|
||||||
|
org_path: P,
|
||||||
|
) -> Result<bool, Box<dyn std::error::Error>> {
|
||||||
|
wasm_run_compare_on_file_with_settings(org_path, &GlobalSettings::default(), false).await
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn wasm_run_compare_on_file_with_settings<'g, 's, P: AsRef<Path>>(
|
||||||
|
org_path: P,
|
||||||
|
global_settings: &GlobalSettings<'g, 's>,
|
||||||
|
silent: bool,
|
||||||
|
) -> Result<bool, Box<dyn std::error::Error>> {
|
||||||
|
let org_path = org_path.as_ref();
|
||||||
|
if !silent {
|
||||||
|
print_versions().await?;
|
||||||
|
}
|
||||||
|
let parent_directory = org_path
|
||||||
|
.parent()
|
||||||
|
.ok_or("Should be contained inside a directory.")?;
|
||||||
|
let org_contents = std::fs::read_to_string(org_path)?;
|
||||||
|
// 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.replace("\r\n", "\n");
|
||||||
|
let org_contents = org_contents.as_str();
|
||||||
|
let file_access_interface = LocalFileAccessInterface {
|
||||||
|
working_directory: Some(parent_directory.to_path_buf()),
|
||||||
|
};
|
||||||
|
let global_settings = {
|
||||||
|
let mut global_settings = global_settings.clone();
|
||||||
|
global_settings.file_access = &file_access_interface;
|
||||||
|
global_settings
|
||||||
|
};
|
||||||
|
let rust_parsed = parse_file_with_settings(org_contents, &global_settings, Some(org_path))?;
|
||||||
|
let to_wasm_context = ToWasmContext::new(org_contents);
|
||||||
|
let wasm_parsed = rust_parsed
|
||||||
|
.to_wasm(to_wasm_context)
|
||||||
|
.map_err(|_e| "Failed to convert to wasm.")?;
|
||||||
|
let org_sexp = emacs_parse_file_org_document(org_path, &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 = wasm_compare_document(org_contents, &parsed_sexp, wasm_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 = foreground_color(0, 255, 0),
|
||||||
|
reset = reset_color(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(true)
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user