diff --git a/.forgejo/workflows/webrepl.yaml b/.forgejo/workflows/webrepl.yaml new file mode 100644 index 0000000..f842352 --- /dev/null +++ b/.forgejo/workflows/webrepl.yaml @@ -0,0 +1,40 @@ +name: webrepl +on: [push] +#on: +# push: +# branches: +# - main +jobs: + test: + runs-on: docker + + container: + image: rust:1.83-alpine + + steps: + - name: Install dependencies + run: apk add --no-cache git nodejs util-linux + + - name: Install wasm-pack + run: cargo install wasm-pack + + - name: Checkout + uses: actions/checkout@v4 + + - name: Build talc-web + run: wasm-pack build --release --no-typescript --no-pack --target web + working-directory: talc-web + + - name: Save artifacts + uses: forgejo/upload-artifact@v4 + with: + name: webrepl + path: | + *.html + *.js + *.css + pkg/ + if-no-files-found: error + + - name: Done + run: echo done! diff --git a/Cargo.lock b/Cargo.lock index c764966..f5aa90d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -29,6 +29,12 @@ version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" +[[package]] +name = "bumpalo" +version = "3.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c" + [[package]] name = "byteorder" version = "1.5.0" @@ -144,8 +150,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7" dependencies = [ "cfg-if", + "js-sys", "libc", "wasi", + "wasm-bindgen", ] [[package]] @@ -163,6 +171,16 @@ dependencies = [ "windows-sys 0.59.0", ] +[[package]] +name = "js-sys" +version = "0.3.76" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6717b6b5b077764fb5966237269cb3c64edddde4b14ce42647430a78ced9e7b7" +dependencies = [ + "once_cell", + "wasm-bindgen", +] + [[package]] name = "lazy_static" version = "1.5.0" @@ -288,6 +306,12 @@ dependencies = [ "autocfg", ] +[[package]] +name = "once_cell" +version = "1.20.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775" + [[package]] name = "ppv-lite86" version = "0.2.20" @@ -427,9 +451,9 @@ checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" [[package]] name = "syn" -version = "2.0.94" +version = "2.0.95" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "987bc0be1cdea8b10216bd06e2ca407d40b9543468fafd3ddfb02f36e77f71f3" +checksum = "46f71c0377baf4ef1cc3e3402ded576dccc315800fbc62dfc7fe04b009773b4a" dependencies = [ "proc-macro2", "quote", @@ -477,6 +501,16 @@ dependencies = [ "talc-macros", ] +[[package]] +name = "talc-web" +version = "0.1.0" +dependencies = [ + "getrandom", + "talc-lang", + "talc-std", + "wasm-bindgen", +] + [[package]] name = "unicode-ident" version = "1.0.14" @@ -507,6 +541,60 @@ version = "0.11.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" +[[package]] +name = "wasm-bindgen" +version = "0.2.99" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a474f6281d1d70c17ae7aa6a613c87fce69a127e2624002df63dcb39d6cf6396" +dependencies = [ + "cfg-if", + "once_cell", + "wasm-bindgen-macro", +] + +[[package]] +name = "wasm-bindgen-backend" +version = "0.2.99" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f89bb38646b4f81674e8f5c3fb81b562be1fd936d84320f3264486418519c79" +dependencies = [ + "bumpalo", + "log", + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.99" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2cc6181fd9a7492eef6fef1f33961e3695e4579b9872a6f7c83aee556666d4fe" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.99" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "30d7a95b763d3c45903ed6c81f156801839e5ee968bb07e534c44df0fcd330c2" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-backend", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.99" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "943aab3fdaaa029a6e0271b35ea10b72b943135afe9bffca82384098ad0e06a6" + [[package]] name = "windows-sys" version = "0.52.0" diff --git a/Cargo.toml b/Cargo.toml index ecfe00c..60d5ad0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,5 +1,5 @@ [workspace] -members = ["talc-lang", "talc-bin", "talc-std", "talc-macros"] +members = ["talc-lang", "talc-bin", "talc-std", "talc-macros", "talc-web"] resolver = "2" diff --git a/docs/src/SUMMARY.md b/docs/src/SUMMARY.md index 8bf81f2..1d7ef76 100644 --- a/docs/src/SUMMARY.md +++ b/docs/src/SUMMARY.md @@ -4,6 +4,7 @@ - [Installation](./install/installation.md) - [Tour of the REPL](./install/repl.md) +- [The Web REPL](./install/webrepl.md) # The language diff --git a/docs/src/install/webrepl.md b/docs/src/install/webrepl.md new file mode 100644 index 0000000..3029d26 --- /dev/null +++ b/docs/src/install/webrepl.md @@ -0,0 +1,18 @@ +# The Web REPL + +As an alterative to the command-line REPL, you can try out Talc in the browser +at (https://talc.trimill.xyz/repl)[https://talc.trimill.xyz/repl]. Although +the full Talc language and standard library (aside from file I/O and process +control) are available, editing features are more limited than the command-line +interface - especially of note is the lack of syntax highlighting and tab +completion. + +## Usage + +Just like the command-line REPL, enter an expression and press Enter to +evaluate it. Use the up and down arrows to access input history. + +For multiline editing, use Shift+Enter to insert a newline. Hold the Control +key while pressing the up or down arrows to move the cursor between lines. + +To clear the screen, press Ctrl+L. diff --git a/talc-web/Cargo.toml b/talc-web/Cargo.toml new file mode 100644 index 0000000..32f0e98 --- /dev/null +++ b/talc-web/Cargo.toml @@ -0,0 +1,16 @@ +[package] +name = "talc-web" +version = "0.1.0" +edition = "2021" + +[lib] +crate-type = ["cdylib", "rlib"] + +[lints] +workspace = true + +[dependencies] +talc-lang = { path = "../talc-lang" } +talc-std = { path = "../talc-std", default-features = false, features = ["rand", "regex"] } +getrandom = { version = "0.2", features = ["js"] } +wasm-bindgen = "0.2" diff --git a/talc-web/README.md b/talc-web/README.md new file mode 100644 index 0000000..47bd9dc --- /dev/null +++ b/talc-web/README.md @@ -0,0 +1,16 @@ +# Talc Web + +The `talc-web` crate provides a WASM interface to execute Talc expressions +in a REPL. Together with the associated HTML, CSS, and JavaScript files, this +creates an alternative to the command-line REPL. + +## Building + +In the `talc-web` directory, run: + +```bash +wasm-pack build --release --no-typescript --no-pack --target web +``` + +See (the main README.md)[../README.md] for more information about building +Talc. diff --git a/talc-web/index.html b/talc-web/index.html new file mode 100644 index 0000000..3752624 --- /dev/null +++ b/talc-web/index.html @@ -0,0 +1,29 @@ + + +
+ + + +