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
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