Compare commits
89 Commits
v0.1.13
...
c1b471208d
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c1b471208d | ||
|
|
606bab9e6d | ||
|
|
0edf5620a2 | ||
|
|
cdf87641c5 | ||
|
|
eb2995dd3b | ||
|
|
cd6a64c015 | ||
|
|
a4a83d047d | ||
|
|
a4414369ce | ||
|
|
83e4b72307 | ||
|
|
34b3e4fa7b | ||
|
|
c0e879dc1e | ||
|
|
fa31b001f4 | ||
|
|
0897061ff6 | ||
|
|
28a3e1bc7b | ||
|
|
3fd3d20722 | ||
|
|
90735586b5 | ||
|
|
78befc7665 | ||
|
|
ef549d3b19 | ||
|
|
777c756a7f | ||
|
|
037caf369c | ||
|
|
54085b5833 | ||
|
|
2bfa8e59e7 | ||
|
|
5d31db39a4 | ||
|
|
adcd0de7e4 | ||
|
|
c2f9789a64 | ||
|
|
579cbb5d11 | ||
|
|
cad2be43bf | ||
|
|
a0a4f0eb90 | ||
|
|
9f4f8e79ce | ||
|
|
77e0dbb42e | ||
|
|
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
|
||||
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:
|
||||
- name: report-success
|
||||
when:
|
||||
|
||||
@@ -115,7 +115,7 @@ spec:
|
||||
[
|
||||
--no-default-features,
|
||||
--features,
|
||||
compare,
|
||||
"compare,wasm_test",
|
||||
--no-fail-fast,
|
||||
--lib,
|
||||
--test,
|
||||
|
||||
21
Cargo.toml
21
Cargo.toml
@@ -39,17 +39,31 @@ path = "src/lib.rs"
|
||||
path = "src/bin_foreign_document_test.rs"
|
||||
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]
|
||||
futures = { version = "0.3.28", optional = true }
|
||||
nom = "7.1.1"
|
||||
opentelemetry = { version = "0.20.0", optional = true, default-features = false, features = ["trace", "rt-tokio"] }
|
||||
opentelemetry-otlp = { version = "0.13.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"] }
|
||||
tracing = { version = "0.1.37", optional = true }
|
||||
tracing-opentelemetry = { version = "0.20.0", optional = true }
|
||||
tracing-subscriber = { version = "0.3.17", optional = true, features = ["env-filter"] }
|
||||
walkdir = { version = "2.3.3", optional = true }
|
||||
wasm-bindgen = { version = "0.2.89", optional = true }
|
||||
|
||||
[build-dependencies]
|
||||
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"]
|
||||
tracing = ["dep:opentelemetry", "dep:opentelemetry-otlp", "dep:opentelemetry-semantic-conventions", "dep:tokio", "dep:tracing", "dep:tracing-opentelemetry", "dep:tracing-subscriber"]
|
||||
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.
|
||||
[profile.release-lto]
|
||||
@@ -79,3 +95,8 @@ strip = "symbols"
|
||||
inherits = "release"
|
||||
lto = true
|
||||
debug = true
|
||||
|
||||
[profile.wasm]
|
||||
inherits = "release"
|
||||
lto = true
|
||||
strip = true
|
||||
|
||||
14
Makefile
14
Makefile
@@ -29,6 +29,15 @@ build:
|
||||
release:
|
||||
> 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
|
||||
clean:
|
||||
> cargo clean
|
||||
@@ -54,6 +63,11 @@ dockertest:
|
||||
> $(MAKE) -C docker/organic_test
|
||||
> docker run --init --rm -i -t --read-only -v "$$(readlink -f ./):/source:ro" --mount type=tmpfs,destination=/tmp --mount source=cargo-cache,target=/usr/local/cargo/registry --mount source=rust-cache,target=/target --env CARGO_TARGET_DIR=/target -w /source organic-test --no-default-features --features compare --no-fail-fast --lib --test test_loader -- --test-threads $(TESTJOBS)
|
||||
|
||||
.PHONY: dockerwasmtest
|
||||
dockerwasmtest:
|
||||
> $(MAKE) -C docker/organic_test
|
||||
> docker run --init --rm -i -t --read-only -v "$$(readlink -f ./):/source:ro" --mount type=tmpfs,destination=/tmp --mount source=cargo-cache,target=/usr/local/cargo/registry --mount source=rust-cache,target=/target --env CARGO_TARGET_DIR=/target -w /source organic-test --no-default-features --features compare,wasm_test --no-fail-fast --lib --test test_loader autogen_wasm_ -- --test-threads $(TESTJOBS)
|
||||
|
||||
.PHONY: buildtest
|
||||
buildtest:
|
||||
> cargo build --no-default-features
|
||||
|
||||
@@ -2,5 +2,6 @@ FROM rustlang/rust:nightly-alpine3.17
|
||||
|
||||
RUN apk add --no-cache musl-dev
|
||||
RUN cargo install --locked --no-default-features --features ci-autoclean cargo-cache
|
||||
RUN rustup target add wasm32-unknown-unknown
|
||||
|
||||
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(exact_size_is_empty)]
|
||||
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::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::context::GlobalSettings;
|
||||
use crate::context::LocalFileAccessInterface;
|
||||
use crate::parser::parse_file_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>>(
|
||||
org_contents: P,
|
||||
@@ -68,8 +69,8 @@ pub async fn run_anonymous_compare_with_settings<'g, 's, P: AsRef<str>>(
|
||||
} else if !silent {
|
||||
println!(
|
||||
"{color}Entire document passes.{reset}",
|
||||
color = DiffResult::foreground_color(0, 255, 0),
|
||||
reset = DiffResult::reset_color(),
|
||||
color = foreground_color(0, 255, 0),
|
||||
reset = reset_color(),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -121,19 +122,10 @@ pub async fn run_compare_on_file_with_settings<'g, 's, P: AsRef<Path>>(
|
||||
} else if !silent {
|
||||
println!(
|
||||
"{color}Entire document passes.{reset}",
|
||||
color = DiffResult::foreground_color(0, 255, 0),
|
||||
reset = DiffResult::reset_color(),
|
||||
color = foreground_color(0, 255, 0),
|
||||
reset = reset_color(),
|
||||
);
|
||||
}
|
||||
|
||||
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::WarningDelayType;
|
||||
use crate::types::Year;
|
||||
use crate::util::foreground_color;
|
||||
use crate::util::reset_color;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum DiffEntry<'b, 's> {
|
||||
@@ -200,21 +202,21 @@ impl<'b, 's> DiffResult<'b, 's> {
|
||||
if self.has_bad_children() {
|
||||
format!(
|
||||
"{color}BADCHILD{reset}",
|
||||
color = DiffResult::foreground_color(255, 255, 0),
|
||||
reset = DiffResult::reset_color(),
|
||||
color = foreground_color(255, 255, 0),
|
||||
reset = reset_color(),
|
||||
)
|
||||
} else {
|
||||
format!(
|
||||
"{color}GOOD{reset}",
|
||||
color = DiffResult::foreground_color(0, 255, 0),
|
||||
reset = DiffResult::reset_color(),
|
||||
color = foreground_color(0, 255, 0),
|
||||
reset = reset_color(),
|
||||
)
|
||||
}
|
||||
}
|
||||
DiffStatus::Bad => format!(
|
||||
"{color}BAD{reset}",
|
||||
color = DiffResult::foreground_color(255, 0, 0),
|
||||
reset = DiffResult::reset_color(),
|
||||
color = foreground_color(255, 0, 0),
|
||||
reset = reset_color(),
|
||||
),
|
||||
}
|
||||
};
|
||||
@@ -239,45 +241,6 @@ impl<'b, 's> DiffResult<'b, 's> {
|
||||
.iter()
|
||||
.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> {
|
||||
@@ -295,14 +258,14 @@ impl<'b, 's> DiffLayer<'b, 's> {
|
||||
let status_text = if self.has_bad_children() {
|
||||
format!(
|
||||
"{color}BADCHILD{reset}",
|
||||
color = DiffResult::foreground_color(255, 255, 0),
|
||||
reset = DiffResult::reset_color(),
|
||||
color = foreground_color(255, 255, 0),
|
||||
reset = reset_color(),
|
||||
)
|
||||
} else {
|
||||
format!(
|
||||
"{color}GOOD{reset}",
|
||||
color = DiffResult::foreground_color(0, 255, 0),
|
||||
reset = DiffResult::reset_color(),
|
||||
color = foreground_color(0, 255, 0),
|
||||
reset = reset_color(),
|
||||
)
|
||||
};
|
||||
println!(
|
||||
|
||||
@@ -4,7 +4,6 @@ mod compare_field;
|
||||
mod diff;
|
||||
mod elisp_fact;
|
||||
mod macros;
|
||||
mod parse;
|
||||
mod sexp;
|
||||
mod util;
|
||||
pub use compare::run_anonymous_compare;
|
||||
@@ -13,3 +12,14 @@ pub use compare::run_compare_on_file;
|
||||
pub use compare::run_compare_on_file_with_settings;
|
||||
pub use compare::silent_anonymous_compare;
|
||||
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(crate) use sexp::TextWithProperties;
|
||||
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::maybe_token_to_usize;
|
||||
pub(crate) use util::EmacsStandardProperties;
|
||||
|
||||
@@ -145,20 +145,20 @@ fn assert_post_blank<'b, 's, S: StandardProperties<'s> + ?Sized>(
|
||||
Ok(())
|
||||
}
|
||||
|
||||
struct EmacsStandardProperties {
|
||||
begin: Option<usize>,
|
||||
pub(crate) struct EmacsStandardProperties {
|
||||
pub(crate) begin: Option<usize>,
|
||||
#[allow(dead_code)]
|
||||
post_affiliated: Option<usize>,
|
||||
pub(crate) post_affiliated: Option<usize>,
|
||||
#[allow(dead_code)]
|
||||
contents_begin: Option<usize>,
|
||||
pub(crate) contents_begin: Option<usize>,
|
||||
#[allow(dead_code)]
|
||||
contents_end: Option<usize>,
|
||||
end: Option<usize>,
|
||||
pub(crate) contents_end: Option<usize>,
|
||||
pub(crate) end: Option<usize>,
|
||||
#[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<'_>,
|
||||
) -> Result<EmacsStandardProperties, Box<dyn std::error::Error>> {
|
||||
let children = emacs.as_list()?;
|
||||
@@ -203,7 +203,7 @@ fn get_emacs_standard_properties(
|
||||
})
|
||||
}
|
||||
|
||||
fn maybe_token_to_usize(
|
||||
pub(crate) fn maybe_token_to_usize(
|
||||
token: Option<&Token<'_>>,
|
||||
) -> Result<Option<usize>, Box<dyn std::error::Error>> {
|
||||
Ok(token
|
||||
|
||||
10
src/lib.rs
10
src/lib.rs
@@ -3,13 +3,21 @@
|
||||
#![feature(path_file_prefix)]
|
||||
#![feature(is_sorted)]
|
||||
#![feature(test)]
|
||||
#![feature(iter_intersperse)]
|
||||
// TODO: #![warn(missing_docs)]
|
||||
#![allow(clippy::bool_assert_comparison)] // Sometimes you want the long form because its easier to see at a glance.
|
||||
|
||||
extern crate test;
|
||||
|
||||
#[cfg(feature = "compare")]
|
||||
// TODO: I only include compare to use some shared stuff like sexp and DiffResult. Ideally, this would be moved to a shared module.
|
||||
#[cfg(any(feature = "compare", feature = "wasm_test"))]
|
||||
pub mod compare;
|
||||
#[cfg(any(feature = "compare", feature = "wasm_test"))]
|
||||
pub mod util;
|
||||
#[cfg(any(feature = "wasm", feature = "wasm_test"))]
|
||||
pub mod wasm;
|
||||
#[cfg(feature = "wasm_test")]
|
||||
pub mod wasm_test;
|
||||
|
||||
mod context;
|
||||
mod error;
|
||||
|
||||
@@ -332,19 +332,19 @@ pub type HourInner = u8;
|
||||
pub type MinuteInner = u8;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Year(YearInner);
|
||||
pub struct Year(pub YearInner);
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Month(MonthInner);
|
||||
pub struct Month(pub MonthInner);
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct DayOfMonth(DayOfMonthInner);
|
||||
pub struct DayOfMonth(pub DayOfMonthInner);
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Hour(HourInner);
|
||||
pub struct Hour(pub HourInner);
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Minute(MinuteInner);
|
||||
pub struct Minute(pub MinuteInner);
|
||||
|
||||
impl Year {
|
||||
// TODO: Make a real error type instead of a boxed any error.
|
||||
|
||||
@@ -1,29 +1,55 @@
|
||||
use std::borrow::Cow;
|
||||
use std::path::Path;
|
||||
|
||||
use tokio::process::Command;
|
||||
|
||||
use crate::context::HeadlineLevelFilter;
|
||||
use crate::settings::GlobalSettings;
|
||||
use crate::settings::HeadlineLevelFilter;
|
||||
|
||||
/// Generate elisp to configure org-mode parsing settings
|
||||
///
|
||||
/// Currently only org-list-allow-alphabetical is supported.
|
||||
fn global_settings_elisp(global_settings: &GlobalSettings) -> String {
|
||||
// This string concatenation is wildly inefficient but its only called in tests 🤷.
|
||||
let mut ret = "".to_owned();
|
||||
if global_settings.list_allow_alphabetical {
|
||||
ret += "(setq org-list-allow-alphabetical t)\n"
|
||||
}
|
||||
if global_settings.tab_width != crate::settings::DEFAULT_TAB_WIDTH {
|
||||
ret += format!("(setq-default tab-width {})", global_settings.tab_width).as_str();
|
||||
}
|
||||
if global_settings.odd_levels_only != HeadlineLevelFilter::default() {
|
||||
ret += match global_settings.odd_levels_only {
|
||||
HeadlineLevelFilter::Odd => "(setq org-odd-levels-only t)\n",
|
||||
HeadlineLevelFilter::OddEven => "(setq org-odd-levels-only nil)\n",
|
||||
};
|
||||
}
|
||||
ret
|
||||
pub 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(())
|
||||
}
|
||||
|
||||
pub(crate) async fn get_emacs_version() -> Result<String, Box<dyn std::error::Error>> {
|
||||
let elisp_script = r#"(progn
|
||||
(message "%s" (version))
|
||||
)"#;
|
||||
let mut cmd = Command::new("emacs");
|
||||
let cmd = cmd
|
||||
.arg("-q")
|
||||
.arg("--no-site-file")
|
||||
.arg("--no-splash")
|
||||
.arg("--batch")
|
||||
.arg("--eval")
|
||||
.arg(elisp_script);
|
||||
|
||||
let out = cmd.output().await?;
|
||||
out.status.exit_ok()?;
|
||||
Ok(String::from_utf8(out.stderr)?)
|
||||
}
|
||||
|
||||
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>(
|
||||
@@ -144,39 +170,64 @@ where
|
||||
output
|
||||
}
|
||||
|
||||
pub async fn get_emacs_version() -> Result<String, Box<dyn std::error::Error>> {
|
||||
let elisp_script = r#"(progn
|
||||
(message "%s" (version))
|
||||
)"#;
|
||||
let mut cmd = Command::new("emacs");
|
||||
let cmd = cmd
|
||||
.arg("-q")
|
||||
.arg("--no-site-file")
|
||||
.arg("--no-splash")
|
||||
.arg("--batch")
|
||||
.arg("--eval")
|
||||
.arg(elisp_script);
|
||||
|
||||
let out = cmd.output().await?;
|
||||
out.status.exit_ok()?;
|
||||
Ok(String::from_utf8(out.stderr)?)
|
||||
/// Generate elisp to configure org-mode parsing settings
|
||||
///
|
||||
/// Currently only org-list-allow-alphabetical is supported.
|
||||
fn global_settings_elisp(global_settings: &GlobalSettings) -> String {
|
||||
// This string concatenation is wildly inefficient but its only called in tests 🤷.
|
||||
let mut ret = "".to_owned();
|
||||
if global_settings.list_allow_alphabetical {
|
||||
ret += "(setq org-list-allow-alphabetical t)\n"
|
||||
}
|
||||
if global_settings.tab_width != crate::settings::DEFAULT_TAB_WIDTH {
|
||||
ret += format!("(setq-default tab-width {})", global_settings.tab_width).as_str();
|
||||
}
|
||||
if global_settings.odd_levels_only != HeadlineLevelFilter::default() {
|
||||
ret += match global_settings.odd_levels_only {
|
||||
HeadlineLevelFilter::Odd => "(setq org-odd-levels-only t)\n",
|
||||
HeadlineLevelFilter::OddEven => "(setq org-odd-levels-only nil)\n",
|
||||
};
|
||||
}
|
||||
ret
|
||||
}
|
||||
|
||||
pub 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)?)
|
||||
fn should_use_color() -> bool {
|
||||
!std::env::var("NO_COLOR").is_ok_and(|val| !val.is_empty())
|
||||
}
|
||||
|
||||
pub(crate) fn foreground_color(red: u8, green: u8, blue: u8) -> Cow<'static, str> {
|
||||
if should_use_color() {
|
||||
format!(
|
||||
"\x1b[38;2;{red};{green};{blue}m",
|
||||
red = red,
|
||||
green = green,
|
||||
blue = blue
|
||||
)
|
||||
.into()
|
||||
} else {
|
||||
Cow::from("")
|
||||
}
|
||||
}
|
||||
|
||||
#[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 {
|
||||
""
|
||||
}
|
||||
}
|
||||
102
src/wasm/additional_property.rs
Normal file
102
src/wasm/additional_property.rs
Normal file
@@ -0,0 +1,102 @@
|
||||
use std::borrow::Cow;
|
||||
use std::collections::HashMap;
|
||||
|
||||
use serde::Deserialize;
|
||||
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, Deserialize)]
|
||||
#[serde(untagged)]
|
||||
pub enum AdditionalPropertyValue {
|
||||
SingleString(String),
|
||||
ListOfStrings(Vec<String>),
|
||||
OptionalPair {
|
||||
optval: Option<String>,
|
||||
val: String,
|
||||
},
|
||||
ObjectTree {
|
||||
#[serde(rename = "object-tree")]
|
||||
object_tree: Vec<(Option<Vec<WasmAstNode>>, Vec<WasmAstNode>)>,
|
||||
},
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Default)]
|
||||
pub struct AdditionalProperties {
|
||||
#[serde(flatten)]
|
||||
pub(crate) properties: HashMap<String, AdditionalPropertyValue>,
|
||||
}
|
||||
|
||||
impl AdditionalProperties {
|
||||
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,
|
||||
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).to_owned())
|
||||
}
|
||||
AffiliatedKeywordValue::ListOfStrings(val) => {
|
||||
AdditionalPropertyValue::ListOfStrings(
|
||||
val.iter().map(|s| (*s).to_owned()).collect(),
|
||||
)
|
||||
}
|
||||
AffiliatedKeywordValue::OptionalPair { optval, val } => {
|
||||
AdditionalPropertyValue::OptionalPair {
|
||||
optval: optval.map(|s| (*s).to_owned()),
|
||||
val: (*val).to_owned(),
|
||||
}
|
||||
}
|
||||
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 { object_tree: ret }
|
||||
}
|
||||
};
|
||||
additional_properties
|
||||
.properties
|
||||
.insert(name.clone(), converted_val);
|
||||
}
|
||||
Ok(additional_properties)
|
||||
}
|
||||
);
|
||||
33
src/wasm/angle_link.rs
Normal file
33
src/wasm/angle_link.rs
Normal file
@@ -0,0 +1,33 @@
|
||||
use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
|
||||
use super::ast_node::WasmAstNode;
|
||||
use super::macros::to_wasm;
|
||||
use super::to_wasm::ToWasm;
|
||||
use super::AdditionalProperties;
|
||||
use crate::compare::ElispFact;
|
||||
use crate::types::AngleLink;
|
||||
use crate::wasm::to_wasm::ToWasmStandardProperties;
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct WasmAngleLink {
|
||||
#[serde(flatten)]
|
||||
pub(crate) additional_properties: AdditionalProperties,
|
||||
}
|
||||
|
||||
to_wasm!(
|
||||
WasmAngleLink,
|
||||
AngleLink<'s>,
|
||||
original,
|
||||
wasm_context,
|
||||
{ WasmAstNode::AngleLink(original) },
|
||||
{ "TODO".into() },
|
||||
{
|
||||
Ok((
|
||||
Vec::new(),
|
||||
WasmAngleLink {
|
||||
additional_properties: AdditionalProperties::default(),
|
||||
},
|
||||
))
|
||||
}
|
||||
);
|
||||
142
src/wasm/ast_node.rs
Normal file
142
src/wasm/ast_node.rs
Normal file
@@ -0,0 +1,142 @@
|
||||
use serde::Deserialize;
|
||||
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;
|
||||
use super::WasmStandardProperties;
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct WasmAstNodeWrapper<I> {
|
||||
#[serde(rename = "ast-node")]
|
||||
pub(crate) ast_node: String,
|
||||
#[serde(rename = "standard-properties")]
|
||||
pub(crate) standard_properties: WasmStandardProperties,
|
||||
#[serde(rename = "children")]
|
||||
pub(crate) children: Vec<WasmAstNode>,
|
||||
#[serde(rename = "properties")]
|
||||
pub(crate) properties: I,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
#[serde(untagged)]
|
||||
pub enum WasmAstNode {
|
||||
// Document Nodes
|
||||
Document(WasmAstNodeWrapper<WasmDocument>),
|
||||
Headline(WasmAstNodeWrapper<WasmHeadline>),
|
||||
Section(WasmAstNodeWrapper<WasmSection>),
|
||||
// Elements
|
||||
Paragraph(WasmAstNodeWrapper<WasmParagraph>),
|
||||
PlainList(WasmAstNodeWrapper<WasmPlainList>),
|
||||
PlainListItem(WasmAstNodeWrapper<WasmPlainListItem>),
|
||||
CenterBlock(WasmAstNodeWrapper<WasmCenterBlock>),
|
||||
QuoteBlock(WasmAstNodeWrapper<WasmQuoteBlock>),
|
||||
SpecialBlock(WasmAstNodeWrapper<WasmSpecialBlock>),
|
||||
DynamicBlock(WasmAstNodeWrapper<WasmDynamicBlock>),
|
||||
FootnoteDefinition(WasmAstNodeWrapper<WasmFootnoteDefinition>),
|
||||
Comment(WasmAstNodeWrapper<WasmComment>),
|
||||
Drawer(WasmAstNodeWrapper<WasmDrawer>),
|
||||
PropertyDrawer(WasmAstNodeWrapper<WasmPropertyDrawer>),
|
||||
NodeProperty(WasmAstNodeWrapper<WasmNodeProperty>),
|
||||
Table(WasmAstNodeWrapper<WasmTable>),
|
||||
TableRow(WasmAstNodeWrapper<WasmTableRow>),
|
||||
VerseBlock(WasmAstNodeWrapper<WasmVerseBlock>),
|
||||
CommentBlock(WasmAstNodeWrapper<WasmCommentBlock>),
|
||||
ExampleBlock(WasmAstNodeWrapper<WasmExampleBlock>),
|
||||
ExportBlock(WasmAstNodeWrapper<WasmExportBlock>),
|
||||
SrcBlock(WasmAstNodeWrapper<WasmSrcBlock>),
|
||||
Clock(WasmAstNodeWrapper<WasmClock>),
|
||||
DiarySexp(WasmAstNodeWrapper<WasmDiarySexp>),
|
||||
Planning(WasmAstNodeWrapper<WasmPlanning>),
|
||||
FixedWidthArea(WasmAstNodeWrapper<WasmFixedWidthArea>),
|
||||
HorizontalRule(WasmAstNodeWrapper<WasmHorizontalRule>),
|
||||
Keyword(WasmAstNodeWrapper<WasmKeyword>),
|
||||
BabelCall(WasmAstNodeWrapper<WasmBabelCall>),
|
||||
LatexEnvironment(WasmAstNodeWrapper<WasmLatexEnvironment>),
|
||||
// Objects
|
||||
Bold(WasmAstNodeWrapper<WasmBold>),
|
||||
Italic(WasmAstNodeWrapper<WasmItalic>),
|
||||
Underline(WasmAstNodeWrapper<WasmUnderline>),
|
||||
StrikeThrough(WasmAstNodeWrapper<WasmStrikeThrough>),
|
||||
Code(WasmAstNodeWrapper<WasmCode>),
|
||||
Verbatim(WasmAstNodeWrapper<WasmVerbatim>),
|
||||
PlainText(WasmAstNodeWrapper<WasmPlainText>),
|
||||
RegularLink(WasmAstNodeWrapper<WasmRegularLink>),
|
||||
RadioLink(WasmAstNodeWrapper<WasmRadioLink>),
|
||||
RadioTarget(WasmAstNodeWrapper<WasmRadioTarget>),
|
||||
PlainLink(WasmAstNodeWrapper<WasmPlainLink>),
|
||||
AngleLink(WasmAstNodeWrapper<WasmAngleLink>),
|
||||
OrgMacro(WasmAstNodeWrapper<WasmOrgMacro>),
|
||||
Entity(WasmAstNodeWrapper<WasmEntity>),
|
||||
LatexFragment(WasmAstNodeWrapper<WasmLatexFragment>),
|
||||
ExportSnippet(WasmAstNodeWrapper<WasmExportSnippet>),
|
||||
FootnoteReference(WasmAstNodeWrapper<WasmFootnoteReference>),
|
||||
Citation(WasmAstNodeWrapper<WasmCitation>),
|
||||
CitationReference(WasmAstNodeWrapper<WasmCitationReference>),
|
||||
InlineBabelCall(WasmAstNodeWrapper<WasmInlineBabelCall>),
|
||||
InlineSourceBlock(WasmAstNodeWrapper<WasmInlineSourceBlock>),
|
||||
LineBreak(WasmAstNodeWrapper<WasmLineBreak>),
|
||||
Target(WasmAstNodeWrapper<WasmTarget>),
|
||||
StatisticsCookie(WasmAstNodeWrapper<WasmStatisticsCookie>),
|
||||
Subscript(WasmAstNodeWrapper<WasmSubscript>),
|
||||
Superscript(WasmAstNodeWrapper<WasmSuperscript>),
|
||||
TableCell(WasmAstNodeWrapper<WasmTableCell>),
|
||||
Timestamp(WasmAstNodeWrapper<WasmTimestamp>),
|
||||
}
|
||||
|
||||
impl WasmAstNode {}
|
||||
33
src/wasm/babel_call.rs
Normal file
33
src/wasm/babel_call.rs
Normal file
@@ -0,0 +1,33 @@
|
||||
use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
|
||||
use super::ast_node::WasmAstNode;
|
||||
use super::macros::to_wasm;
|
||||
use super::to_wasm::ToWasm;
|
||||
use super::AdditionalProperties;
|
||||
use crate::compare::ElispFact;
|
||||
use crate::types::BabelCall;
|
||||
use crate::wasm::to_wasm::ToWasmStandardProperties;
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct WasmBabelCall {
|
||||
#[serde(flatten)]
|
||||
pub(crate) additional_properties: AdditionalProperties,
|
||||
}
|
||||
|
||||
to_wasm!(
|
||||
WasmBabelCall,
|
||||
BabelCall<'s>,
|
||||
original,
|
||||
wasm_context,
|
||||
{ WasmAstNode::BabelCall(original) },
|
||||
{ "TODO".into() },
|
||||
{
|
||||
Ok((
|
||||
Vec::new(),
|
||||
WasmBabelCall {
|
||||
additional_properties: AdditionalProperties::default(),
|
||||
},
|
||||
))
|
||||
}
|
||||
);
|
||||
34
src/wasm/bold.rs
Normal file
34
src/wasm/bold.rs
Normal file
@@ -0,0 +1,34 @@
|
||||
use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
|
||||
use super::ast_node::WasmAstNode;
|
||||
use super::macros::to_wasm;
|
||||
use super::to_wasm::ToWasm;
|
||||
use crate::compare::ElispFact;
|
||||
use crate::types::Bold;
|
||||
use crate::wasm::to_wasm::ToWasmStandardProperties;
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct WasmBold {}
|
||||
|
||||
to_wasm!(
|
||||
WasmBold,
|
||||
Bold<'s>,
|
||||
original,
|
||||
wasm_context,
|
||||
{ WasmAstNode::Bold(original) },
|
||||
{ "bold".into() },
|
||||
{
|
||||
let children = original
|
||||
.children
|
||||
.iter()
|
||||
.map(|child| {
|
||||
child
|
||||
.to_wasm(wasm_context.clone())
|
||||
.map(Into::<WasmAstNode>::into)
|
||||
})
|
||||
.collect::<Result<Vec<_>, _>>()?;
|
||||
|
||||
Ok((children, WasmBold {}))
|
||||
}
|
||||
);
|
||||
43
src/wasm/center_block.rs
Normal file
43
src/wasm/center_block.rs
Normal file
@@ -0,0 +1,43 @@
|
||||
use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
|
||||
use super::ast_node::WasmAstNode;
|
||||
use super::macros::to_wasm;
|
||||
use super::to_wasm::ToWasm;
|
||||
use super::AdditionalProperties;
|
||||
use crate::compare::ElispFact;
|
||||
use crate::types::CenterBlock;
|
||||
use crate::wasm::to_wasm::ToWasmStandardProperties;
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct WasmCenterBlock {
|
||||
#[serde(flatten)]
|
||||
pub(crate) additional_properties: AdditionalProperties,
|
||||
}
|
||||
|
||||
to_wasm!(
|
||||
WasmCenterBlock,
|
||||
CenterBlock<'s>,
|
||||
original,
|
||||
wasm_context,
|
||||
{ WasmAstNode::CenterBlock(original) },
|
||||
{ "TODO".into() },
|
||||
{
|
||||
let children = original
|
||||
.children
|
||||
.iter()
|
||||
.map(|child| {
|
||||
child
|
||||
.to_wasm(wasm_context.clone())
|
||||
.map(Into::<WasmAstNode>::into)
|
||||
})
|
||||
.collect::<Result<Vec<_>, _>>()?;
|
||||
|
||||
Ok((
|
||||
children,
|
||||
WasmCenterBlock {
|
||||
additional_properties: AdditionalProperties::default(),
|
||||
},
|
||||
))
|
||||
}
|
||||
);
|
||||
43
src/wasm/citation.rs
Normal file
43
src/wasm/citation.rs
Normal file
@@ -0,0 +1,43 @@
|
||||
use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
|
||||
use super::ast_node::WasmAstNode;
|
||||
use super::macros::to_wasm;
|
||||
use super::to_wasm::ToWasm;
|
||||
use super::AdditionalProperties;
|
||||
use crate::compare::ElispFact;
|
||||
use crate::types::Citation;
|
||||
use crate::wasm::to_wasm::ToWasmStandardProperties;
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct WasmCitation {
|
||||
#[serde(flatten)]
|
||||
pub(crate) additional_properties: AdditionalProperties,
|
||||
}
|
||||
|
||||
to_wasm!(
|
||||
WasmCitation,
|
||||
Citation<'s>,
|
||||
original,
|
||||
wasm_context,
|
||||
{ WasmAstNode::Citation(original) },
|
||||
{ "TODO".into() },
|
||||
{
|
||||
let children = original
|
||||
.children
|
||||
.iter()
|
||||
.map(|child| {
|
||||
child
|
||||
.to_wasm(wasm_context.clone())
|
||||
.map(Into::<WasmAstNode>::into)
|
||||
})
|
||||
.collect::<Result<Vec<_>, _>>()?;
|
||||
|
||||
Ok((
|
||||
children,
|
||||
WasmCitation {
|
||||
additional_properties: AdditionalProperties::default(),
|
||||
},
|
||||
))
|
||||
}
|
||||
);
|
||||
33
src/wasm/citation_reference.rs
Normal file
33
src/wasm/citation_reference.rs
Normal file
@@ -0,0 +1,33 @@
|
||||
use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
|
||||
use super::ast_node::WasmAstNode;
|
||||
use super::macros::to_wasm;
|
||||
use super::to_wasm::ToWasm;
|
||||
use super::AdditionalProperties;
|
||||
use crate::compare::ElispFact;
|
||||
use crate::types::CitationReference;
|
||||
use crate::wasm::to_wasm::ToWasmStandardProperties;
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct WasmCitationReference {
|
||||
#[serde(flatten)]
|
||||
pub(crate) additional_properties: AdditionalProperties,
|
||||
}
|
||||
|
||||
to_wasm!(
|
||||
WasmCitationReference,
|
||||
CitationReference<'s>,
|
||||
original,
|
||||
wasm_context,
|
||||
{ WasmAstNode::CitationReference(original) },
|
||||
{ "TODO".into() },
|
||||
{
|
||||
Ok((
|
||||
Vec::new(),
|
||||
WasmCitationReference {
|
||||
additional_properties: AdditionalProperties::default(),
|
||||
},
|
||||
))
|
||||
}
|
||||
);
|
||||
33
src/wasm/clock.rs
Normal file
33
src/wasm/clock.rs
Normal file
@@ -0,0 +1,33 @@
|
||||
use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
|
||||
use super::ast_node::WasmAstNode;
|
||||
use super::macros::to_wasm;
|
||||
use super::to_wasm::ToWasm;
|
||||
use super::AdditionalProperties;
|
||||
use crate::compare::ElispFact;
|
||||
use crate::types::Clock;
|
||||
use crate::wasm::to_wasm::ToWasmStandardProperties;
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct WasmClock {
|
||||
#[serde(flatten)]
|
||||
pub(crate) additional_properties: AdditionalProperties,
|
||||
}
|
||||
|
||||
to_wasm!(
|
||||
WasmClock,
|
||||
Clock<'s>,
|
||||
original,
|
||||
wasm_context,
|
||||
{ WasmAstNode::Clock(original) },
|
||||
{ "TODO".into() },
|
||||
{
|
||||
Ok((
|
||||
Vec::new(),
|
||||
WasmClock {
|
||||
additional_properties: AdditionalProperties::default(),
|
||||
},
|
||||
))
|
||||
}
|
||||
);
|
||||
33
src/wasm/code.rs
Normal file
33
src/wasm/code.rs
Normal file
@@ -0,0 +1,33 @@
|
||||
use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
|
||||
use super::ast_node::WasmAstNode;
|
||||
use super::macros::to_wasm;
|
||||
use super::to_wasm::ToWasm;
|
||||
use super::AdditionalProperties;
|
||||
use crate::compare::ElispFact;
|
||||
use crate::types::Code;
|
||||
use crate::wasm::to_wasm::ToWasmStandardProperties;
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct WasmCode {
|
||||
#[serde(flatten)]
|
||||
pub(crate) additional_properties: AdditionalProperties,
|
||||
}
|
||||
|
||||
to_wasm!(
|
||||
WasmCode,
|
||||
Code<'s>,
|
||||
original,
|
||||
wasm_context,
|
||||
{ WasmAstNode::Code(original) },
|
||||
{ "TODO".into() },
|
||||
{
|
||||
Ok((
|
||||
Vec::new(),
|
||||
WasmCode {
|
||||
additional_properties: AdditionalProperties::default(),
|
||||
},
|
||||
))
|
||||
}
|
||||
);
|
||||
31
src/wasm/comment.rs
Normal file
31
src/wasm/comment.rs
Normal file
@@ -0,0 +1,31 @@
|
||||
use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
|
||||
use super::ast_node::WasmAstNode;
|
||||
use super::macros::to_wasm;
|
||||
use super::to_wasm::ToWasm;
|
||||
use crate::compare::ElispFact;
|
||||
use crate::types::Comment;
|
||||
use crate::wasm::to_wasm::ToWasmStandardProperties;
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct WasmComment {
|
||||
pub(crate) value: String,
|
||||
}
|
||||
|
||||
to_wasm!(
|
||||
WasmComment,
|
||||
Comment<'s>,
|
||||
original,
|
||||
wasm_context,
|
||||
{ WasmAstNode::Comment(original) },
|
||||
{ "comment".into() },
|
||||
{
|
||||
Ok((
|
||||
Vec::new(),
|
||||
WasmComment {
|
||||
value: original.get_value(),
|
||||
},
|
||||
))
|
||||
}
|
||||
);
|
||||
33
src/wasm/comment_block.rs
Normal file
33
src/wasm/comment_block.rs
Normal file
@@ -0,0 +1,33 @@
|
||||
use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
|
||||
use super::ast_node::WasmAstNode;
|
||||
use super::macros::to_wasm;
|
||||
use super::to_wasm::ToWasm;
|
||||
use super::AdditionalProperties;
|
||||
use crate::compare::ElispFact;
|
||||
use crate::types::CommentBlock;
|
||||
use crate::wasm::to_wasm::ToWasmStandardProperties;
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct WasmCommentBlock {
|
||||
#[serde(flatten)]
|
||||
pub(crate) additional_properties: AdditionalProperties,
|
||||
}
|
||||
|
||||
to_wasm!(
|
||||
WasmCommentBlock,
|
||||
CommentBlock<'s>,
|
||||
original,
|
||||
wasm_context,
|
||||
{ WasmAstNode::CommentBlock(original) },
|
||||
{ "TODO".into() },
|
||||
{
|
||||
Ok((
|
||||
Vec::new(),
|
||||
WasmCommentBlock {
|
||||
additional_properties: AdditionalProperties::default(),
|
||||
},
|
||||
))
|
||||
}
|
||||
);
|
||||
33
src/wasm/diary_sexp.rs
Normal file
33
src/wasm/diary_sexp.rs
Normal file
@@ -0,0 +1,33 @@
|
||||
use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
|
||||
use super::ast_node::WasmAstNode;
|
||||
use super::macros::to_wasm;
|
||||
use super::to_wasm::ToWasm;
|
||||
use super::AdditionalProperties;
|
||||
use crate::compare::ElispFact;
|
||||
use crate::types::DiarySexp;
|
||||
use crate::wasm::to_wasm::ToWasmStandardProperties;
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct WasmDiarySexp {
|
||||
#[serde(flatten)]
|
||||
pub(crate) additional_properties: AdditionalProperties,
|
||||
}
|
||||
|
||||
to_wasm!(
|
||||
WasmDiarySexp,
|
||||
DiarySexp<'s>,
|
||||
original,
|
||||
wasm_context,
|
||||
{ WasmAstNode::DiarySexp(original) },
|
||||
{ "TODO".into() },
|
||||
{
|
||||
Ok((
|
||||
Vec::new(),
|
||||
WasmDiarySexp {
|
||||
additional_properties: AdditionalProperties::default(),
|
||||
},
|
||||
))
|
||||
}
|
||||
);
|
||||
69
src/wasm/document.rs
Normal file
69
src/wasm/document.rs
Normal file
@@ -0,0 +1,69 @@
|
||||
use std::path::PathBuf;
|
||||
|
||||
use serde::Deserialize;
|
||||
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::to_wasm::ToWasm;
|
||||
use crate::compare::ElispFact;
|
||||
use crate::types::Document;
|
||||
use crate::wasm::to_wasm::ToWasmStandardProperties;
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct WasmDocument {
|
||||
#[serde(flatten)]
|
||||
pub(crate) additional_properties: AdditionalProperties,
|
||||
#[serde(rename = "CATEGORY")]
|
||||
pub(crate) category: Option<String>,
|
||||
pub(crate) path: Option<PathBuf>,
|
||||
}
|
||||
|
||||
to_wasm!(
|
||||
WasmDocument,
|
||||
Document<'s>,
|
||||
original,
|
||||
wasm_context,
|
||||
{ WasmAstNode::Document(original) },
|
||||
{ "org-data".into() },
|
||||
{
|
||||
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("").to_owned()),
|
||||
)
|
||||
}) {
|
||||
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((
|
||||
children,
|
||||
WasmDocument {
|
||||
additional_properties,
|
||||
category: category.map(str::to_owned),
|
||||
path,
|
||||
},
|
||||
))
|
||||
}
|
||||
);
|
||||
43
src/wasm/drawer.rs
Normal file
43
src/wasm/drawer.rs
Normal file
@@ -0,0 +1,43 @@
|
||||
use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
|
||||
use super::ast_node::WasmAstNode;
|
||||
use super::macros::to_wasm;
|
||||
use super::to_wasm::ToWasm;
|
||||
use super::AdditionalProperties;
|
||||
use crate::compare::ElispFact;
|
||||
use crate::types::Drawer;
|
||||
use crate::wasm::to_wasm::ToWasmStandardProperties;
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct WasmDrawer {
|
||||
#[serde(flatten)]
|
||||
pub(crate) additional_properties: AdditionalProperties,
|
||||
}
|
||||
|
||||
to_wasm!(
|
||||
WasmDrawer,
|
||||
Drawer<'s>,
|
||||
original,
|
||||
wasm_context,
|
||||
{ WasmAstNode::Drawer(original) },
|
||||
{ "TODO".into() },
|
||||
{
|
||||
let children = original
|
||||
.children
|
||||
.iter()
|
||||
.map(|child| {
|
||||
child
|
||||
.to_wasm(wasm_context.clone())
|
||||
.map(Into::<WasmAstNode>::into)
|
||||
})
|
||||
.collect::<Result<Vec<_>, _>>()?;
|
||||
|
||||
Ok((
|
||||
children,
|
||||
WasmDrawer {
|
||||
additional_properties: AdditionalProperties::default(),
|
||||
},
|
||||
))
|
||||
}
|
||||
);
|
||||
43
src/wasm/dynamic_block.rs
Normal file
43
src/wasm/dynamic_block.rs
Normal file
@@ -0,0 +1,43 @@
|
||||
use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
|
||||
use super::ast_node::WasmAstNode;
|
||||
use super::macros::to_wasm;
|
||||
use super::to_wasm::ToWasm;
|
||||
use super::AdditionalProperties;
|
||||
use crate::compare::ElispFact;
|
||||
use crate::types::DynamicBlock;
|
||||
use crate::wasm::to_wasm::ToWasmStandardProperties;
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct WasmDynamicBlock {
|
||||
#[serde(flatten)]
|
||||
pub(crate) additional_properties: AdditionalProperties,
|
||||
}
|
||||
|
||||
to_wasm!(
|
||||
WasmDynamicBlock,
|
||||
DynamicBlock<'s>,
|
||||
original,
|
||||
wasm_context,
|
||||
{ WasmAstNode::DynamicBlock(original) },
|
||||
{ "TODO".into() },
|
||||
{
|
||||
let children = original
|
||||
.children
|
||||
.iter()
|
||||
.map(|child| {
|
||||
child
|
||||
.to_wasm(wasm_context.clone())
|
||||
.map(Into::<WasmAstNode>::into)
|
||||
})
|
||||
.collect::<Result<Vec<_>, _>>()?;
|
||||
|
||||
Ok((
|
||||
children,
|
||||
WasmDynamicBlock {
|
||||
additional_properties: AdditionalProperties::default(),
|
||||
},
|
||||
))
|
||||
}
|
||||
);
|
||||
33
src/wasm/entity.rs
Normal file
33
src/wasm/entity.rs
Normal file
@@ -0,0 +1,33 @@
|
||||
use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
|
||||
use super::ast_node::WasmAstNode;
|
||||
use super::macros::to_wasm;
|
||||
use super::to_wasm::ToWasm;
|
||||
use super::AdditionalProperties;
|
||||
use crate::compare::ElispFact;
|
||||
use crate::types::Entity;
|
||||
use crate::wasm::to_wasm::ToWasmStandardProperties;
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct WasmEntity {
|
||||
#[serde(flatten)]
|
||||
pub(crate) additional_properties: AdditionalProperties,
|
||||
}
|
||||
|
||||
to_wasm!(
|
||||
WasmEntity,
|
||||
Entity<'s>,
|
||||
original,
|
||||
wasm_context,
|
||||
{ WasmAstNode::Entity(original) },
|
||||
{ "TODO".into() },
|
||||
{
|
||||
Ok((
|
||||
Vec::new(),
|
||||
WasmEntity {
|
||||
additional_properties: AdditionalProperties::default(),
|
||||
},
|
||||
))
|
||||
}
|
||||
);
|
||||
33
src/wasm/example_block.rs
Normal file
33
src/wasm/example_block.rs
Normal file
@@ -0,0 +1,33 @@
|
||||
use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
|
||||
use super::ast_node::WasmAstNode;
|
||||
use super::macros::to_wasm;
|
||||
use super::to_wasm::ToWasm;
|
||||
use super::AdditionalProperties;
|
||||
use crate::compare::ElispFact;
|
||||
use crate::types::ExampleBlock;
|
||||
use crate::wasm::to_wasm::ToWasmStandardProperties;
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct WasmExampleBlock {
|
||||
#[serde(flatten)]
|
||||
pub(crate) additional_properties: AdditionalProperties,
|
||||
}
|
||||
|
||||
to_wasm!(
|
||||
WasmExampleBlock,
|
||||
ExampleBlock<'s>,
|
||||
original,
|
||||
wasm_context,
|
||||
{ WasmAstNode::ExampleBlock(original) },
|
||||
{ "TODO".into() },
|
||||
{
|
||||
Ok((
|
||||
Vec::new(),
|
||||
WasmExampleBlock {
|
||||
additional_properties: AdditionalProperties::default(),
|
||||
},
|
||||
))
|
||||
}
|
||||
);
|
||||
33
src/wasm/export_block.rs
Normal file
33
src/wasm/export_block.rs
Normal file
@@ -0,0 +1,33 @@
|
||||
use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
|
||||
use super::ast_node::WasmAstNode;
|
||||
use super::macros::to_wasm;
|
||||
use super::to_wasm::ToWasm;
|
||||
use super::AdditionalProperties;
|
||||
use crate::compare::ElispFact;
|
||||
use crate::types::ExportBlock;
|
||||
use crate::wasm::to_wasm::ToWasmStandardProperties;
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct WasmExportBlock {
|
||||
#[serde(flatten)]
|
||||
pub(crate) additional_properties: AdditionalProperties,
|
||||
}
|
||||
|
||||
to_wasm!(
|
||||
WasmExportBlock,
|
||||
ExportBlock<'s>,
|
||||
original,
|
||||
wasm_context,
|
||||
{ WasmAstNode::ExportBlock(original) },
|
||||
{ "TODO".into() },
|
||||
{
|
||||
Ok((
|
||||
Vec::new(),
|
||||
WasmExportBlock {
|
||||
additional_properties: AdditionalProperties::default(),
|
||||
},
|
||||
))
|
||||
}
|
||||
);
|
||||
33
src/wasm/export_snippet.rs
Normal file
33
src/wasm/export_snippet.rs
Normal file
@@ -0,0 +1,33 @@
|
||||
use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
|
||||
use super::ast_node::WasmAstNode;
|
||||
use super::macros::to_wasm;
|
||||
use super::to_wasm::ToWasm;
|
||||
use super::AdditionalProperties;
|
||||
use crate::compare::ElispFact;
|
||||
use crate::types::ExportSnippet;
|
||||
use crate::wasm::to_wasm::ToWasmStandardProperties;
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct WasmExportSnippet {
|
||||
#[serde(flatten)]
|
||||
pub(crate) additional_properties: AdditionalProperties,
|
||||
}
|
||||
|
||||
to_wasm!(
|
||||
WasmExportSnippet,
|
||||
ExportSnippet<'s>,
|
||||
original,
|
||||
wasm_context,
|
||||
{ WasmAstNode::ExportSnippet(original) },
|
||||
{ "TODO".into() },
|
||||
{
|
||||
Ok((
|
||||
Vec::new(),
|
||||
WasmExportSnippet {
|
||||
additional_properties: AdditionalProperties::default(),
|
||||
},
|
||||
))
|
||||
}
|
||||
);
|
||||
42
src/wasm/fixed_width_area.rs
Normal file
42
src/wasm/fixed_width_area.rs
Normal file
@@ -0,0 +1,42 @@
|
||||
use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
|
||||
use super::ast_node::WasmAstNode;
|
||||
use super::macros::to_wasm;
|
||||
use super::to_wasm::ToWasm;
|
||||
use super::AdditionalProperties;
|
||||
use crate::compare::ElispFact;
|
||||
use crate::types::FixedWidthArea;
|
||||
use crate::types::GetAffiliatedKeywords;
|
||||
use crate::wasm::to_wasm::ToWasmStandardProperties;
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct WasmFixedWidthArea {
|
||||
#[serde(flatten)]
|
||||
pub(crate) additional_properties: AdditionalProperties,
|
||||
pub(crate) value: String,
|
||||
}
|
||||
|
||||
to_wasm!(
|
||||
WasmFixedWidthArea,
|
||||
FixedWidthArea<'s>,
|
||||
original,
|
||||
wasm_context,
|
||||
{ WasmAstNode::FixedWidthArea(original) },
|
||||
{ "fixed-width".into() },
|
||||
{
|
||||
let additional_properties = original
|
||||
.get_affiliated_keywords()
|
||||
.to_wasm(wasm_context.clone())?;
|
||||
|
||||
let value = original.get_value();
|
||||
|
||||
Ok((
|
||||
Vec::new(),
|
||||
WasmFixedWidthArea {
|
||||
additional_properties,
|
||||
value,
|
||||
},
|
||||
))
|
||||
}
|
||||
);
|
||||
43
src/wasm/footnote_definition.rs
Normal file
43
src/wasm/footnote_definition.rs
Normal file
@@ -0,0 +1,43 @@
|
||||
use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
|
||||
use super::ast_node::WasmAstNode;
|
||||
use super::macros::to_wasm;
|
||||
use super::to_wasm::ToWasm;
|
||||
use super::AdditionalProperties;
|
||||
use crate::compare::ElispFact;
|
||||
use crate::types::FootnoteDefinition;
|
||||
use crate::wasm::to_wasm::ToWasmStandardProperties;
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct WasmFootnoteDefinition {
|
||||
#[serde(flatten)]
|
||||
pub(crate) additional_properties: AdditionalProperties,
|
||||
}
|
||||
|
||||
to_wasm!(
|
||||
WasmFootnoteDefinition,
|
||||
FootnoteDefinition<'s>,
|
||||
original,
|
||||
wasm_context,
|
||||
{ WasmAstNode::FootnoteDefinition(original) },
|
||||
{ "TODO".into() },
|
||||
{
|
||||
let children = original
|
||||
.children
|
||||
.iter()
|
||||
.map(|child| {
|
||||
child
|
||||
.to_wasm(wasm_context.clone())
|
||||
.map(Into::<WasmAstNode>::into)
|
||||
})
|
||||
.collect::<Result<Vec<_>, _>>()?;
|
||||
|
||||
Ok((
|
||||
children,
|
||||
WasmFootnoteDefinition {
|
||||
additional_properties: AdditionalProperties::default(),
|
||||
},
|
||||
))
|
||||
}
|
||||
);
|
||||
33
src/wasm/footnote_reference.rs
Normal file
33
src/wasm/footnote_reference.rs
Normal file
@@ -0,0 +1,33 @@
|
||||
use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
|
||||
use super::ast_node::WasmAstNode;
|
||||
use super::macros::to_wasm;
|
||||
use super::to_wasm::ToWasm;
|
||||
use super::AdditionalProperties;
|
||||
use crate::compare::ElispFact;
|
||||
use crate::types::FootnoteReference;
|
||||
use crate::wasm::to_wasm::ToWasmStandardProperties;
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct WasmFootnoteReference {
|
||||
#[serde(flatten)]
|
||||
pub(crate) additional_properties: AdditionalProperties,
|
||||
}
|
||||
|
||||
to_wasm!(
|
||||
WasmFootnoteReference,
|
||||
FootnoteReference<'s>,
|
||||
original,
|
||||
wasm_context,
|
||||
{ WasmAstNode::FootnoteReference(original) },
|
||||
{ "TODO".into() },
|
||||
{
|
||||
Ok((
|
||||
Vec::new(),
|
||||
WasmFootnoteReference {
|
||||
additional_properties: AdditionalProperties::default(),
|
||||
},
|
||||
))
|
||||
}
|
||||
);
|
||||
136
src/wasm/headline.rs
Normal file
136
src/wasm/headline.rs
Normal file
@@ -0,0 +1,136 @@
|
||||
use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
|
||||
use super::ast_node::WasmAstNode;
|
||||
use super::macros::to_wasm;
|
||||
use super::to_wasm::ToWasm;
|
||||
use super::AdditionalProperties;
|
||||
use super::AdditionalPropertyValue;
|
||||
use crate::compare::ElispFact;
|
||||
use crate::types::Heading;
|
||||
use crate::types::HeadlineLevel;
|
||||
use crate::types::PriorityCookie;
|
||||
use crate::types::TodoKeywordType;
|
||||
use crate::wasm::to_wasm::ToWasmStandardProperties;
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct WasmHeadline {
|
||||
#[serde(flatten)]
|
||||
pub(crate) additional_properties: AdditionalProperties,
|
||||
pub(crate) level: HeadlineLevel,
|
||||
pub(crate) tags: Vec<String>,
|
||||
#[serde(rename = "todo-keyword")]
|
||||
pub(crate) todo_keyword: Option<String>,
|
||||
#[serde(rename = "todo-type")]
|
||||
pub(crate) todo_type: Option<String>,
|
||||
pub(crate) title: Vec<WasmAstNode>,
|
||||
pub(crate) priority: Option<PriorityCookie>,
|
||||
#[serde(rename = "archivedp")]
|
||||
pub(crate) is_archived: bool,
|
||||
#[serde(rename = "commentedp")]
|
||||
pub(crate) is_comment: bool,
|
||||
#[serde(rename = "raw-value")]
|
||||
pub(crate) raw_value: String,
|
||||
#[serde(rename = "footnote-section-p")]
|
||||
pub(crate) is_footnote_section: bool,
|
||||
pub(crate) scheduled: Option<Box<WasmAstNode>>,
|
||||
pub(crate) deadline: Option<Box<WasmAstNode>>,
|
||||
pub(crate) closed: Option<Box<WasmAstNode>>,
|
||||
#[serde(rename = "pre-blank")]
|
||||
pub(crate) pre_blank: usize,
|
||||
}
|
||||
|
||||
to_wasm!(
|
||||
WasmHeadline,
|
||||
Heading<'s>,
|
||||
original,
|
||||
wasm_context,
|
||||
{ WasmAstNode::Headline(original) },
|
||||
{ "headline".into() },
|
||||
{
|
||||
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("").to_owned()),
|
||||
)
|
||||
}) {
|
||||
additional_properties.properties.insert(name, val);
|
||||
}
|
||||
|
||||
let children = original
|
||||
.children
|
||||
.iter()
|
||||
.map(|child| {
|
||||
child
|
||||
.to_wasm(wasm_context.clone())
|
||||
.map(Into::<WasmAstNode>::into)
|
||||
})
|
||||
.collect::<Result<Vec<_>, _>>()?;
|
||||
|
||||
Ok((
|
||||
children,
|
||||
WasmHeadline {
|
||||
additional_properties,
|
||||
level: original.level,
|
||||
tags: original.tags.iter().map(|tag| (*tag).to_owned()).collect(),
|
||||
todo_keyword: original
|
||||
.todo_keyword
|
||||
.as_ref()
|
||||
.map(|(_, keyword)| (*keyword).to_owned()),
|
||||
todo_type: original
|
||||
.todo_keyword
|
||||
.as_ref()
|
||||
.map(|(keyword, _)| match keyword {
|
||||
TodoKeywordType::Done => "done".to_owned(),
|
||||
TodoKeywordType::Todo => "todo".to_owned(),
|
||||
}),
|
||||
title: original
|
||||
.title
|
||||
.iter()
|
||||
.map(|child| {
|
||||
child
|
||||
.to_wasm(wasm_context.clone())
|
||||
.map(Into::<WasmAstNode>::into)
|
||||
})
|
||||
.collect::<Result<Vec<_>, _>>()?,
|
||||
priority: original.priority_cookie,
|
||||
is_archived: original.is_archived,
|
||||
is_comment: original.is_comment,
|
||||
raw_value: original.get_raw_value(),
|
||||
is_footnote_section: original.is_footnote_section,
|
||||
scheduled: original
|
||||
.scheduled
|
||||
.as_ref()
|
||||
.map(|child| {
|
||||
child
|
||||
.to_wasm(wasm_context.clone())
|
||||
.map(Into::<WasmAstNode>::into)
|
||||
})
|
||||
.map_or(Ok(None), |r| r.map(Some))?
|
||||
.map(|child| Box::new(child)),
|
||||
deadline: original
|
||||
.deadline
|
||||
.as_ref()
|
||||
.map(|child| {
|
||||
child
|
||||
.to_wasm(wasm_context.clone())
|
||||
.map(Into::<WasmAstNode>::into)
|
||||
})
|
||||
.map_or(Ok(None), |r| r.map(Some))?
|
||||
.map(|child| Box::new(child)),
|
||||
closed: original
|
||||
.closed
|
||||
.as_ref()
|
||||
.map(|child| {
|
||||
child
|
||||
.to_wasm(wasm_context.clone())
|
||||
.map(Into::<WasmAstNode>::into)
|
||||
})
|
||||
.map_or(Ok(None), |r| r.map(Some))?
|
||||
.map(|child| Box::new(child)),
|
||||
pre_blank: 0, // TODO: Should this be a no-op?
|
||||
},
|
||||
))
|
||||
}
|
||||
);
|
||||
33
src/wasm/horizontal_rule.rs
Normal file
33
src/wasm/horizontal_rule.rs
Normal file
@@ -0,0 +1,33 @@
|
||||
use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
|
||||
use super::ast_node::WasmAstNode;
|
||||
use super::macros::to_wasm;
|
||||
use super::to_wasm::ToWasm;
|
||||
use super::AdditionalProperties;
|
||||
use crate::compare::ElispFact;
|
||||
use crate::types::HorizontalRule;
|
||||
use crate::wasm::to_wasm::ToWasmStandardProperties;
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct WasmHorizontalRule {
|
||||
#[serde(flatten)]
|
||||
pub(crate) additional_properties: AdditionalProperties,
|
||||
}
|
||||
|
||||
to_wasm!(
|
||||
WasmHorizontalRule,
|
||||
HorizontalRule<'s>,
|
||||
original,
|
||||
wasm_context,
|
||||
{ WasmAstNode::HorizontalRule(original) },
|
||||
{ "TODO".into() },
|
||||
{
|
||||
Ok((
|
||||
Vec::new(),
|
||||
WasmHorizontalRule {
|
||||
additional_properties: AdditionalProperties::default(),
|
||||
},
|
||||
))
|
||||
}
|
||||
);
|
||||
33
src/wasm/inline_babel_call.rs
Normal file
33
src/wasm/inline_babel_call.rs
Normal file
@@ -0,0 +1,33 @@
|
||||
use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
|
||||
use super::ast_node::WasmAstNode;
|
||||
use super::macros::to_wasm;
|
||||
use super::to_wasm::ToWasm;
|
||||
use super::AdditionalProperties;
|
||||
use crate::compare::ElispFact;
|
||||
use crate::types::InlineBabelCall;
|
||||
use crate::wasm::to_wasm::ToWasmStandardProperties;
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct WasmInlineBabelCall {
|
||||
#[serde(flatten)]
|
||||
pub(crate) additional_properties: AdditionalProperties,
|
||||
}
|
||||
|
||||
to_wasm!(
|
||||
WasmInlineBabelCall,
|
||||
InlineBabelCall<'s>,
|
||||
original,
|
||||
wasm_context,
|
||||
{ WasmAstNode::InlineBabelCall(original) },
|
||||
{ "TODO".into() },
|
||||
{
|
||||
Ok((
|
||||
Vec::new(),
|
||||
WasmInlineBabelCall {
|
||||
additional_properties: AdditionalProperties::default(),
|
||||
},
|
||||
))
|
||||
}
|
||||
);
|
||||
33
src/wasm/inline_source_block.rs
Normal file
33
src/wasm/inline_source_block.rs
Normal file
@@ -0,0 +1,33 @@
|
||||
use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
|
||||
use super::ast_node::WasmAstNode;
|
||||
use super::macros::to_wasm;
|
||||
use super::to_wasm::ToWasm;
|
||||
use super::AdditionalProperties;
|
||||
use crate::compare::ElispFact;
|
||||
use crate::types::InlineSourceBlock;
|
||||
use crate::wasm::to_wasm::ToWasmStandardProperties;
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct WasmInlineSourceBlock {
|
||||
#[serde(flatten)]
|
||||
pub(crate) additional_properties: AdditionalProperties,
|
||||
}
|
||||
|
||||
to_wasm!(
|
||||
WasmInlineSourceBlock,
|
||||
InlineSourceBlock<'s>,
|
||||
original,
|
||||
wasm_context,
|
||||
{ WasmAstNode::InlineSourceBlock(original) },
|
||||
{ "TODO".into() },
|
||||
{
|
||||
Ok((
|
||||
Vec::new(),
|
||||
WasmInlineSourceBlock {
|
||||
additional_properties: AdditionalProperties::default(),
|
||||
},
|
||||
))
|
||||
}
|
||||
);
|
||||
43
src/wasm/italic.rs
Normal file
43
src/wasm/italic.rs
Normal file
@@ -0,0 +1,43 @@
|
||||
use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
|
||||
use super::ast_node::WasmAstNode;
|
||||
use super::macros::to_wasm;
|
||||
use super::to_wasm::ToWasm;
|
||||
use super::AdditionalProperties;
|
||||
use crate::compare::ElispFact;
|
||||
use crate::types::Italic;
|
||||
use crate::wasm::to_wasm::ToWasmStandardProperties;
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct WasmItalic {
|
||||
#[serde(flatten)]
|
||||
pub(crate) additional_properties: AdditionalProperties,
|
||||
}
|
||||
|
||||
to_wasm!(
|
||||
WasmItalic,
|
||||
Italic<'s>,
|
||||
original,
|
||||
wasm_context,
|
||||
{ WasmAstNode::Italic(original) },
|
||||
{ "TODO".into() },
|
||||
{
|
||||
let children = original
|
||||
.children
|
||||
.iter()
|
||||
.map(|child| {
|
||||
child
|
||||
.to_wasm(wasm_context.clone())
|
||||
.map(Into::<WasmAstNode>::into)
|
||||
})
|
||||
.collect::<Result<Vec<_>, _>>()?;
|
||||
|
||||
Ok((
|
||||
children,
|
||||
WasmItalic {
|
||||
additional_properties: AdditionalProperties::default(),
|
||||
},
|
||||
))
|
||||
}
|
||||
);
|
||||
42
src/wasm/keyword.rs
Normal file
42
src/wasm/keyword.rs
Normal file
@@ -0,0 +1,42 @@
|
||||
use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
|
||||
use super::ast_node::WasmAstNode;
|
||||
use super::macros::to_wasm;
|
||||
use super::to_wasm::ToWasm;
|
||||
use super::AdditionalProperties;
|
||||
use crate::compare::ElispFact;
|
||||
use crate::types::GetAffiliatedKeywords;
|
||||
use crate::types::Keyword;
|
||||
use crate::wasm::to_wasm::ToWasmStandardProperties;
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct WasmKeyword {
|
||||
#[serde(flatten)]
|
||||
pub(crate) additional_properties: AdditionalProperties,
|
||||
pub(crate) key: String,
|
||||
pub(crate) value: String,
|
||||
}
|
||||
|
||||
to_wasm!(
|
||||
WasmKeyword,
|
||||
Keyword<'s>,
|
||||
original,
|
||||
wasm_context,
|
||||
{ WasmAstNode::Keyword(original) },
|
||||
{ "keyword".into() },
|
||||
{
|
||||
let additional_properties = original
|
||||
.get_affiliated_keywords()
|
||||
.to_wasm(wasm_context.clone())?;
|
||||
|
||||
Ok((
|
||||
Vec::new(),
|
||||
WasmKeyword {
|
||||
additional_properties,
|
||||
key: original.key.to_uppercase(),
|
||||
value: original.value.to_owned(),
|
||||
},
|
||||
))
|
||||
}
|
||||
);
|
||||
33
src/wasm/latex_environment.rs
Normal file
33
src/wasm/latex_environment.rs
Normal file
@@ -0,0 +1,33 @@
|
||||
use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
|
||||
use super::ast_node::WasmAstNode;
|
||||
use super::macros::to_wasm;
|
||||
use super::to_wasm::ToWasm;
|
||||
use super::AdditionalProperties;
|
||||
use crate::compare::ElispFact;
|
||||
use crate::types::LatexEnvironment;
|
||||
use crate::wasm::to_wasm::ToWasmStandardProperties;
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct WasmLatexEnvironment {
|
||||
#[serde(flatten)]
|
||||
pub(crate) additional_properties: AdditionalProperties,
|
||||
}
|
||||
|
||||
to_wasm!(
|
||||
WasmLatexEnvironment,
|
||||
LatexEnvironment<'s>,
|
||||
original,
|
||||
wasm_context,
|
||||
{ WasmAstNode::LatexEnvironment(original) },
|
||||
{ "TODO".into() },
|
||||
{
|
||||
Ok((
|
||||
Vec::new(),
|
||||
WasmLatexEnvironment {
|
||||
additional_properties: AdditionalProperties::default(),
|
||||
},
|
||||
))
|
||||
}
|
||||
);
|
||||
33
src/wasm/latex_fragment.rs
Normal file
33
src/wasm/latex_fragment.rs
Normal file
@@ -0,0 +1,33 @@
|
||||
use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
|
||||
use super::ast_node::WasmAstNode;
|
||||
use super::macros::to_wasm;
|
||||
use super::to_wasm::ToWasm;
|
||||
use super::AdditionalProperties;
|
||||
use crate::compare::ElispFact;
|
||||
use crate::types::LatexFragment;
|
||||
use crate::wasm::to_wasm::ToWasmStandardProperties;
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct WasmLatexFragment {
|
||||
#[serde(flatten)]
|
||||
pub(crate) additional_properties: AdditionalProperties,
|
||||
}
|
||||
|
||||
to_wasm!(
|
||||
WasmLatexFragment,
|
||||
LatexFragment<'s>,
|
||||
original,
|
||||
wasm_context,
|
||||
{ WasmAstNode::LatexFragment(original) },
|
||||
{ "TODO".into() },
|
||||
{
|
||||
Ok((
|
||||
Vec::new(),
|
||||
WasmLatexFragment {
|
||||
additional_properties: AdditionalProperties::default(),
|
||||
},
|
||||
))
|
||||
}
|
||||
);
|
||||
33
src/wasm/line_break.rs
Normal file
33
src/wasm/line_break.rs
Normal file
@@ -0,0 +1,33 @@
|
||||
use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
|
||||
use super::ast_node::WasmAstNode;
|
||||
use super::macros::to_wasm;
|
||||
use super::to_wasm::ToWasm;
|
||||
use super::AdditionalProperties;
|
||||
use crate::compare::ElispFact;
|
||||
use crate::types::LineBreak;
|
||||
use crate::wasm::to_wasm::ToWasmStandardProperties;
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct WasmLineBreak {
|
||||
#[serde(flatten)]
|
||||
pub(crate) additional_properties: AdditionalProperties,
|
||||
}
|
||||
|
||||
to_wasm!(
|
||||
WasmLineBreak,
|
||||
LineBreak<'s>,
|
||||
original,
|
||||
wasm_context,
|
||||
{ WasmAstNode::LineBreak(original) },
|
||||
{ "TODO".into() },
|
||||
{
|
||||
Ok((
|
||||
Vec::new(),
|
||||
WasmLineBreak {
|
||||
additional_properties: AdditionalProperties::default(),
|
||||
},
|
||||
))
|
||||
}
|
||||
);
|
||||
60
src/wasm/macros.rs
Normal file
60
src/wasm/macros.rs
Normal file
@@ -0,0 +1,60 @@
|
||||
/// 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> ToWasm for $istruct {
|
||||
type Output = $ostruct;
|
||||
|
||||
fn to_wasm(
|
||||
&self,
|
||||
$wasm_context: crate::wasm::to_wasm::ToWasmContext<'_>,
|
||||
) -> Result<Self::Output, crate::error::CustomError> {
|
||||
let $original = self;
|
||||
$fnbody
|
||||
}
|
||||
}
|
||||
};
|
||||
($ostruct:ty, $istruct:ty, $original:ident, $wasm_context:ident, $toastnodebody:tt, $elispnamebody:tt, $fnbody:tt) => {
|
||||
impl<'s> ToWasm for $istruct {
|
||||
type Output = crate::wasm::ast_node::WasmAstNodeWrapper<$ostruct>;
|
||||
|
||||
fn to_wasm(
|
||||
&self,
|
||||
$wasm_context: crate::wasm::to_wasm::ToWasmContext<'_>,
|
||||
) -> Result<Self::Output, crate::error::CustomError> {
|
||||
let $original = self;
|
||||
let standard_properties =
|
||||
self.to_wasm_standard_properties($wasm_context.clone())?;
|
||||
|
||||
$fnbody.map(
|
||||
|(children, inner)| crate::wasm::ast_node::WasmAstNodeWrapper {
|
||||
ast_node: inner.get_elisp_name().into_owned(),
|
||||
standard_properties,
|
||||
children,
|
||||
properties: inner,
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
impl Into<WasmAstNode> for crate::wasm::ast_node::WasmAstNodeWrapper<$ostruct> {
|
||||
fn into(self) -> WasmAstNode {
|
||||
let $original = self;
|
||||
let ret = $toastnodebody;
|
||||
ret
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "wasm_test")]
|
||||
impl<'s> crate::compare::ElispFact<'s> for $ostruct {
|
||||
fn get_elisp_name<'b>(&'b self) -> std::borrow::Cow<'s, str> {
|
||||
let $original = self;
|
||||
let ret = $elispnamebody;
|
||||
ret
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
pub(crate) use to_wasm;
|
||||
131
src/wasm/mod.rs
Normal file
131
src/wasm/mod.rs
Normal file
@@ -0,0 +1,131 @@
|
||||
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 use ast_node::WasmAstNodeWrapper;
|
||||
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;
|
||||
33
src/wasm/node_property.rs
Normal file
33
src/wasm/node_property.rs
Normal file
@@ -0,0 +1,33 @@
|
||||
use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
|
||||
use super::ast_node::WasmAstNode;
|
||||
use super::macros::to_wasm;
|
||||
use super::to_wasm::ToWasm;
|
||||
use super::AdditionalProperties;
|
||||
use crate::compare::ElispFact;
|
||||
use crate::types::NodeProperty;
|
||||
use crate::wasm::to_wasm::ToWasmStandardProperties;
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct WasmNodeProperty {
|
||||
#[serde(flatten)]
|
||||
pub(crate) additional_properties: AdditionalProperties,
|
||||
}
|
||||
|
||||
to_wasm!(
|
||||
WasmNodeProperty,
|
||||
NodeProperty<'s>,
|
||||
original,
|
||||
wasm_context,
|
||||
{ WasmAstNode::NodeProperty(original) },
|
||||
{ "TODO".into() },
|
||||
{
|
||||
Ok((
|
||||
Vec::new(),
|
||||
WasmNodeProperty {
|
||||
additional_properties: AdditionalProperties::default(),
|
||||
},
|
||||
))
|
||||
}
|
||||
);
|
||||
33
src/wasm/org_macro.rs
Normal file
33
src/wasm/org_macro.rs
Normal file
@@ -0,0 +1,33 @@
|
||||
use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
|
||||
use super::ast_node::WasmAstNode;
|
||||
use super::macros::to_wasm;
|
||||
use super::to_wasm::ToWasm;
|
||||
use super::AdditionalProperties;
|
||||
use crate::compare::ElispFact;
|
||||
use crate::types::OrgMacro;
|
||||
use crate::wasm::to_wasm::ToWasmStandardProperties;
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct WasmOrgMacro {
|
||||
#[serde(flatten)]
|
||||
pub(crate) additional_properties: AdditionalProperties,
|
||||
}
|
||||
|
||||
to_wasm!(
|
||||
WasmOrgMacro,
|
||||
OrgMacro<'s>,
|
||||
original,
|
||||
wasm_context,
|
||||
{ WasmAstNode::OrgMacro(original) },
|
||||
{ "TODO".into() },
|
||||
{
|
||||
Ok((
|
||||
Vec::new(),
|
||||
WasmOrgMacro {
|
||||
additional_properties: AdditionalProperties::default(),
|
||||
},
|
||||
))
|
||||
}
|
||||
);
|
||||
48
src/wasm/paragraph.rs
Normal file
48
src/wasm/paragraph.rs
Normal file
@@ -0,0 +1,48 @@
|
||||
use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
|
||||
use super::ast_node::WasmAstNode;
|
||||
use super::macros::to_wasm;
|
||||
use super::to_wasm::ToWasm;
|
||||
use super::AdditionalProperties;
|
||||
use crate::compare::ElispFact;
|
||||
use crate::types::GetAffiliatedKeywords;
|
||||
use crate::types::Paragraph;
|
||||
use crate::wasm::to_wasm::ToWasmStandardProperties;
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct WasmParagraph {
|
||||
#[serde(flatten)]
|
||||
pub(crate) additional_properties: AdditionalProperties,
|
||||
}
|
||||
|
||||
to_wasm!(
|
||||
WasmParagraph,
|
||||
Paragraph<'s>,
|
||||
original,
|
||||
wasm_context,
|
||||
{ WasmAstNode::Paragraph(original) },
|
||||
{ "paragraph".into() },
|
||||
{
|
||||
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((
|
||||
children,
|
||||
WasmParagraph {
|
||||
additional_properties,
|
||||
},
|
||||
))
|
||||
}
|
||||
);
|
||||
15
src/wasm/parse_result.rs
Normal file
15
src/wasm/parse_result.rs
Normal file
@@ -0,0 +1,15 @@
|
||||
use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
|
||||
use super::ast_node::WasmAstNodeWrapper;
|
||||
use super::document::WasmDocument;
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
#[serde(tag = "status", content = "content")]
|
||||
pub enum ParseResult {
|
||||
#[serde(rename = "success")]
|
||||
Success(WasmAstNodeWrapper<WasmDocument>),
|
||||
|
||||
#[serde(rename = "error")]
|
||||
Error(String),
|
||||
}
|
||||
33
src/wasm/plain_link.rs
Normal file
33
src/wasm/plain_link.rs
Normal file
@@ -0,0 +1,33 @@
|
||||
use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
|
||||
use super::ast_node::WasmAstNode;
|
||||
use super::macros::to_wasm;
|
||||
use super::to_wasm::ToWasm;
|
||||
use super::AdditionalProperties;
|
||||
use crate::compare::ElispFact;
|
||||
use crate::types::PlainLink;
|
||||
use crate::wasm::to_wasm::ToWasmStandardProperties;
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct WasmPlainLink {
|
||||
#[serde(flatten)]
|
||||
pub(crate) additional_properties: AdditionalProperties,
|
||||
}
|
||||
|
||||
to_wasm!(
|
||||
WasmPlainLink,
|
||||
PlainLink<'s>,
|
||||
original,
|
||||
wasm_context,
|
||||
{ WasmAstNode::PlainLink(original) },
|
||||
{ "TODO".into() },
|
||||
{
|
||||
Ok((
|
||||
Vec::new(),
|
||||
WasmPlainLink {
|
||||
additional_properties: AdditionalProperties::default(),
|
||||
},
|
||||
))
|
||||
}
|
||||
);
|
||||
57
src/wasm/plain_list.rs
Normal file
57
src/wasm/plain_list.rs
Normal file
@@ -0,0 +1,57 @@
|
||||
use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
|
||||
use super::ast_node::WasmAstNode;
|
||||
use super::macros::to_wasm;
|
||||
use super::to_wasm::ToWasm;
|
||||
use super::AdditionalProperties;
|
||||
use crate::compare::ElispFact;
|
||||
use crate::types::GetAffiliatedKeywords;
|
||||
use crate::types::PlainList;
|
||||
use crate::types::PlainListType;
|
||||
use crate::wasm::to_wasm::ToWasmStandardProperties;
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct WasmPlainList {
|
||||
#[serde(flatten)]
|
||||
pub(crate) additional_properties: AdditionalProperties,
|
||||
#[serde(rename = "type")]
|
||||
pub(crate) list_type: String,
|
||||
}
|
||||
|
||||
to_wasm!(
|
||||
WasmPlainList,
|
||||
PlainList<'s>,
|
||||
original,
|
||||
wasm_context,
|
||||
{ WasmAstNode::PlainList(original) },
|
||||
{ "plain-list".into() },
|
||||
{
|
||||
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((
|
||||
children,
|
||||
WasmPlainList {
|
||||
additional_properties,
|
||||
list_type: match original.list_type {
|
||||
PlainListType::Unordered => "unordered",
|
||||
PlainListType::Ordered => "ordered",
|
||||
PlainListType::Descriptive => "descriptive",
|
||||
}
|
||||
.to_owned(),
|
||||
},
|
||||
))
|
||||
}
|
||||
);
|
||||
59
src/wasm/plain_list_item.rs
Normal file
59
src/wasm/plain_list_item.rs
Normal file
@@ -0,0 +1,59 @@
|
||||
use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
|
||||
use super::ast_node::WasmAstNode;
|
||||
use super::macros::to_wasm;
|
||||
use super::to_wasm::ToWasm;
|
||||
use crate::compare::ElispFact;
|
||||
use crate::types::CheckboxType;
|
||||
use crate::types::PlainListItem;
|
||||
use crate::types::PlainListItemCounter;
|
||||
use crate::wasm::to_wasm::ToWasmStandardProperties;
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct WasmPlainListItem {
|
||||
pub(crate) tag: Vec<WasmAstNode>,
|
||||
pub(crate) bullet: String,
|
||||
pub(crate) counter: Option<PlainListItemCounter>,
|
||||
pub(crate) checkbox: Option<String>,
|
||||
#[serde(rename = "pre-blank")]
|
||||
pub(crate) pre_blank: usize,
|
||||
}
|
||||
|
||||
to_wasm!(
|
||||
WasmPlainListItem,
|
||||
PlainListItem<'s>,
|
||||
original,
|
||||
wasm_context,
|
||||
{ WasmAstNode::PlainListItem(original) },
|
||||
{ "item".into() },
|
||||
{
|
||||
let children = original
|
||||
.children
|
||||
.iter()
|
||||
.map(|child| {
|
||||
child
|
||||
.to_wasm(wasm_context.clone())
|
||||
.map(Into::<WasmAstNode>::into)
|
||||
})
|
||||
.collect::<Result<Vec<_>, _>>()?;
|
||||
|
||||
Ok((
|
||||
children,
|
||||
WasmPlainListItem {
|
||||
tag: Vec::new(),
|
||||
bullet: original.bullet.to_owned(),
|
||||
counter: original.counter.clone(),
|
||||
checkbox: original.checkbox.as_ref().map(|(checkbox_type, _)| {
|
||||
match checkbox_type {
|
||||
CheckboxType::On => "on",
|
||||
CheckboxType::Trans => "trans",
|
||||
CheckboxType::Off => "off",
|
||||
}
|
||||
.to_owned()
|
||||
}),
|
||||
pre_blank: 0, // TODO: Should this be a no-op?
|
||||
},
|
||||
))
|
||||
}
|
||||
);
|
||||
22
src/wasm/plain_text.rs
Normal file
22
src/wasm/plain_text.rs
Normal file
@@ -0,0 +1,22 @@
|
||||
use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
|
||||
use super::ast_node::WasmAstNode;
|
||||
use super::macros::to_wasm;
|
||||
use super::to_wasm::ToWasm;
|
||||
use crate::compare::ElispFact;
|
||||
use crate::types::PlainText;
|
||||
use crate::wasm::to_wasm::ToWasmStandardProperties;
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct WasmPlainText {}
|
||||
|
||||
to_wasm!(
|
||||
WasmPlainText,
|
||||
PlainText<'s>,
|
||||
original,
|
||||
wasm_context,
|
||||
{ WasmAstNode::PlainText(original) },
|
||||
{ "plain-text".into() },
|
||||
{ Ok((Vec::new(), WasmPlainText {},)) }
|
||||
);
|
||||
62
src/wasm/planning.rs
Normal file
62
src/wasm/planning.rs
Normal file
@@ -0,0 +1,62 @@
|
||||
use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
|
||||
use super::ast_node::WasmAstNode;
|
||||
use super::macros::to_wasm;
|
||||
use super::to_wasm::ToWasm;
|
||||
use crate::compare::ElispFact;
|
||||
use crate::types::Planning;
|
||||
use crate::wasm::to_wasm::ToWasmStandardProperties;
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct WasmPlanning {
|
||||
pub(crate) scheduled: Option<Box<WasmAstNode>>,
|
||||
pub(crate) deadline: Option<Box<WasmAstNode>>,
|
||||
pub(crate) closed: Option<Box<WasmAstNode>>,
|
||||
}
|
||||
|
||||
to_wasm!(
|
||||
WasmPlanning,
|
||||
Planning<'s>,
|
||||
original,
|
||||
wasm_context,
|
||||
{ WasmAstNode::Planning(original) },
|
||||
{ "planning".into() },
|
||||
{
|
||||
Ok((
|
||||
Vec::new(),
|
||||
WasmPlanning {
|
||||
scheduled: original
|
||||
.scheduled
|
||||
.as_ref()
|
||||
.map(|child| {
|
||||
child
|
||||
.to_wasm(wasm_context.clone())
|
||||
.map(Into::<WasmAstNode>::into)
|
||||
})
|
||||
.map_or(Ok(None), |r| r.map(Some))?
|
||||
.map(|child| Box::new(child)),
|
||||
deadline: original
|
||||
.deadline
|
||||
.as_ref()
|
||||
.map(|child| {
|
||||
child
|
||||
.to_wasm(wasm_context.clone())
|
||||
.map(Into::<WasmAstNode>::into)
|
||||
})
|
||||
.map_or(Ok(None), |r| r.map(Some))?
|
||||
.map(|child| Box::new(child)),
|
||||
closed: original
|
||||
.closed
|
||||
.as_ref()
|
||||
.map(|child| {
|
||||
child
|
||||
.to_wasm(wasm_context.clone())
|
||||
.map(Into::<WasmAstNode>::into)
|
||||
})
|
||||
.map_or(Ok(None), |r| r.map(Some))?
|
||||
.map(|child| Box::new(child)),
|
||||
},
|
||||
))
|
||||
}
|
||||
);
|
||||
43
src/wasm/property_drawer.rs
Normal file
43
src/wasm/property_drawer.rs
Normal file
@@ -0,0 +1,43 @@
|
||||
use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
|
||||
use super::ast_node::WasmAstNode;
|
||||
use super::macros::to_wasm;
|
||||
use super::to_wasm::ToWasm;
|
||||
use super::AdditionalProperties;
|
||||
use crate::compare::ElispFact;
|
||||
use crate::types::PropertyDrawer;
|
||||
use crate::wasm::to_wasm::ToWasmStandardProperties;
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct WasmPropertyDrawer {
|
||||
#[serde(flatten)]
|
||||
pub(crate) additional_properties: AdditionalProperties,
|
||||
}
|
||||
|
||||
to_wasm!(
|
||||
WasmPropertyDrawer,
|
||||
PropertyDrawer<'s>,
|
||||
original,
|
||||
wasm_context,
|
||||
{ WasmAstNode::PropertyDrawer(original) },
|
||||
{ "TODO".into() },
|
||||
{
|
||||
let children = original
|
||||
.children
|
||||
.iter()
|
||||
.map(|child| {
|
||||
child
|
||||
.to_wasm(wasm_context.clone())
|
||||
.map(Into::<WasmAstNode>::into)
|
||||
})
|
||||
.collect::<Result<Vec<_>, _>>()?;
|
||||
|
||||
Ok((
|
||||
children,
|
||||
WasmPropertyDrawer {
|
||||
additional_properties: AdditionalProperties::default(),
|
||||
},
|
||||
))
|
||||
}
|
||||
);
|
||||
43
src/wasm/quote_block.rs
Normal file
43
src/wasm/quote_block.rs
Normal file
@@ -0,0 +1,43 @@
|
||||
use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
|
||||
use super::ast_node::WasmAstNode;
|
||||
use super::macros::to_wasm;
|
||||
use super::to_wasm::ToWasm;
|
||||
use super::AdditionalProperties;
|
||||
use crate::compare::ElispFact;
|
||||
use crate::types::QuoteBlock;
|
||||
use crate::wasm::to_wasm::ToWasmStandardProperties;
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct WasmQuoteBlock {
|
||||
#[serde(flatten)]
|
||||
pub(crate) additional_properties: AdditionalProperties,
|
||||
}
|
||||
|
||||
to_wasm!(
|
||||
WasmQuoteBlock,
|
||||
QuoteBlock<'s>,
|
||||
original,
|
||||
wasm_context,
|
||||
{ WasmAstNode::QuoteBlock(original) },
|
||||
{ "TODO".into() },
|
||||
{
|
||||
let children = original
|
||||
.children
|
||||
.iter()
|
||||
.map(|child| {
|
||||
child
|
||||
.to_wasm(wasm_context.clone())
|
||||
.map(Into::<WasmAstNode>::into)
|
||||
})
|
||||
.collect::<Result<Vec<_>, _>>()?;
|
||||
|
||||
Ok((
|
||||
children,
|
||||
WasmQuoteBlock {
|
||||
additional_properties: AdditionalProperties::default(),
|
||||
},
|
||||
))
|
||||
}
|
||||
);
|
||||
43
src/wasm/radio_link.rs
Normal file
43
src/wasm/radio_link.rs
Normal file
@@ -0,0 +1,43 @@
|
||||
use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
|
||||
use super::ast_node::WasmAstNode;
|
||||
use super::macros::to_wasm;
|
||||
use super::to_wasm::ToWasm;
|
||||
use super::AdditionalProperties;
|
||||
use crate::compare::ElispFact;
|
||||
use crate::types::RadioLink;
|
||||
use crate::wasm::to_wasm::ToWasmStandardProperties;
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct WasmRadioLink {
|
||||
#[serde(flatten)]
|
||||
pub(crate) additional_properties: AdditionalProperties,
|
||||
}
|
||||
|
||||
to_wasm!(
|
||||
WasmRadioLink,
|
||||
RadioLink<'s>,
|
||||
original,
|
||||
wasm_context,
|
||||
{ WasmAstNode::RadioLink(original) },
|
||||
{ "TODO".into() },
|
||||
{
|
||||
let children = original
|
||||
.children
|
||||
.iter()
|
||||
.map(|child| {
|
||||
child
|
||||
.to_wasm(wasm_context.clone())
|
||||
.map(Into::<WasmAstNode>::into)
|
||||
})
|
||||
.collect::<Result<Vec<_>, _>>()?;
|
||||
|
||||
Ok((
|
||||
children,
|
||||
WasmRadioLink {
|
||||
additional_properties: AdditionalProperties::default(),
|
||||
},
|
||||
))
|
||||
}
|
||||
);
|
||||
43
src/wasm/radio_target.rs
Normal file
43
src/wasm/radio_target.rs
Normal file
@@ -0,0 +1,43 @@
|
||||
use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
|
||||
use super::ast_node::WasmAstNode;
|
||||
use super::macros::to_wasm;
|
||||
use super::to_wasm::ToWasm;
|
||||
use super::AdditionalProperties;
|
||||
use crate::compare::ElispFact;
|
||||
use crate::types::RadioTarget;
|
||||
use crate::wasm::to_wasm::ToWasmStandardProperties;
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct WasmRadioTarget {
|
||||
#[serde(flatten)]
|
||||
pub(crate) additional_properties: AdditionalProperties,
|
||||
}
|
||||
|
||||
to_wasm!(
|
||||
WasmRadioTarget,
|
||||
RadioTarget<'s>,
|
||||
original,
|
||||
wasm_context,
|
||||
{ WasmAstNode::RadioTarget(original) },
|
||||
{ "TODO".into() },
|
||||
{
|
||||
let children = original
|
||||
.children
|
||||
.iter()
|
||||
.map(|child| {
|
||||
child
|
||||
.to_wasm(wasm_context.clone())
|
||||
.map(Into::<WasmAstNode>::into)
|
||||
})
|
||||
.collect::<Result<Vec<_>, _>>()?;
|
||||
|
||||
Ok((
|
||||
children,
|
||||
WasmRadioTarget {
|
||||
additional_properties: AdditionalProperties::default(),
|
||||
},
|
||||
))
|
||||
}
|
||||
);
|
||||
43
src/wasm/regular_link.rs
Normal file
43
src/wasm/regular_link.rs
Normal file
@@ -0,0 +1,43 @@
|
||||
use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
|
||||
use super::ast_node::WasmAstNode;
|
||||
use super::macros::to_wasm;
|
||||
use super::to_wasm::ToWasm;
|
||||
use super::AdditionalProperties;
|
||||
use crate::compare::ElispFact;
|
||||
use crate::types::RegularLink;
|
||||
use crate::wasm::to_wasm::ToWasmStandardProperties;
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct WasmRegularLink {
|
||||
#[serde(flatten)]
|
||||
pub(crate) additional_properties: AdditionalProperties,
|
||||
}
|
||||
|
||||
to_wasm!(
|
||||
WasmRegularLink,
|
||||
RegularLink<'s>,
|
||||
original,
|
||||
wasm_context,
|
||||
{ WasmAstNode::RegularLink(original) },
|
||||
{ "TODO".into() },
|
||||
{
|
||||
let children = original
|
||||
.children
|
||||
.iter()
|
||||
.map(|child| {
|
||||
child
|
||||
.to_wasm(wasm_context.clone())
|
||||
.map(Into::<WasmAstNode>::into)
|
||||
})
|
||||
.collect::<Result<Vec<_>, _>>()?;
|
||||
|
||||
Ok((
|
||||
children,
|
||||
WasmRegularLink {
|
||||
additional_properties: AdditionalProperties::default(),
|
||||
},
|
||||
))
|
||||
}
|
||||
);
|
||||
34
src/wasm/section.rs
Normal file
34
src/wasm/section.rs
Normal file
@@ -0,0 +1,34 @@
|
||||
use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
|
||||
use super::ast_node::WasmAstNode;
|
||||
use super::macros::to_wasm;
|
||||
use super::to_wasm::ToWasm;
|
||||
use crate::compare::ElispFact;
|
||||
use crate::types::Section;
|
||||
use crate::wasm::to_wasm::ToWasmStandardProperties;
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct WasmSection {}
|
||||
|
||||
to_wasm!(
|
||||
WasmSection,
|
||||
Section<'s>,
|
||||
original,
|
||||
wasm_context,
|
||||
{ WasmAstNode::Section(original) },
|
||||
{ "section".into() },
|
||||
{
|
||||
let children = original
|
||||
.children
|
||||
.iter()
|
||||
.map(|child| {
|
||||
child
|
||||
.to_wasm(wasm_context.clone())
|
||||
.map(Into::<WasmAstNode>::into)
|
||||
})
|
||||
.collect::<Result<Vec<_>, _>>()?;
|
||||
|
||||
Ok((children, WasmSection {}))
|
||||
}
|
||||
);
|
||||
43
src/wasm/special_block.rs
Normal file
43
src/wasm/special_block.rs
Normal file
@@ -0,0 +1,43 @@
|
||||
use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
|
||||
use super::ast_node::WasmAstNode;
|
||||
use super::macros::to_wasm;
|
||||
use super::to_wasm::ToWasm;
|
||||
use super::AdditionalProperties;
|
||||
use crate::compare::ElispFact;
|
||||
use crate::types::SpecialBlock;
|
||||
use crate::wasm::to_wasm::ToWasmStandardProperties;
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct WasmSpecialBlock {
|
||||
#[serde(flatten)]
|
||||
pub(crate) additional_properties: AdditionalProperties,
|
||||
}
|
||||
|
||||
to_wasm!(
|
||||
WasmSpecialBlock,
|
||||
SpecialBlock<'s>,
|
||||
original,
|
||||
wasm_context,
|
||||
{ WasmAstNode::SpecialBlock(original) },
|
||||
{ "TODO".into() },
|
||||
{
|
||||
let children = original
|
||||
.children
|
||||
.iter()
|
||||
.map(|child| {
|
||||
child
|
||||
.to_wasm(wasm_context.clone())
|
||||
.map(Into::<WasmAstNode>::into)
|
||||
})
|
||||
.collect::<Result<Vec<_>, _>>()?;
|
||||
|
||||
Ok((
|
||||
children,
|
||||
WasmSpecialBlock {
|
||||
additional_properties: AdditionalProperties::default(),
|
||||
},
|
||||
))
|
||||
}
|
||||
);
|
||||
33
src/wasm/src_block.rs
Normal file
33
src/wasm/src_block.rs
Normal file
@@ -0,0 +1,33 @@
|
||||
use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
|
||||
use super::ast_node::WasmAstNode;
|
||||
use super::macros::to_wasm;
|
||||
use super::to_wasm::ToWasm;
|
||||
use super::AdditionalProperties;
|
||||
use crate::compare::ElispFact;
|
||||
use crate::types::SrcBlock;
|
||||
use crate::wasm::to_wasm::ToWasmStandardProperties;
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct WasmSrcBlock {
|
||||
#[serde(flatten)]
|
||||
pub(crate) additional_properties: AdditionalProperties,
|
||||
}
|
||||
|
||||
to_wasm!(
|
||||
WasmSrcBlock,
|
||||
SrcBlock<'s>,
|
||||
original,
|
||||
wasm_context,
|
||||
{ WasmAstNode::SrcBlock(original) },
|
||||
{ "TODO".into() },
|
||||
{
|
||||
Ok((
|
||||
Vec::new(),
|
||||
WasmSrcBlock {
|
||||
additional_properties: AdditionalProperties::default(),
|
||||
},
|
||||
))
|
||||
}
|
||||
);
|
||||
74
src/wasm/standard_properties.rs
Normal file
74
src/wasm/standard_properties.rs
Normal file
@@ -0,0 +1,74 @@
|
||||
use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
|
||||
use super::to_wasm::ToWasmContext;
|
||||
use super::to_wasm::ToWasmStandardProperties;
|
||||
use crate::types::PostBlank;
|
||||
use crate::types::StandardProperties;
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub(crate) struct WasmStandardProperties {
|
||||
pub(crate) begin: usize,
|
||||
pub(crate) end: usize,
|
||||
#[serde(rename = "contents-begin")]
|
||||
pub(crate) contents_begin: Option<usize>,
|
||||
#[serde(rename = "contents-end")]
|
||||
pub(crate) contents_end: Option<usize>,
|
||||
#[serde(rename = "post-blank")]
|
||||
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
|
||||
}
|
||||
31
src/wasm/statistics_cookie.rs
Normal file
31
src/wasm/statistics_cookie.rs
Normal file
@@ -0,0 +1,31 @@
|
||||
use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
|
||||
use super::ast_node::WasmAstNode;
|
||||
use super::macros::to_wasm;
|
||||
use super::to_wasm::ToWasm;
|
||||
use crate::compare::ElispFact;
|
||||
use crate::types::StatisticsCookie;
|
||||
use crate::wasm::to_wasm::ToWasmStandardProperties;
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct WasmStatisticsCookie {
|
||||
pub(crate) value: String,
|
||||
}
|
||||
|
||||
to_wasm!(
|
||||
WasmStatisticsCookie,
|
||||
StatisticsCookie<'s>,
|
||||
original,
|
||||
wasm_context,
|
||||
{ WasmAstNode::StatisticsCookie(original) },
|
||||
{ "statistics-cookie".into() },
|
||||
{
|
||||
Ok((
|
||||
Vec::new(),
|
||||
WasmStatisticsCookie {
|
||||
value: original.value.to_owned(),
|
||||
},
|
||||
))
|
||||
}
|
||||
);
|
||||
43
src/wasm/strike_through.rs
Normal file
43
src/wasm/strike_through.rs
Normal file
@@ -0,0 +1,43 @@
|
||||
use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
|
||||
use super::ast_node::WasmAstNode;
|
||||
use super::macros::to_wasm;
|
||||
use super::to_wasm::ToWasm;
|
||||
use super::AdditionalProperties;
|
||||
use crate::compare::ElispFact;
|
||||
use crate::types::StrikeThrough;
|
||||
use crate::wasm::to_wasm::ToWasmStandardProperties;
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct WasmStrikeThrough {
|
||||
#[serde(flatten)]
|
||||
pub(crate) additional_properties: AdditionalProperties,
|
||||
}
|
||||
|
||||
to_wasm!(
|
||||
WasmStrikeThrough,
|
||||
StrikeThrough<'s>,
|
||||
original,
|
||||
wasm_context,
|
||||
{ WasmAstNode::StrikeThrough(original) },
|
||||
{ "TODO".into() },
|
||||
{
|
||||
let children = original
|
||||
.children
|
||||
.iter()
|
||||
.map(|child| {
|
||||
child
|
||||
.to_wasm(wasm_context.clone())
|
||||
.map(Into::<WasmAstNode>::into)
|
||||
})
|
||||
.collect::<Result<Vec<_>, _>>()?;
|
||||
|
||||
Ok((
|
||||
children,
|
||||
WasmStrikeThrough {
|
||||
additional_properties: AdditionalProperties::default(),
|
||||
},
|
||||
))
|
||||
}
|
||||
);
|
||||
43
src/wasm/subscript.rs
Normal file
43
src/wasm/subscript.rs
Normal file
@@ -0,0 +1,43 @@
|
||||
use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
|
||||
use super::ast_node::WasmAstNode;
|
||||
use super::macros::to_wasm;
|
||||
use super::to_wasm::ToWasm;
|
||||
use super::AdditionalProperties;
|
||||
use crate::compare::ElispFact;
|
||||
use crate::types::Subscript;
|
||||
use crate::wasm::to_wasm::ToWasmStandardProperties;
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct WasmSubscript {
|
||||
#[serde(flatten)]
|
||||
pub(crate) additional_properties: AdditionalProperties,
|
||||
}
|
||||
|
||||
to_wasm!(
|
||||
WasmSubscript,
|
||||
Subscript<'s>,
|
||||
original,
|
||||
wasm_context,
|
||||
{ WasmAstNode::Subscript(original) },
|
||||
{ "TODO".into() },
|
||||
{
|
||||
let children = original
|
||||
.children
|
||||
.iter()
|
||||
.map(|child| {
|
||||
child
|
||||
.to_wasm(wasm_context.clone())
|
||||
.map(Into::<WasmAstNode>::into)
|
||||
})
|
||||
.collect::<Result<Vec<_>, _>>()?;
|
||||
|
||||
Ok((
|
||||
children,
|
||||
WasmSubscript {
|
||||
additional_properties: AdditionalProperties::default(),
|
||||
},
|
||||
))
|
||||
}
|
||||
);
|
||||
43
src/wasm/superscript.rs
Normal file
43
src/wasm/superscript.rs
Normal file
@@ -0,0 +1,43 @@
|
||||
use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
|
||||
use super::ast_node::WasmAstNode;
|
||||
use super::macros::to_wasm;
|
||||
use super::to_wasm::ToWasm;
|
||||
use super::AdditionalProperties;
|
||||
use crate::compare::ElispFact;
|
||||
use crate::types::Superscript;
|
||||
use crate::wasm::to_wasm::ToWasmStandardProperties;
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct WasmSuperscript {
|
||||
#[serde(flatten)]
|
||||
pub(crate) additional_properties: AdditionalProperties,
|
||||
}
|
||||
|
||||
to_wasm!(
|
||||
WasmSuperscript,
|
||||
Superscript<'s>,
|
||||
original,
|
||||
wasm_context,
|
||||
{ WasmAstNode::Superscript(original) },
|
||||
{ "TODO".into() },
|
||||
{
|
||||
let children = original
|
||||
.children
|
||||
.iter()
|
||||
.map(|child| {
|
||||
child
|
||||
.to_wasm(wasm_context.clone())
|
||||
.map(Into::<WasmAstNode>::into)
|
||||
})
|
||||
.collect::<Result<Vec<_>, _>>()?;
|
||||
|
||||
Ok((
|
||||
children,
|
||||
WasmSuperscript {
|
||||
additional_properties: AdditionalProperties::default(),
|
||||
},
|
||||
))
|
||||
}
|
||||
);
|
||||
43
src/wasm/table.rs
Normal file
43
src/wasm/table.rs
Normal file
@@ -0,0 +1,43 @@
|
||||
use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
|
||||
use super::ast_node::WasmAstNode;
|
||||
use super::macros::to_wasm;
|
||||
use super::to_wasm::ToWasm;
|
||||
use super::AdditionalProperties;
|
||||
use crate::compare::ElispFact;
|
||||
use crate::types::Table;
|
||||
use crate::wasm::to_wasm::ToWasmStandardProperties;
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct WasmTable {
|
||||
#[serde(flatten)]
|
||||
pub(crate) additional_properties: AdditionalProperties,
|
||||
}
|
||||
|
||||
to_wasm!(
|
||||
WasmTable,
|
||||
Table<'s>,
|
||||
original,
|
||||
wasm_context,
|
||||
{ WasmAstNode::Table(original) },
|
||||
{ "TODO".into() },
|
||||
{
|
||||
let children = original
|
||||
.children
|
||||
.iter()
|
||||
.map(|child| {
|
||||
child
|
||||
.to_wasm(wasm_context.clone())
|
||||
.map(Into::<WasmAstNode>::into)
|
||||
})
|
||||
.collect::<Result<Vec<_>, _>>()?;
|
||||
|
||||
Ok((
|
||||
children,
|
||||
WasmTable {
|
||||
additional_properties: AdditionalProperties::default(),
|
||||
},
|
||||
))
|
||||
}
|
||||
);
|
||||
43
src/wasm/table_cell.rs
Normal file
43
src/wasm/table_cell.rs
Normal file
@@ -0,0 +1,43 @@
|
||||
use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
|
||||
use super::ast_node::WasmAstNode;
|
||||
use super::macros::to_wasm;
|
||||
use super::to_wasm::ToWasm;
|
||||
use super::AdditionalProperties;
|
||||
use crate::compare::ElispFact;
|
||||
use crate::types::TableCell;
|
||||
use crate::wasm::to_wasm::ToWasmStandardProperties;
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct WasmTableCell {
|
||||
#[serde(flatten)]
|
||||
pub(crate) additional_properties: AdditionalProperties,
|
||||
}
|
||||
|
||||
to_wasm!(
|
||||
WasmTableCell,
|
||||
TableCell<'s>,
|
||||
original,
|
||||
wasm_context,
|
||||
{ WasmAstNode::TableCell(original) },
|
||||
{ "TODO".into() },
|
||||
{
|
||||
let children = original
|
||||
.children
|
||||
.iter()
|
||||
.map(|child| {
|
||||
child
|
||||
.to_wasm(wasm_context.clone())
|
||||
.map(Into::<WasmAstNode>::into)
|
||||
})
|
||||
.collect::<Result<Vec<_>, _>>()?;
|
||||
|
||||
Ok((
|
||||
children,
|
||||
WasmTableCell {
|
||||
additional_properties: AdditionalProperties::default(),
|
||||
},
|
||||
))
|
||||
}
|
||||
);
|
||||
43
src/wasm/table_row.rs
Normal file
43
src/wasm/table_row.rs
Normal file
@@ -0,0 +1,43 @@
|
||||
use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
|
||||
use super::ast_node::WasmAstNode;
|
||||
use super::macros::to_wasm;
|
||||
use super::to_wasm::ToWasm;
|
||||
use super::AdditionalProperties;
|
||||
use crate::compare::ElispFact;
|
||||
use crate::types::TableRow;
|
||||
use crate::wasm::to_wasm::ToWasmStandardProperties;
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct WasmTableRow {
|
||||
#[serde(flatten)]
|
||||
pub(crate) additional_properties: AdditionalProperties,
|
||||
}
|
||||
|
||||
to_wasm!(
|
||||
WasmTableRow,
|
||||
TableRow<'s>,
|
||||
original,
|
||||
wasm_context,
|
||||
{ WasmAstNode::TableRow(original) },
|
||||
{ "TODO".into() },
|
||||
{
|
||||
let children = original
|
||||
.children
|
||||
.iter()
|
||||
.map(|child| {
|
||||
child
|
||||
.to_wasm(wasm_context.clone())
|
||||
.map(Into::<WasmAstNode>::into)
|
||||
})
|
||||
.collect::<Result<Vec<_>, _>>()?;
|
||||
|
||||
Ok((
|
||||
children,
|
||||
WasmTableRow {
|
||||
additional_properties: AdditionalProperties::default(),
|
||||
},
|
||||
))
|
||||
}
|
||||
);
|
||||
33
src/wasm/target.rs
Normal file
33
src/wasm/target.rs
Normal file
@@ -0,0 +1,33 @@
|
||||
use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
|
||||
use super::ast_node::WasmAstNode;
|
||||
use super::macros::to_wasm;
|
||||
use super::to_wasm::ToWasm;
|
||||
use super::AdditionalProperties;
|
||||
use crate::compare::ElispFact;
|
||||
use crate::types::Target;
|
||||
use crate::wasm::to_wasm::ToWasmStandardProperties;
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct WasmTarget {
|
||||
#[serde(flatten)]
|
||||
pub(crate) additional_properties: AdditionalProperties,
|
||||
}
|
||||
|
||||
to_wasm!(
|
||||
WasmTarget,
|
||||
Target<'s>,
|
||||
original,
|
||||
wasm_context,
|
||||
{ WasmAstNode::Target(original) },
|
||||
{ "TODO".into() },
|
||||
{
|
||||
Ok((
|
||||
Vec::new(),
|
||||
WasmTarget {
|
||||
additional_properties: AdditionalProperties::default(),
|
||||
},
|
||||
))
|
||||
}
|
||||
);
|
||||
146
src/wasm/timestamp.rs
Normal file
146
src/wasm/timestamp.rs
Normal file
@@ -0,0 +1,146 @@
|
||||
use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
|
||||
use super::ast_node::WasmAstNode;
|
||||
use super::macros::to_wasm;
|
||||
use super::to_wasm::ToWasm;
|
||||
use crate::compare::ElispFact;
|
||||
use crate::types::DayOfMonthInner;
|
||||
use crate::types::HourInner;
|
||||
use crate::types::MinuteInner;
|
||||
use crate::types::MonthInner;
|
||||
use crate::types::RepeaterType;
|
||||
use crate::types::RepeaterWarningDelayValueType;
|
||||
use crate::types::TimeUnit;
|
||||
use crate::types::Timestamp;
|
||||
use crate::types::TimestampRangeType;
|
||||
use crate::types::TimestampType;
|
||||
use crate::types::WarningDelayType;
|
||||
use crate::types::YearInner;
|
||||
use crate::wasm::to_wasm::ToWasmStandardProperties;
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct WasmTimestamp {
|
||||
#[serde(rename = "type")]
|
||||
pub(crate) timestamp_type: String,
|
||||
#[serde(rename = "range-type")]
|
||||
pub(crate) range_type: Option<String>,
|
||||
#[serde(rename = "raw-value")]
|
||||
pub(crate) raw_value: String,
|
||||
#[serde(rename = "year-start")]
|
||||
pub(crate) year_start: Option<YearInner>,
|
||||
#[serde(rename = "month-start")]
|
||||
pub(crate) month_start: Option<MonthInner>,
|
||||
#[serde(rename = "day-start")]
|
||||
pub(crate) day_of_month_start: Option<DayOfMonthInner>,
|
||||
#[serde(rename = "hour-start")]
|
||||
pub(crate) hour_start: Option<HourInner>,
|
||||
#[serde(rename = "minute-start")]
|
||||
pub(crate) minute_start: Option<MinuteInner>,
|
||||
#[serde(rename = "year-end")]
|
||||
pub(crate) year_end: Option<YearInner>,
|
||||
#[serde(rename = "month-end")]
|
||||
pub(crate) month_end: Option<MonthInner>,
|
||||
#[serde(rename = "day-end")]
|
||||
pub(crate) day_of_month_end: Option<DayOfMonthInner>,
|
||||
#[serde(rename = "hour-end")]
|
||||
pub(crate) hour_end: Option<HourInner>,
|
||||
#[serde(rename = "minute-end")]
|
||||
pub(crate) minute_end: Option<MinuteInner>,
|
||||
#[serde(rename = "repeater-type")]
|
||||
pub(crate) repeater_type: Option<String>,
|
||||
#[serde(rename = "repeater-unit")]
|
||||
pub(crate) repeater_unit: Option<String>,
|
||||
#[serde(rename = "repeater-value")]
|
||||
pub(crate) repeater_value: Option<RepeaterWarningDelayValueType>,
|
||||
#[serde(rename = "warning-type")]
|
||||
pub(crate) warning_type: Option<String>,
|
||||
#[serde(rename = "warning-unit")]
|
||||
pub(crate) warning_unit: Option<String>,
|
||||
#[serde(rename = "warning-value")]
|
||||
pub(crate) warning_value: Option<RepeaterWarningDelayValueType>,
|
||||
}
|
||||
|
||||
to_wasm!(
|
||||
WasmTimestamp,
|
||||
Timestamp<'s>,
|
||||
original,
|
||||
wasm_context,
|
||||
{ WasmAstNode::Timestamp(original) },
|
||||
{ "timestamp".into() },
|
||||
{
|
||||
Ok((
|
||||
Vec::new(),
|
||||
WasmTimestamp {
|
||||
timestamp_type: match original.timestamp_type {
|
||||
TimestampType::Diary => "diary",
|
||||
TimestampType::Active => "active",
|
||||
TimestampType::Inactive => "inactive",
|
||||
TimestampType::ActiveRange => "active-range",
|
||||
TimestampType::InactiveRange => "inactive-range",
|
||||
}
|
||||
.to_owned(),
|
||||
range_type: match original.range_type {
|
||||
TimestampRangeType::DateRange => Some("daterange".to_owned()),
|
||||
TimestampRangeType::TimeRange => Some("timerange".to_owned()),
|
||||
TimestampRangeType::None => None,
|
||||
},
|
||||
raw_value: original.get_raw_value().to_owned(),
|
||||
year_start: original.start.as_ref().map(|date| date.get_year().0),
|
||||
month_start: original.start.as_ref().map(|date| date.get_month().0),
|
||||
day_of_month_start: original
|
||||
.start
|
||||
.as_ref()
|
||||
.map(|date| date.get_day_of_month().0),
|
||||
hour_start: original.start_time.as_ref().map(|time| time.get_hour().0),
|
||||
minute_start: original.start_time.as_ref().map(|time| time.get_minute().0),
|
||||
year_end: original.end.as_ref().map(|date| date.get_year().0),
|
||||
month_end: original.end.as_ref().map(|date| date.get_month().0),
|
||||
day_of_month_end: original.end.as_ref().map(|date| date.get_day_of_month().0),
|
||||
hour_end: original.end_time.as_ref().map(|time| time.get_hour().0),
|
||||
minute_end: original.end_time.as_ref().map(|time| time.get_minute().0),
|
||||
repeater_type: original
|
||||
.repeater
|
||||
.as_ref()
|
||||
.map(|repeater| match repeater.repeater_type {
|
||||
RepeaterType::Cumulative => "cumulate",
|
||||
RepeaterType::CatchUp => "catch-up",
|
||||
RepeaterType::Restart => "restart",
|
||||
})
|
||||
.map(|text| text.to_owned()),
|
||||
repeater_unit: original
|
||||
.repeater
|
||||
.as_ref()
|
||||
.map(|repeater| match repeater.unit {
|
||||
TimeUnit::Hour => "hour",
|
||||
TimeUnit::Day => "day",
|
||||
TimeUnit::Week => "week",
|
||||
TimeUnit::Month => "month",
|
||||
TimeUnit::Year => "year",
|
||||
})
|
||||
.map(|text| text.to_owned()),
|
||||
repeater_value: original.repeater.as_ref().map(|repeater| repeater.value),
|
||||
warning_type: original
|
||||
.warning_delay
|
||||
.as_ref()
|
||||
.map(|warning| match warning.warning_delay_type {
|
||||
WarningDelayType::All => "all",
|
||||
WarningDelayType::First => "first",
|
||||
})
|
||||
.map(|text| text.to_owned()),
|
||||
warning_unit: original
|
||||
.warning_delay
|
||||
.as_ref()
|
||||
.map(|warning| match warning.unit {
|
||||
TimeUnit::Hour => "hour",
|
||||
TimeUnit::Day => "day",
|
||||
TimeUnit::Week => "week",
|
||||
TimeUnit::Month => "month",
|
||||
TimeUnit::Year => "year",
|
||||
})
|
||||
.map(|text| text.to_owned()),
|
||||
warning_value: original.warning_delay.as_ref().map(|warning| warning.value),
|
||||
},
|
||||
))
|
||||
}
|
||||
);
|
||||
124
src/wasm/to_wasm.rs
Normal file
124
src/wasm/to_wasm.rs
Normal file
@@ -0,0 +1,124 @@
|
||||
use super::macros::to_wasm;
|
||||
use super::WasmAstNode;
|
||||
use crate::error::CustomError;
|
||||
use crate::types::DocumentElement;
|
||||
use crate::types::Element;
|
||||
use crate::types::Object;
|
||||
|
||||
pub trait ToWasm {
|
||||
type Output;
|
||||
|
||||
fn to_wasm(&self, full_document: ToWasmContext<'_>) -> Result<Self::Output, CustomError>;
|
||||
}
|
||||
|
||||
pub(crate) trait ToWasmStandardProperties {
|
||||
type Output;
|
||||
|
||||
fn to_wasm_standard_properties(
|
||||
&self,
|
||||
wasm_context: ToWasmContext<'_>,
|
||||
) -> Result<Self::Output, CustomError>;
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub 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, DocumentElement<'s>, original, wasm_context, {
|
||||
match original {
|
||||
DocumentElement::Heading(inner) => {
|
||||
inner.to_wasm(wasm_context).map(Into::<WasmAstNode>::into)
|
||||
}
|
||||
DocumentElement::Section(inner) => {
|
||||
inner.to_wasm(wasm_context).map(Into::<WasmAstNode>::into)
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
to_wasm!(WasmAstNode, Element<'s>, original, wasm_context, {
|
||||
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, Object<'s>, original, wasm_context, {
|
||||
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),
|
||||
}
|
||||
});
|
||||
43
src/wasm/underline.rs
Normal file
43
src/wasm/underline.rs
Normal file
@@ -0,0 +1,43 @@
|
||||
use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
|
||||
use super::ast_node::WasmAstNode;
|
||||
use super::macros::to_wasm;
|
||||
use super::to_wasm::ToWasm;
|
||||
use super::AdditionalProperties;
|
||||
use crate::compare::ElispFact;
|
||||
use crate::types::Underline;
|
||||
use crate::wasm::to_wasm::ToWasmStandardProperties;
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct WasmUnderline {
|
||||
#[serde(flatten)]
|
||||
pub(crate) additional_properties: AdditionalProperties,
|
||||
}
|
||||
|
||||
to_wasm!(
|
||||
WasmUnderline,
|
||||
Underline<'s>,
|
||||
original,
|
||||
wasm_context,
|
||||
{ WasmAstNode::Underline(original) },
|
||||
{ "TODO".into() },
|
||||
{
|
||||
let children = original
|
||||
.children
|
||||
.iter()
|
||||
.map(|child| {
|
||||
child
|
||||
.to_wasm(wasm_context.clone())
|
||||
.map(Into::<WasmAstNode>::into)
|
||||
})
|
||||
.collect::<Result<Vec<_>, _>>()?;
|
||||
|
||||
Ok((
|
||||
children,
|
||||
WasmUnderline {
|
||||
additional_properties: AdditionalProperties::default(),
|
||||
},
|
||||
))
|
||||
}
|
||||
);
|
||||
33
src/wasm/verbatim.rs
Normal file
33
src/wasm/verbatim.rs
Normal file
@@ -0,0 +1,33 @@
|
||||
use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
|
||||
use super::ast_node::WasmAstNode;
|
||||
use super::macros::to_wasm;
|
||||
use super::to_wasm::ToWasm;
|
||||
use super::AdditionalProperties;
|
||||
use crate::compare::ElispFact;
|
||||
use crate::types::Verbatim;
|
||||
use crate::wasm::to_wasm::ToWasmStandardProperties;
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct WasmVerbatim {
|
||||
#[serde(flatten)]
|
||||
pub(crate) additional_properties: AdditionalProperties,
|
||||
}
|
||||
|
||||
to_wasm!(
|
||||
WasmVerbatim,
|
||||
Verbatim<'s>,
|
||||
original,
|
||||
wasm_context,
|
||||
{ WasmAstNode::Verbatim(original) },
|
||||
{ "TODO".into() },
|
||||
{
|
||||
Ok((
|
||||
Vec::new(),
|
||||
WasmVerbatim {
|
||||
additional_properties: AdditionalProperties::default(),
|
||||
},
|
||||
))
|
||||
}
|
||||
);
|
||||
43
src/wasm/verse_block.rs
Normal file
43
src/wasm/verse_block.rs
Normal file
@@ -0,0 +1,43 @@
|
||||
use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
|
||||
use super::ast_node::WasmAstNode;
|
||||
use super::macros::to_wasm;
|
||||
use super::to_wasm::ToWasm;
|
||||
use super::AdditionalProperties;
|
||||
use crate::compare::ElispFact;
|
||||
use crate::types::VerseBlock;
|
||||
use crate::wasm::to_wasm::ToWasmStandardProperties;
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct WasmVerseBlock {
|
||||
#[serde(flatten)]
|
||||
pub(crate) additional_properties: AdditionalProperties,
|
||||
}
|
||||
|
||||
to_wasm!(
|
||||
WasmVerseBlock,
|
||||
VerseBlock<'s>,
|
||||
original,
|
||||
wasm_context,
|
||||
{ WasmAstNode::VerseBlock(original) },
|
||||
{ "TODO".into() },
|
||||
{
|
||||
let children = original
|
||||
.children
|
||||
.iter()
|
||||
.map(|child| {
|
||||
child
|
||||
.to_wasm(wasm_context.clone())
|
||||
.map(Into::<WasmAstNode>::into)
|
||||
})
|
||||
.collect::<Result<Vec<_>, _>>()?;
|
||||
|
||||
Ok((
|
||||
children,
|
||||
WasmVerseBlock {
|
||||
additional_properties: AdditionalProperties::default(),
|
||||
},
|
||||
))
|
||||
}
|
||||
);
|
||||
733
src/wasm_test/compare.rs
Normal file
733
src/wasm_test/compare.rs
Normal file
@@ -0,0 +1,733 @@
|
||||
use std::borrow::Cow;
|
||||
use std::collections::HashMap;
|
||||
|
||||
use super::diff::WasmDiffResult;
|
||||
use super::diff::WasmDiffStatus;
|
||||
use crate::compare::maybe_token_to_usize;
|
||||
use crate::compare::unquote;
|
||||
use crate::compare::EmacsStandardProperties;
|
||||
use crate::compare::TextWithProperties;
|
||||
use crate::compare::Token;
|
||||
use crate::wasm::WasmAstNodeWrapper;
|
||||
use crate::wasm::WasmDocument;
|
||||
|
||||
pub fn wasm_compare_document<'e, 's, 'w>(
|
||||
source: &'s str,
|
||||
emacs: &'e Token<'s>,
|
||||
wasm: &'w WasmAstNodeWrapper<WasmDocument>,
|
||||
) -> Result<WasmDiffResult<'s>, Box<dyn std::error::Error>> {
|
||||
let wasm_json = serde_json::to_string(&wasm)?;
|
||||
let wasm_json_parsed = serde_json::from_str(&wasm_json)?;
|
||||
compare_json_value(source, emacs, &wasm_json_parsed)
|
||||
}
|
||||
|
||||
fn compare_json_value<'b, 's>(
|
||||
source: &'s str,
|
||||
emacs: &'b Token<'s>,
|
||||
wasm: &serde_json::Value,
|
||||
) -> Result<WasmDiffResult<'s>, Box<dyn std::error::Error>> {
|
||||
// println!("XXXXXXXXXXXXXX compare_json_value XXXXXXXXXXXXXX");
|
||||
// println!("{:?}", emacs);
|
||||
// println!("{:?}", wasm);
|
||||
// println!("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX");
|
||||
match (wasm, emacs) {
|
||||
(serde_json::Value::Object(wasm), Token::List(el)) if wasm.contains_key("ast-node") => {
|
||||
// We hit a regular ast node.
|
||||
compare_ast_node(source, el, wasm)
|
||||
}
|
||||
(serde_json::Value::String(w), Token::Atom(e))
|
||||
if e.starts_with('"') && e.ends_with('"') =>
|
||||
{
|
||||
// We hit a string compared against a quoted string from elisp (as opposed to an unquoted literal).
|
||||
compare_quoted_string(source, e, w)
|
||||
}
|
||||
(serde_json::Value::Array(w), Token::List(e)) => {
|
||||
// TODO: This is creating children with no names.
|
||||
wasm_compare_list(source, e.iter(), w.iter())
|
||||
}
|
||||
(serde_json::Value::Object(wasm), Token::List(e))
|
||||
if wasm.contains_key("optval") && wasm.contains_key("val") =>
|
||||
{
|
||||
compare_optional_pair(source, e, wasm)
|
||||
}
|
||||
(serde_json::Value::Object(wasm), Token::List(el)) if wasm.contains_key("object-tree") => {
|
||||
// We hit an object tree additional property.
|
||||
compare_object_tree(source, el, wasm)
|
||||
}
|
||||
(serde_json::Value::Object(w), Token::TextWithProperties(e)) if is_plain_text(w) => {
|
||||
compare_plain_text(source, e, w)
|
||||
}
|
||||
(serde_json::Value::Null, Token::Atom("nil")) => Ok(WasmDiffResult::default()),
|
||||
(serde_json::Value::Bool(false), Token::Atom("nil")) => Ok(WasmDiffResult::default()),
|
||||
(serde_json::Value::Bool(true), Token::Atom(e)) if (*e) != "nil" => {
|
||||
Ok(WasmDiffResult::default())
|
||||
}
|
||||
(serde_json::Value::Bool(w), Token::Atom(e)) => {
|
||||
let mut result = WasmDiffResult::default();
|
||||
result.status.push(WasmDiffStatus::Bad(
|
||||
format!(
|
||||
"Value mismatch. Emacs=({emacs:?}) Wasm=({wasm:?}).",
|
||||
emacs = e,
|
||||
wasm = w,
|
||||
)
|
||||
.into(),
|
||||
));
|
||||
Ok(result)
|
||||
}
|
||||
(serde_json::Value::Number(w), Token::Atom(e)) if w.to_string().as_str() == (*e) => {
|
||||
Ok(WasmDiffResult::default())
|
||||
}
|
||||
(serde_json::Value::Array(w), Token::Atom("nil")) if w.is_empty() => {
|
||||
Ok(WasmDiffResult::default())
|
||||
}
|
||||
(serde_json::Value::String(w), Token::Atom(e)) if w.as_str() == *e => {
|
||||
Ok(WasmDiffResult::default())
|
||||
}
|
||||
(serde_json::Value::Null, Token::Atom(_)) => todo!(),
|
||||
(serde_json::Value::Null, Token::List(_)) => todo!(),
|
||||
(serde_json::Value::Null, Token::TextWithProperties(_)) => todo!(),
|
||||
(serde_json::Value::Null, Token::Vector(_)) => todo!(),
|
||||
// (serde_json::Value::Bool(_), Token::Atom(_)) => todo!(),
|
||||
(serde_json::Value::Bool(_), Token::List(_)) => todo!(),
|
||||
(serde_json::Value::Bool(_), Token::TextWithProperties(_)) => todo!(),
|
||||
(serde_json::Value::Bool(_), Token::Vector(_)) => todo!(),
|
||||
(serde_json::Value::Number(_), Token::Atom(_)) => todo!(),
|
||||
(serde_json::Value::Number(_), Token::List(_)) => todo!(),
|
||||
(serde_json::Value::Number(_), Token::TextWithProperties(_)) => todo!(),
|
||||
(serde_json::Value::Number(_), Token::Vector(_)) => todo!(),
|
||||
// (serde_json::Value::String(_), Token::Atom(_)) => todo!(),
|
||||
(serde_json::Value::String(w), Token::Atom(e)) => {
|
||||
let mut result = WasmDiffResult::default();
|
||||
result.status.push(WasmDiffStatus::Bad(
|
||||
format!(
|
||||
"Value mismatch. Emacs=({emacs:?}) Wasm=({wasm:?}).",
|
||||
emacs = e,
|
||||
wasm = w,
|
||||
)
|
||||
.into(),
|
||||
));
|
||||
Ok(result)
|
||||
}
|
||||
(serde_json::Value::String(_), Token::List(_)) => todo!(),
|
||||
(serde_json::Value::String(_), Token::TextWithProperties(_)) => todo!(),
|
||||
(serde_json::Value::String(_), Token::Vector(_)) => todo!(),
|
||||
(serde_json::Value::Array(_), Token::Atom(_)) => todo!(),
|
||||
// (serde_json::Value::Array(_), Token::List(_)) => todo!(),
|
||||
(serde_json::Value::Array(_), Token::TextWithProperties(_)) => todo!(),
|
||||
(serde_json::Value::Array(_), Token::Vector(_)) => todo!(),
|
||||
(serde_json::Value::Object(_), Token::Atom(_)) => todo!(),
|
||||
(serde_json::Value::Object(_), Token::List(_)) => todo!(),
|
||||
(serde_json::Value::Object(_), Token::TextWithProperties(_)) => todo!(),
|
||||
(serde_json::Value::Object(_), Token::Vector(_)) => todo!(),
|
||||
}
|
||||
}
|
||||
|
||||
fn compare_optional_json_value<'b, 's>(
|
||||
source: &'s str,
|
||||
emacs: Option<&'b Token<'s>>,
|
||||
wasm: Option<&serde_json::Value>,
|
||||
) -> Result<WasmDiffResult<'s>, Box<dyn std::error::Error>> {
|
||||
match (emacs, wasm) {
|
||||
(None, None) | (None, Some(serde_json::Value::Null)) | (Some(Token::Atom("nil")), None) => {
|
||||
Ok(WasmDiffResult::default())
|
||||
}
|
||||
(Some(e), Some(w)) => compare_json_value(source, e, w),
|
||||
_ => Ok(WasmDiffResult {
|
||||
status: vec![WasmDiffStatus::Bad(
|
||||
format!(
|
||||
"Nullness mismatch. Emacs=({emacs:?}) Wasm=({wasm:?}).",
|
||||
emacs = emacs,
|
||||
wasm = wasm
|
||||
)
|
||||
.into(),
|
||||
)],
|
||||
children: Vec::new(),
|
||||
name: "".into(),
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
||||
fn compare_ast_node<'e, 's, 'w>(
|
||||
source: &'s str,
|
||||
emacs: &'e Vec<Token<'s>>,
|
||||
wasm: &'w serde_json::Map<String, serde_json::Value>,
|
||||
) -> Result<WasmDiffResult<'s>, Box<dyn std::error::Error>> {
|
||||
let mut result = WasmDiffResult::default();
|
||||
let mut emacs_list_iter = emacs.iter();
|
||||
|
||||
{
|
||||
// Compare ast node type.
|
||||
let emacs_name = emacs_list_iter
|
||||
.next()
|
||||
.ok_or("Should have a name as the first child.")?
|
||||
.as_atom()?;
|
||||
let wasm_name = wasm
|
||||
.get("ast-node")
|
||||
.ok_or("Should have a ast node type.")?
|
||||
.as_str()
|
||||
.ok_or("Ast node type should be a string.")?;
|
||||
result.name = emacs_name.into();
|
||||
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(),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
if result.is_bad() {
|
||||
return Ok(result);
|
||||
}
|
||||
|
||||
let emacs_attributes_map = emacs_list_iter
|
||||
.next()
|
||||
.ok_or("Should have an attributes child.")?
|
||||
.as_map()?;
|
||||
let wasm_attributes_map = wasm
|
||||
.get("properties")
|
||||
.ok_or(r#"Wasm ast node should have a "properties" attribute."#)?
|
||||
.as_object()
|
||||
.ok_or(r#"Wasm ast node "properties" attribute should be an object."#)?;
|
||||
|
||||
{
|
||||
// Compare attribute names.
|
||||
let emacs_keys: std::collections::BTreeSet<String> = emacs_attributes_map
|
||||
.keys()
|
||||
.map(|s| (*s).to_owned())
|
||||
.collect();
|
||||
// wasm_attributes_map.iter().filter_map(|(k,v)| if matches!(v, serde_json::Value::Null) {None} else {Some(k)}).map(wasm_key_to_emacs_key)
|
||||
let wasm_keys: std::collections::BTreeSet<String> =
|
||||
std::iter::once(":standard-properties".to_owned())
|
||||
.chain(wasm_attributes_map.keys().map(wasm_key_to_emacs_key))
|
||||
.collect();
|
||||
let emacs_only_attributes: Vec<&String> = emacs_keys.difference(&wasm_keys).collect();
|
||||
let wasm_only_attributes: Vec<&String> = wasm_keys
|
||||
.difference(&emacs_keys)
|
||||
.filter(|attribute| {
|
||||
emacs_attributes_map
|
||||
.get(attribute.as_str())
|
||||
.map(|token| !matches!(token, Token::Atom("nil")))
|
||||
.unwrap_or(false)
|
||||
})
|
||||
.collect();
|
||||
if !emacs_only_attributes.is_empty() {
|
||||
result.status.push(WasmDiffStatus::Bad(
|
||||
format!(
|
||||
"Wasm node lacked field present in elisp node ({name}).",
|
||||
name = emacs_only_attributes
|
||||
.iter()
|
||||
.map(|s| s.as_str())
|
||||
.intersperse(", ")
|
||||
.collect::<String>(),
|
||||
)
|
||||
.into(),
|
||||
));
|
||||
}
|
||||
if !wasm_only_attributes.is_empty() {
|
||||
result.status.push(WasmDiffStatus::Bad(
|
||||
format!(
|
||||
"Elisp node lacked field present in wasm node ({name}).",
|
||||
name = wasm_only_attributes
|
||||
.iter()
|
||||
.map(|s| s.as_str())
|
||||
.intersperse(", ")
|
||||
.collect::<String>(),
|
||||
)
|
||||
.into(),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
if result.is_bad() {
|
||||
return Ok(result);
|
||||
}
|
||||
|
||||
{
|
||||
// Compare attributes.
|
||||
for attribute_name in wasm_attributes_map.keys() {
|
||||
let mut layer = WasmDiffResult::default();
|
||||
layer.name = Cow::Owned(attribute_name.clone());
|
||||
let wasm_attribute_value = wasm_attributes_map.get(attribute_name);
|
||||
let emacs_key = wasm_key_to_emacs_key(attribute_name);
|
||||
let emacs_attribute_value = emacs_attributes_map.get(emacs_key.as_str()).map(|e| *e);
|
||||
let inner_layer =
|
||||
compare_optional_json_value(source, emacs_attribute_value, wasm_attribute_value)?;
|
||||
if !inner_layer.name.is_empty() {
|
||||
layer.children.push(inner_layer);
|
||||
} else {
|
||||
layer.extend(inner_layer)?;
|
||||
}
|
||||
result.children.push(layer);
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
// Compare standard-properties.
|
||||
let mut layer = WasmDiffResult::default();
|
||||
layer.name = "standard-properties".into();
|
||||
let emacs_standard_properties = wasm_get_emacs_standard_properties(&emacs_attributes_map)?;
|
||||
let wasm_standard_properties = wasm
|
||||
.get("standard-properties")
|
||||
.ok_or(r#"Wasm AST nodes should have a "standard-properties" attribute."#)?
|
||||
.as_object()
|
||||
.ok_or(r#"Wasm ast node "standard-properties" attribute should be an object."#)?;
|
||||
for (emacs_value, wasm_name) in [
|
||||
(emacs_standard_properties.begin, "begin"),
|
||||
(emacs_standard_properties.end, "end"),
|
||||
(emacs_standard_properties.contents_begin, "contents-begin"),
|
||||
(emacs_standard_properties.contents_end, "contents-end"),
|
||||
(emacs_standard_properties.post_blank, "post-blank"),
|
||||
] {
|
||||
match (emacs_value, wasm_standard_properties.get(wasm_name)) {
|
||||
(None, None) | (None, Some(serde_json::Value::Null)) => {}
|
||||
(None, Some(_)) => {
|
||||
layer.status.push(WasmDiffStatus::Bad(
|
||||
format!(
|
||||
"Elisp node lacked field present in wasm node. Name=({name}).",
|
||||
name = wasm_name,
|
||||
)
|
||||
.into(),
|
||||
));
|
||||
}
|
||||
(Some(_), None) => {
|
||||
layer.status.push(WasmDiffStatus::Bad(
|
||||
format!(
|
||||
"Wasm node lacked field present in elisp node. Name=({name}).",
|
||||
name = wasm_name,
|
||||
)
|
||||
.into(),
|
||||
));
|
||||
}
|
||||
(Some(e), Some(serde_json::Value::Number(w)))
|
||||
if w.as_u64().map(|w| w as usize) == Some(e) => {}
|
||||
(Some(e), Some(w)) => {
|
||||
layer.status.push(WasmDiffStatus::Bad(
|
||||
format!(
|
||||
"Property value mismatch. Emacs=({emacs:?}) Wasm=({wasm:?}).",
|
||||
emacs = e,
|
||||
wasm = w,
|
||||
)
|
||||
.into(),
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
result.children.push(layer);
|
||||
}
|
||||
|
||||
{
|
||||
// Compare children.
|
||||
let mut layer = WasmDiffResult::default();
|
||||
layer.name = "children".into();
|
||||
if let Some(wasm_iter) = wasm
|
||||
.get("children")
|
||||
.map(|children| children.as_array())
|
||||
.flatten()
|
||||
.map(|children| children.iter())
|
||||
{
|
||||
layer.extend(wasm_compare_list(source, emacs_list_iter, wasm_iter)?)?;
|
||||
} else {
|
||||
layer.extend(wasm_compare_list(
|
||||
source,
|
||||
emacs_list_iter,
|
||||
std::iter::empty::<&serde_json::Value>(),
|
||||
)?)?;
|
||||
}
|
||||
result.children.push(layer);
|
||||
}
|
||||
|
||||
Ok(result)
|
||||
}
|
||||
|
||||
fn wasm_key_to_emacs_key<WK: std::fmt::Display>(wasm_key: WK) -> String {
|
||||
format!(":{key}", key = wasm_key)
|
||||
}
|
||||
|
||||
fn compare_quoted_string<'e, 's, 'w>(
|
||||
source: &'s str,
|
||||
emacs: &'e str,
|
||||
wasm: &'w String,
|
||||
) -> Result<WasmDiffResult<'s>, Box<dyn std::error::Error>> {
|
||||
let mut result = WasmDiffResult::default();
|
||||
let emacs_text = unquote(emacs)?;
|
||||
if wasm.as_str() != emacs_text {
|
||||
result.status.push(WasmDiffStatus::Bad(
|
||||
format!(
|
||||
"Text mismatch. Emacs=({emacs:?}) Wasm=({wasm:?}).",
|
||||
emacs = emacs_text,
|
||||
wasm = wasm,
|
||||
)
|
||||
.into(),
|
||||
));
|
||||
}
|
||||
Ok(result)
|
||||
}
|
||||
|
||||
pub(crate) fn wasm_get_emacs_standard_properties(
|
||||
attributes_map: &HashMap<&str, &Token<'_>>,
|
||||
) -> Result<EmacsStandardProperties, Box<dyn std::error::Error>> {
|
||||
let standard_properties = attributes_map.get(":standard-properties");
|
||||
Ok(if standard_properties.is_some() {
|
||||
let mut std_props = standard_properties
|
||||
.expect("if statement proves its Some")
|
||||
.as_vector()?
|
||||
.iter();
|
||||
let begin = maybe_token_to_usize(std_props.next())?;
|
||||
let post_affiliated = maybe_token_to_usize(std_props.next())?;
|
||||
let contents_begin = maybe_token_to_usize(std_props.next())?;
|
||||
let contents_end = maybe_token_to_usize(std_props.next())?;
|
||||
let end = maybe_token_to_usize(std_props.next())?;
|
||||
let post_blank = maybe_token_to_usize(std_props.next())?;
|
||||
EmacsStandardProperties {
|
||||
begin,
|
||||
post_affiliated,
|
||||
contents_begin,
|
||||
contents_end,
|
||||
end,
|
||||
post_blank,
|
||||
}
|
||||
} else {
|
||||
let begin = maybe_token_to_usize(attributes_map.get(":begin").copied())?;
|
||||
let end = maybe_token_to_usize(attributes_map.get(":end").copied())?;
|
||||
let contents_begin = maybe_token_to_usize(attributes_map.get(":contents-begin").copied())?;
|
||||
let contents_end = maybe_token_to_usize(attributes_map.get(":contents-end").copied())?;
|
||||
let post_blank = maybe_token_to_usize(attributes_map.get(":post-blank").copied())?;
|
||||
let post_affiliated =
|
||||
maybe_token_to_usize(attributes_map.get(":post-affiliated").copied())?;
|
||||
EmacsStandardProperties {
|
||||
begin,
|
||||
post_affiliated,
|
||||
contents_begin,
|
||||
contents_end,
|
||||
end,
|
||||
post_blank,
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
fn wasm_compare_list<'e, 's: 'e, 'w, EI, WI>(
|
||||
source: &'s str,
|
||||
mut emacs: EI,
|
||||
wasm: WI,
|
||||
) -> Result<WasmDiffResult<'s>, Box<dyn std::error::Error>>
|
||||
where
|
||||
EI: Iterator<Item = &'e Token<'s>> + ExactSizeIterator,
|
||||
WI: Iterator<Item = &'w serde_json::Value> + ExactSizeIterator,
|
||||
{
|
||||
let emacs_length = emacs.len();
|
||||
let wasm_length = wasm.len();
|
||||
if emacs_length == 1 && wasm_length == 0 {
|
||||
if emacs.all(|t| matches!(t.as_atom(), Ok(r#""""#))) {
|
||||
return Ok(WasmDiffResult::default());
|
||||
}
|
||||
}
|
||||
if emacs_length != wasm_length {
|
||||
return Ok(WasmDiffResult {
|
||||
status: vec![WasmDiffStatus::Bad(
|
||||
format!(
|
||||
"Child length mismatch. Emacs=({emacs:?}) Wasm=({wasm:?}).",
|
||||
emacs = emacs_length,
|
||||
wasm = 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(compare_json_value(source, emacs_child, wasm_child)?);
|
||||
}
|
||||
Ok(WasmDiffResult {
|
||||
status: Vec::new(),
|
||||
children: child_status,
|
||||
name: "".into(),
|
||||
})
|
||||
}
|
||||
|
||||
fn compare_optional_pair<'e, 's, 'w>(
|
||||
source: &'s str,
|
||||
emacs: &'e Vec<Token<'s>>,
|
||||
wasm: &'w serde_json::Map<String, serde_json::Value>,
|
||||
) -> Result<WasmDiffResult<'s>, Box<dyn std::error::Error>> {
|
||||
let mut result = WasmDiffResult::default();
|
||||
let wasm_optval = wasm
|
||||
.get("optval")
|
||||
.ok_or(r#"Wasm optional pair should have an "optval" attribute."#)?;
|
||||
let wasm_val = wasm
|
||||
.get("val")
|
||||
.ok_or(r#"Wasm optional pair should have an "optval" attribute."#)?;
|
||||
if let serde_json::Value::Null = wasm_optval {
|
||||
// If the optval is null, then the elisp should have just a single value of a quoted string.
|
||||
if emacs.len() != 1 {
|
||||
return Ok(WasmDiffResult {
|
||||
status: vec![WasmDiffStatus::Bad(
|
||||
format!(
|
||||
"Optional pair with null optval should have 1 element. Emacs=({emacs:?}) Wasm=({wasm:?}).",
|
||||
emacs = emacs,
|
||||
wasm = wasm
|
||||
)
|
||||
.into(),
|
||||
)],
|
||||
children: Vec::new(),
|
||||
name: "".into(),
|
||||
});
|
||||
}
|
||||
|
||||
let emacs_val = emacs
|
||||
.first()
|
||||
.expect("If-statement proves this will be Some.");
|
||||
result.extend(compare_json_value(source, emacs_val, wasm_val)?)?;
|
||||
} else {
|
||||
// If the optval is not null, then the elisp should have 3 values, the optval, a dot, and the val.
|
||||
if emacs.len() != 3 {
|
||||
return Ok(WasmDiffResult {
|
||||
status: vec![WasmDiffStatus::Bad(
|
||||
format!(
|
||||
"Optional pair with non-null optval should have 3 elements. Emacs=({emacs:?}) Wasm=({wasm:?}).",
|
||||
emacs = emacs,
|
||||
wasm = wasm
|
||||
)
|
||||
.into(),
|
||||
)],
|
||||
children: Vec::new(),
|
||||
name: "".into(),
|
||||
});
|
||||
}
|
||||
let emacs_optval = emacs
|
||||
.first()
|
||||
.expect("If-statement proves this will be Some.");
|
||||
let emacs_val = emacs
|
||||
.get(2)
|
||||
.expect("If-statement proves this will be Some.");
|
||||
result.extend(compare_json_value(source, emacs_optval, wasm_optval)?)?;
|
||||
result.extend(compare_json_value(source, emacs_val, wasm_val)?)?;
|
||||
}
|
||||
Ok(result)
|
||||
}
|
||||
|
||||
fn compare_object_tree<'e, 's, 'w>(
|
||||
source: &'s str,
|
||||
emacs: &'e Vec<Token<'s>>,
|
||||
wasm: &'w serde_json::Map<String, serde_json::Value>,
|
||||
) -> Result<WasmDiffResult<'s>, Box<dyn std::error::Error>> {
|
||||
let mut result = WasmDiffResult::default();
|
||||
let wasm_attributes = wasm
|
||||
.get("object-tree")
|
||||
.ok_or(r#"Wasm object tree should have an "object-tree" attribute."#)?
|
||||
.as_array()
|
||||
.ok_or(r#"Wasm "object-tree" attribute should be a list."#)?;
|
||||
let emacs_outer_length = emacs.len();
|
||||
let wasm_outer_length = wasm_attributes.len();
|
||||
if emacs_outer_length != wasm_outer_length {
|
||||
result.status.push(WasmDiffStatus::Bad(
|
||||
format!(
|
||||
"Child length mismatch. Emacs=({emacs:?}) Wasm=({wasm:?}).",
|
||||
emacs = emacs_outer_length,
|
||||
wasm = wasm_outer_length
|
||||
)
|
||||
.into(),
|
||||
));
|
||||
return Ok(result);
|
||||
}
|
||||
|
||||
for (emacs_attribute, wasm_attribute) in emacs.iter().zip(wasm_attributes.iter()) {
|
||||
let emacs_attribute = emacs_attribute.as_list()?;
|
||||
let wasm_attribute = wasm_attribute
|
||||
.as_array()
|
||||
.ok_or("Wasm middle layer in object tree should be a list.")?;
|
||||
if wasm_attribute.len() != 2 {
|
||||
result.status.push(WasmDiffStatus::Bad(
|
||||
format!(
|
||||
"Wasm middle layer in object tree should have a length of 2. Wasm=({wasm:?}).",
|
||||
wasm = wasm_attribute.len()
|
||||
)
|
||||
.into(),
|
||||
));
|
||||
return Ok(result);
|
||||
}
|
||||
if let Some(serde_json::Value::Null) = wasm_attribute.first() {
|
||||
// If optval is null then the emacs array should only contain 1 value.
|
||||
if emacs_attribute.len() != 1 {
|
||||
result.status.push(WasmDiffStatus::Bad(
|
||||
format!(
|
||||
"Emacs middle layer in object tree should have a length of 1. Emacs=({emacs:?}) Wasm=({wasm:?}).",
|
||||
emacs = emacs_attribute,
|
||||
wasm = wasm_attribute
|
||||
)
|
||||
.into(),
|
||||
));
|
||||
return Ok(result);
|
||||
}
|
||||
|
||||
let emacs_val = emacs_attribute
|
||||
.first()
|
||||
.expect("If-statement proves this will be Some.");
|
||||
let wasm_val = wasm_attribute
|
||||
.get(1)
|
||||
.expect("If-statement proves this will be Some.");
|
||||
result.extend(compare_json_value(source, emacs_val, wasm_val)?)?;
|
||||
} else {
|
||||
// If optval is not null, then the emacs array should contain a list, the first child of which is a list for optval, and all other entries to the outer list are the val.
|
||||
if emacs_attribute.len() < 2 {
|
||||
result.status.push(WasmDiffStatus::Bad(
|
||||
format!(
|
||||
"Emacs middle layer in object tree should have a length of at least 2. Emacs=({emacs:?}) Wasm=({wasm:?}).",
|
||||
emacs = emacs_attribute,
|
||||
wasm = wasm_attribute
|
||||
)
|
||||
.into(),
|
||||
));
|
||||
return Ok(result);
|
||||
}
|
||||
let emacs_optval = emacs_attribute.iter().skip(1);
|
||||
let wasm_optval = wasm_attribute
|
||||
.first()
|
||||
.expect("If-statement proves this will be Some.")
|
||||
.as_array()
|
||||
.ok_or("first value in wasm object tree should be a list.")?;
|
||||
let emacs_val = emacs_attribute
|
||||
.first()
|
||||
.ok_or("If-statement proves this will be Some.")?
|
||||
.as_list()?;
|
||||
let wasm_val = wasm_attribute
|
||||
.get(1)
|
||||
.expect("If-statement proves this will be Some.")
|
||||
.as_array()
|
||||
.ok_or("2nd value in wasm object tree should be a list.")?;
|
||||
result.extend(wasm_compare_list(source, emacs_optval, wasm_optval.iter())?)?;
|
||||
result.extend(wasm_compare_list(
|
||||
source,
|
||||
emacs_val.iter(),
|
||||
wasm_val.iter(),
|
||||
)?)?;
|
||||
}
|
||||
}
|
||||
|
||||
Ok(result)
|
||||
}
|
||||
|
||||
fn is_plain_text<'e, 's, 'w>(wasm: &'w serde_json::Map<String, serde_json::Value>) -> bool {
|
||||
if let Some(serde_json::Value::String(node_type)) = wasm.get("ast-node") {
|
||||
node_type == "plain-text"
|
||||
} else {
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
fn compare_plain_text<'e, 's, 'w>(
|
||||
source: &'s str,
|
||||
emacs: &'e TextWithProperties<'s>,
|
||||
wasm: &'w serde_json::Map<String, serde_json::Value>,
|
||||
) -> Result<WasmDiffResult<'s>, Box<dyn std::error::Error>> {
|
||||
let mut result = WasmDiffResult::default();
|
||||
result.name = "plain-text".into();
|
||||
if !is_plain_text(wasm) {
|
||||
result.status.push(WasmDiffStatus::Bad(
|
||||
format!(
|
||||
"AST node type mismatch. Emacs=({emacs:?}) Wasm=({wasm:?}).",
|
||||
emacs = emacs,
|
||||
wasm = wasm,
|
||||
)
|
||||
.into(),
|
||||
));
|
||||
return Ok(result);
|
||||
}
|
||||
|
||||
let emacs_text = unquote(emacs.text)?;
|
||||
let wasm_standard_properties = wasm
|
||||
.get("standard-properties")
|
||||
.ok_or(r#"Wasm AST nodes should have a "standard-properties" attribute."#)?
|
||||
.as_object()
|
||||
.ok_or(r#"Wasm ast node "standard-properties" attribute should be an object."#)?;
|
||||
let wasm_begin = {
|
||||
if let Some(serde_json::Value::Number(begin)) = wasm_standard_properties.get("begin") {
|
||||
begin
|
||||
.as_u64()
|
||||
.map(|w| w as usize)
|
||||
.ok_or("Begin should be a number.")?
|
||||
} else {
|
||||
result.status.push(WasmDiffStatus::Bad(
|
||||
format!(
|
||||
"AST node type mismatch. Emacs=({emacs:?}) Wasm=({wasm:?}).",
|
||||
emacs = emacs,
|
||||
wasm = wasm,
|
||||
)
|
||||
.into(),
|
||||
));
|
||||
return Ok(result);
|
||||
}
|
||||
};
|
||||
let wasm_end = {
|
||||
if let Some(serde_json::Value::Number(end)) = wasm_standard_properties.get("end") {
|
||||
end.as_u64()
|
||||
.map(|w| w as usize)
|
||||
.ok_or("End should be a number.")?
|
||||
} else {
|
||||
result.status.push(WasmDiffStatus::Bad(
|
||||
format!(
|
||||
"AST node type mismatch. Emacs=({emacs:?}) Wasm=({wasm:?}).",
|
||||
emacs = emacs,
|
||||
wasm = wasm,
|
||||
)
|
||||
.into(),
|
||||
));
|
||||
return Ok(result);
|
||||
}
|
||||
};
|
||||
let wasm_text: String = source
|
||||
.chars()
|
||||
.skip(wasm_begin - 1)
|
||||
.take(wasm_end - wasm_begin)
|
||||
.collect();
|
||||
if wasm_text != emacs_text {
|
||||
result.status.push(WasmDiffStatus::Bad(
|
||||
format!(
|
||||
"Text mismatch. Emacs=({emacs:?}) Wasm=({wasm:?}).",
|
||||
emacs = emacs_text,
|
||||
wasm = wasm_text,
|
||||
)
|
||||
.into(),
|
||||
));
|
||||
return Ok(result);
|
||||
}
|
||||
|
||||
let emacs_start = emacs
|
||||
.properties
|
||||
.first()
|
||||
.map(|t| t.as_atom())
|
||||
.map_or(Ok(None), |r| r.map(Some))?;
|
||||
if emacs_start != Some("0") {
|
||||
result.status.push(WasmDiffStatus::Bad(
|
||||
format!(
|
||||
"Text should start at offset 0. Emacs=({emacs:?}) Wasm=({wasm:?}).",
|
||||
emacs = emacs,
|
||||
wasm = wasm,
|
||||
)
|
||||
.into(),
|
||||
));
|
||||
}
|
||||
let emacs_end = emacs
|
||||
.properties
|
||||
.get(1)
|
||||
.map(|t| t.as_atom())
|
||||
.map_or(Ok(None), |r| r.map(Some))?;
|
||||
if emacs_end != Some((wasm_end - wasm_begin).to_string().as_str()) {
|
||||
result.status.push(WasmDiffStatus::Bad(
|
||||
format!(
|
||||
"Text end mismatch. Emacs=({emacs:?}) Wasm=({wasm:?}).",
|
||||
emacs = emacs_end,
|
||||
wasm = wasm_end - wasm_begin,
|
||||
)
|
||||
.into(),
|
||||
));
|
||||
}
|
||||
|
||||
Ok(result)
|
||||
}
|
||||
108
src/wasm_test/diff.rs
Normal file
108
src/wasm_test/diff.rs
Normal file
@@ -0,0 +1,108 @@
|
||||
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)
|
||||
}
|
||||
|
||||
fn print_indented(
|
||||
&self,
|
||||
indentation: usize,
|
||||
original_document: &str,
|
||||
) -> Result<(), Box<dyn std::error::Error>> {
|
||||
let status_text = {
|
||||
if self.is_self_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(),
|
||||
}
|
||||
}
|
||||
}
|
||||
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;
|
||||
9
src/wasm_test/mod.rs
Normal file
9
src/wasm_test/mod.rs
Normal file
@@ -0,0 +1,9 @@
|
||||
mod compare;
|
||||
mod diff;
|
||||
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)
|
||||
}
|
||||
@@ -60,3 +60,13 @@ async fn autogen_odd_{name}() -> Result<(), Box<dyn std::error::Error>> {{
|
||||
assert!(organic::compare::run_anonymous_compare_with_settings(org_contents.as_str(), &global_settings, false).await?);
|
||||
Ok(())
|
||||
}}
|
||||
|
||||
#[cfg(feature = "wasm_test")]
|
||||
{expect_fail}
|
||||
#[tokio::test]
|
||||
async fn autogen_wasm_{name}() -> Result<(), Box<dyn std::error::Error>> {{
|
||||
let org_path = "{path}";
|
||||
let org_contents = std::fs::read_to_string(org_path).expect("Read org file.");
|
||||
assert!(organic::wasm_test::wasm_run_anonymous_compare(org_contents.as_str()).await?);
|
||||
Ok(())
|
||||
}}
|
||||
|
||||
Reference in New Issue
Block a user