mirror of
https://github.com/ParkerTenBroeck/automata.git
synced 2026-06-06 21:24:06 -04:00
adding web
This commit is contained in:
parent
d34136f70b
commit
f155a3d7d8
8 changed files with 229 additions and 37 deletions
144
Cargo.lock
generated
144
Cargo.lock
generated
|
|
@ -5,3 +5,147 @@ version = 4
|
|||
[[package]]
|
||||
name = "automata"
|
||||
version = "0.1.0"
|
||||
|
||||
[[package]]
|
||||
name = "automata-web"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"automata",
|
||||
"console_error_panic_hook",
|
||||
"wasm-bindgen",
|
||||
"web-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "bumpalo"
|
||||
version = "3.19.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5dd9dc738b7a8311c7ade152424974d8115f2cdad61e8dab8dac9f2362298510"
|
||||
|
||||
[[package]]
|
||||
name = "cfg-if"
|
||||
version = "1.0.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801"
|
||||
|
||||
[[package]]
|
||||
name = "console_error_panic_hook"
|
||||
version = "0.1.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a06aeb73f470f66dcdbf7223caeebb85984942f22f1adb2a088cf9668146bbbc"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"wasm-bindgen",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "js-sys"
|
||||
version = "0.3.83"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "464a3709c7f55f1f721e5389aa6ea4e3bc6aba669353300af094b29ffbdde1d8"
|
||||
dependencies = [
|
||||
"once_cell",
|
||||
"wasm-bindgen",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "once_cell"
|
||||
version = "1.21.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d"
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro2"
|
||||
version = "1.0.103"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5ee95bc4ef87b8d5ba32e8b7714ccc834865276eab0aed5c9958d00ec45f49e8"
|
||||
dependencies = [
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "quote"
|
||||
version = "1.0.42"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a338cc41d27e6cc6dce6cefc13a0729dfbb81c262b1f519331575dd80ef3067f"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rustversion"
|
||||
version = "1.0.22"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b39cdef0fa800fc44525c84ccb54a029961a8215f9619753635a9c0d2538d46d"
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "2.0.111"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "390cc9a294ab71bdb1aa2e99d13be9c753cd2d7bd6560c77118597410c4d2e87"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "unicode-ident"
|
||||
version = "1.0.22"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9312f7c4f6ff9069b165498234ce8be658059c6728633667c526e27dc2cf1df5"
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen"
|
||||
version = "0.2.106"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0d759f433fa64a2d763d1340820e46e111a7a5ab75f993d1852d70b03dbb80fd"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"once_cell",
|
||||
"rustversion",
|
||||
"wasm-bindgen-macro",
|
||||
"wasm-bindgen-shared",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen-macro"
|
||||
version = "0.2.106"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "48cb0d2638f8baedbc542ed444afc0644a29166f1595371af4fecf8ce1e7eeb3"
|
||||
dependencies = [
|
||||
"quote",
|
||||
"wasm-bindgen-macro-support",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen-macro-support"
|
||||
version = "0.2.106"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cefb59d5cd5f92d9dcf80e4683949f15ca4b511f4ac0a6e14d4e1ac60c6ecd40"
|
||||
dependencies = [
|
||||
"bumpalo",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
"wasm-bindgen-shared",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen-shared"
|
||||
version = "0.2.106"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cbc538057e648b67f72a982e708d485b2efa771e1ac05fec311f9f63e5800db4"
|
||||
dependencies = [
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "web-sys"
|
||||
version = "0.3.83"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9b32828d774c412041098d182a8b38b16ea816958e07cf40eec2bc080ae137ac"
|
||||
dependencies = [
|
||||
"js-sys",
|
||||
"wasm-bindgen",
|
||||
]
|
||||
|
|
|
|||
|
|
@ -4,3 +4,7 @@ version = "0.1.0"
|
|||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
|
||||
|
||||
[workspace]
|
||||
members = ["web"]
|
||||
|
|
@ -5,6 +5,9 @@
|
|||
# Replace llvmPackages with llvmPackages_X, where X is the latest LLVM version (at the time of writing, 16)
|
||||
llvmPackages.bintools
|
||||
rustup
|
||||
wasm-bindgen-cli_0_2_100
|
||||
wasm-pack
|
||||
binaryen
|
||||
];
|
||||
RUSTC_VERSION = "nightly";
|
||||
# https://github.com/rust-lang/rust-bindgen#environment-variables
|
||||
|
|
|
|||
37
src/main.rs
37
src/main.rs
|
|
@ -1,37 +0,0 @@
|
|||
use automata::automata::npda;
|
||||
|
||||
fn main() {
|
||||
let input = include_str!("../example.npda");
|
||||
|
||||
let table = match npda::TransitionTable::load_table(input) {
|
||||
Ok((ok, logs)) => {
|
||||
for log in logs.displayable() {
|
||||
println!("{log}")
|
||||
}
|
||||
ok
|
||||
}
|
||||
Err(logs) => {
|
||||
for log in logs.displayable() {
|
||||
println!("{log}")
|
||||
}
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
let input = "aababaab";
|
||||
println!("running on: '{input}'");
|
||||
let mut simulator = npda::Simulator::begin(input, table);
|
||||
loop {
|
||||
match simulator.step(){
|
||||
npda::SimulatorResult::Pending => {},
|
||||
npda::SimulatorResult::Reject => {
|
||||
println!("REJECTED");
|
||||
break;
|
||||
},
|
||||
npda::SimulatorResult::Accept(npda) => {
|
||||
println!("ACCEPT: {npda:?}");
|
||||
break;
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
10
web/Cargo.toml
Normal file
10
web/Cargo.toml
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
[package]
|
||||
name = "automata-web"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
automata = {path=".."}
|
||||
console_error_panic_hook = "0.1.7"
|
||||
wasm-bindgen = "*"
|
||||
web-sys = { version = "0.3.83", features = ["Window", "Document", "HtmlElement", "Text"] }
|
||||
15
web/build.sh
Executable file
15
web/build.sh
Executable file
|
|
@ -0,0 +1,15 @@
|
|||
|
||||
|
||||
CRATE_NAME="automata-web"
|
||||
TARGET_NAME="automata-web"
|
||||
OUT_FILE_NAME="./root/automata.wasm"
|
||||
mkdir root
|
||||
TARGET="../target"
|
||||
|
||||
|
||||
cargo build --package automata-web --target wasm32-unknown-unknown --release
|
||||
TARGET_NAME="${CRATE_NAME}.wasm"
|
||||
WASM_PATH="${TARGET}/wasm32-unknown-unknown/release/$TARGET_NAME"
|
||||
|
||||
wasm-bindgen ${WASM_PATH} --out-dir root --out-name ${OUT_FILE_NAME} --no-modules --no-typescript
|
||||
wasm-opt ${OUT_FILE_NAME} -O2 --fast-math -g -o ${OUT_FILE_NAME}
|
||||
2
web/init.sh
Executable file
2
web/init.sh
Executable file
|
|
@ -0,0 +1,2 @@
|
|||
cargo install wasm-bindgen-cli
|
||||
rustup target add wasm32-unknown-unknown
|
||||
51
web/src/main.rs
Normal file
51
web/src/main.rs
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
use automata::automata::npda;
|
||||
|
||||
use web_sys::window;
|
||||
|
||||
fn main() {
|
||||
console_error_panic_hook::set_once();
|
||||
|
||||
let document = window()
|
||||
.and_then(|win| win.document())
|
||||
.expect("Could not access the document");
|
||||
let body = document.body().expect("Could not access document.body");
|
||||
let text_node = document.create_text_node("Hello, world from Vanilla Rust!");
|
||||
body.append_child(text_node.as_ref())
|
||||
.expect("Failed to append text");
|
||||
}
|
||||
|
||||
// pub fn main() {
|
||||
// let input = include_str!("../../example.npda");
|
||||
|
||||
// let table = match npda::TransitionTable::load_table(input) {
|
||||
// Ok((ok, logs)) => {
|
||||
// for log in logs.displayable() {
|
||||
// println!("{log}")
|
||||
// }
|
||||
// ok
|
||||
// }
|
||||
// Err(logs) => {
|
||||
// for log in logs.displayable() {
|
||||
// println!("{log}")
|
||||
// }
|
||||
// return;
|
||||
// }
|
||||
// };
|
||||
|
||||
// let input = "aababaab";
|
||||
// println!("running on: '{input}'");
|
||||
// let mut simulator = npda::Simulator::begin(input, table);
|
||||
// loop {
|
||||
// match simulator.step(){
|
||||
// npda::SimulatorResult::Pending => {},
|
||||
// npda::SimulatorResult::Reject => {
|
||||
// println!("REJECTED");
|
||||
// break;
|
||||
// },
|
||||
// npda::SimulatorResult::Accept(npda) => {
|
||||
// println!("ACCEPT: {npda:?}");
|
||||
// break;
|
||||
// },
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
Loading…
Add table
Add a link
Reference in a new issue