Repository navigation
feat(docs): add interactive Dang WASM REPL component - #88
Merged
Merged
Conversation
Deploying dang with
|
| Latest commit: |
6a6bd82
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://aa1314a9.dang-3kk.pages.dev |
| Branch Preview URL: | https://dang-wasm-repl.dang-3kk.pages.dev |
Add a \dang-repl Booklit component: an in-browser read-eval-print loop built on the same stack as \dang-playground (the cmd/dang-playground WASM module plus tree-sitter highlighting), but presented as a transcript of evaluated entries rather than a single editor. State accumulates across entries within a long-running session, like the CLI REPL. The WASM gains dangReplEval(sessionID, source) and dangReplReset(sessionID) exports: each session keeps a scope pair alive in the module and mutates it in place, so every entry is type-checked and evaluated incrementally against accumulated state — nothing is re-parsed or re-run. Sessions are keyed per REPL component so multiple REPLs on a page stay isolated. This mirrors the native CLI REPL (cmd/dang/repl_tuist.go); the browser REPL is core-language only (no GraphQL imports), so it stays synchronous. The tradeoff of in-place state is that an entry which fails partway can leave partial state behind, which dangReplReset clears. The frontend reuses the playground's asset loader, lazy WASM loader, and tree-sitter highlighter. Bare Enter evaluates when bracket nesting looks balanced, Shift+Enter forces a newline, and Ctrl/Cmd+Enter or the Run button always evaluate. The prompt and "=>" result mirror the CLI REPL. Token colors are de-scoped from .dang-playground-highlight to plain .tok-* so both widgets share one palette. Getting Started gains a small REPL demo seeded with a binding the reader can reference on the next line. Signed-off-by: Alex Suraci <[email protected]>
The base `pre` rule forced `padding:1rem 1.25rem !important`, which beats inline and per-component styles that aren't themselves marked important. That silently clobbered the REPL's code/input rows (which want padding:0, so the transcript aligns under the `dang>` prompt) and the install shell block (which sets a tighter `.5rem .9rem` inline). It was added in the initial scaffold with no rationale, and nothing emits inline `pre` padding that needs overriding — chroma blocks only set color/background inline — so the !important guards nothing. Dropping it lets the more specific `.dang-repl-*` rules and the shell block's inline padding apply as intended; chroma code blocks still pick up the base padding normally. Signed-off-by: Alex Suraci <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Adds a
\dang-replBooklit component: an interactive, in-browser read-eval-print loop for Dang, built on the same tech stack as the existing\dang-playground(thecmd/dang-playgroundWASM module + tree-sitter highlighting) but presented as a REPL — a transcript of evaluated entries with a live input — instead of a single editor.This addresses the docs-feedback request to "implement a Dang WASM REPL, building on the existing Dang playground… another type of component, but [on] the same tech stack: user-editable, treesitter-highlighted, but as a REPL."
How it works
dangReplEval(sessionID, source)anddangReplReset(sessionID). Each session keeps a scope pair (type scope + value scope) alive inside the module and mutates it in place on every entry, so each input is type-checked and evaluated incrementally against the accumulated state — nothing is re-parsed or re-run. This mirrors the native CLI REPL (cmd/dang/repl_tuist.go), which reuses one scope pair for the whole session rather than replaying history. A freshFresheris allocated per call (its type-variable counter is monotonic), but that's independent of the session state.dangReplResetdrops it (the next eval starts from fresh standard-library scopes). The browser REPL is core-language only (no GraphQL imports), so unlikedangEvalit never touches the network and stays synchronous.evalForms, distinct from the playground's GitHub-awareevalSource. The frontend lives in the existingplayground.js, reusing the asset resolver, lazy WASM loader, and tree-sitter highlighter;loadDang()now resolves to all three exports.type { … }entries keep accepting newlines until closed), Shift+Enter forces a newline, and Ctrl/Cmd+Enter or the Run button always evaluate. Thedang>prompt and=>result mirror the CLI REPL documented in Getting Started..dang-playground-highlightto plain.tok-*so the playground and REPL share one palette.Demo
Getting Started gains a small REPL seeded with
let greeting = "world", with a note that the browser REPL runs the core language only (no GraphQL imports).No JS → it degrades to a plain code block, same as the playground. The built
dang.wasmis produced bydocs/build.sh(gitignored, built in CI), so no binary churn here.Verification
GOOS=js GOARCH=wasmbuild +go vetpass. A native harness exercising the realdangAPI against one persistent scope pair confirmed the session semantics: binding carry-over, string interpolation against prior bindings,typedeclarations persisting and constructing across entries (e.g.type Point { … }thenPoint(x: 3).x),printoutput capture, and a type error leaving the session intact (a later entry still resolves earlier bindings).🤖 Generated with Claude Code