Skip to content
playgroundkitPublic

About

Ready-made languages for code-playgrounds: OCaml, Koka, Haskell, Python, Rust, Rocq, Agda, SQL, Typst, the logics of deduxit and more, each a sandboxed language package.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

languages

The language packages for code-playgrounds, the framework that runs code playgrounds in the reader's browser: an editor with language-server support, a Run button and outputs such as a program's output, a tree or a graph. Each language here is a package the framework serves: a manifest, a TextMate grammar and workers, built with Nix from the upstream compiler or interpreter.

The framework is documented in its own repository: the protocol, the sandbox, the element, the hosts. This repository holds the packages, their tests, the flake module that puts them on a site, and a site of examples.

Languages

Language Runs on Editor State
OCaml wasm_of_ocaml toplevel (js_of_ocaml fallback), with Check and QCheck Merlin built (nix build .#ocaml: toplevel 1.9 MB (1.0 MB for the fallback) and Merlin 3.0 MB, 4.9 MB in all, 4.0 MB for the fallback)
OxCaml wasm_of_ocaml toplevel (js_of_ocaml fallback), from OxCaml's opam repository Merlin, with modes built (nix build .#oxcaml: 6.7 MB, 5.4 MB for the fallback)
Koka Koka 3.3.0 (dev commit 2d0d6f4; the compiler on GHC's WebAssembly backend, run as JavaScript; a compile output with the compiler's own messages; fip/fbip warnings; Run refuses programs the JavaScript backend miscompiles, D59) Koka's language server, rebuilt to need no SharedArrayBuffer built (nix build .#koka: 5.6 MB)
JavaScript, TypeScript TypeScript 6.0.3's transpileModule, then the program imported from a blob: URL TypeScript's language service: diagnostics, hover, completion and inlay hints built (nix build .#typescript, .#javascript: 1.2 MB each)
Effekt Effekt's compiler (Scala.js) Effekt's language server built (nix build .#effekt: 0.5 MB)
Python Pyodide 314.0.8 (CPython 3.14), the standard library ty, Astral's type checker, built to WebAssembly built (nix build .#python: 12 MB)
Lua Lua 5.5 built to WebAssembly (Emscripten, standalone) Lua's own parser for diagnostics; hover and completion of the standard library; bytecode listing built (nix build .#lua: 0.14 MB)
Prolog SWI-Prolog 10.1 on WebAssembly (swipl-wasm 8.3.1): every ?- Goal. answered as a table, a proof tree on demand, clpfd and tabling the same system loads the program: syntax errors, singletons, unknown procedures, hover and completion built (nix build .#prolog: 1.8 MB)
Rust none: check only (every browser rustc needs threads) rust-analyzer built to WebAssembly, over the standard library's sources; a macro expanded at the cursor built (nix build .#rust: 4.5 MB)
Standard ML SOSML 1.6.11, an interpreter in JavaScript: each declaration's bindings as a toplevel prints them SOSML's elaboration: errors, types on hover, completion of the Basis library and the program's names built (nix build .#sml: 0.08 MB)
Gleam Gleam 1.19.2's own compiler built to WebAssembly, to JavaScript, which runs with gleam_stdlib 1.3.0 the compiler's errors and warnings with their places; hover with types and documentation; completion of a module's members; the generated JavaScript and Erlang built (nix build .#gleam: 1.0 MB)
Typst Typst 0.15.1's compiler, built to WebAssembly; each page as SVG errors and warnings with ranges, hover and completion from Typst's IDE library, the headings as an outline built (nix build .#typst: 7.5 MB, with fonts for text, code and formulas)
Rocq coq-lsp 0.2.4's WebAssembly build (Rocq 9.1, Stdlib) the same, with the goals at the cursor built (nix build .#rocq: 39 MB)
Haskell GHC 9.14 on its WebAssembly backend, in the bytecode interpreter diagnostics, hover (types) and completion (names in scope, with types) from GHC; Hackage packages such as lens and optics, with Template Haskell, and local cabal packages; a Compile output with GHC's own messages built (nix build .#haskell: 53 MB; 64 MB with lens and optics)
Agda Agda 2.8.0 on GHC's WebAssembly backend, one run per request, with part of the standard library goals, types and diagnostics from Agda itself built (nix build .#agda: 29 MB)
SQL SQLite 3.54.1 as WebAssembly (sql.js), a script run in a fresh in-memory database, each query's result a table SQLite's own parser, with the schema the script builds for hover and completion built (nix build .#sql: 0.33 MB)
Logic deduxit's ordinary-logic suite (Rust, WebAssembly): classical, intuitionistic and minimal, propositional and first-order; proofs as trees and step by step, countermodels, truth tables, tableaux deduxit's parse errors; hover and completion for connectives and fragments built (nix build .#logic: 2.1 MB)
Linear logic deduxit's linear suite: classical, intuitionistic, affine, Mix, cyclic, Lambek; proofs, proof nets, λ-terms the same built (nix build .#linear-logic: 2.1 MB)
Modal logic deduxit's modal suite, K to S5: derivations and Kripke countermodels the same built (nix build .#modal-logic: 2.1 MB)
λ-calculus deduxit's lambda suite: untyped, simply typed and System F terms, reduction, typing derivations, the terms of a type deduxit's parse and type errors built (nix build .#lambda: 2.1 MB)
Calculi deduxit's calculi given as rule files: natural deduction as trees and Fitch proofs, LK, LJ, LM, LL deduxit's parse errors built (nix build .#calculus: 2.1 MB)
Scheme Chibi-Scheme 0.12 (R7RS-small and its libraries) built to WebAssembly; a macro expanded at the cursor read errors and unbound names without running the program, hover and completion for R7RS built (nix build .#scheme: 0.6 MB)

Sizes are what a reader downloads from a host that compresses scripts, WebAssembly and JSON (brotli); data files are gzip, stored that way.

Using it on a site

In a flake built with flake-parts, import this flake's module (it imports the framework's) and choose languages:

{
  inputs.playgrounds.url = "github:playgroundkit/languages";
  # This flake's nixpkgs, so the language packages come from the binary cache (below).
  inputs.nixpkgs.follows = "playgrounds/nixpkgs";
  outputs = inputs: inputs.flake-parts.lib.mkFlake { inherit inputs; } {
    imports = [ inputs.playgrounds.flakeModules.default ];
    systems = [ "x86_64-linux" ];
    perSystem = { config, ... }: {
      playgrounds.languages.ocaml.enable = true;
      # Another engine of the same language, with a library of the site's own:
      playgrounds.languages.ocaml-optics = {
        engine = "ocaml";
        aliases = [ "optics" ];
        libraries = [ config.packages.optics ];
      };
    };
  };
}

packages.playgrounds is then the directory to serve, as the framework's README describes.

Binary cache. The public cache https://playgroundkit.cachix.org holds every language's package, built from main, so a site fetches them instead of building compilers for hours. A site hits it when its nixpkgs follows this flake's (as above) and it adds the cache to its Nix configuration, in its flake or in CI (cachix/cachix-action with name: playgroundkit, no token):

nixConfig = {
  extra-substituters = [ "https://playgroundkit.cachix.org" ];
  extra-trusted-public-keys = [ "playgroundkit.cachix.org-1:f5CGgy/b4sb3Yo56xjrkPcpCJVZ6ICglwuc8BZltxC4=" ];
};

A language with arguments of the site's own (libraries, sources) is built by the site, compilers included. The module only fills the framework's engine registry (playgrounds.engines) with the engines of this repository, so every option of playgrounds.languages.<name> is the framework's.

Every language has an engine, engines.<id> pkgs { … }, that takes id, name and aliases (the package under another name, which gives a site several engines of one language) and, where the language has them, libraries and sources:

  • engines.ocaml pkgs { libraries = [ … ]; sources = { mine = ./mine; }; } adds findlib libraries and a dune library of the site's own to the toplevel and to Merlin.
  • engines.haskell pkgs { libraries = hs: [ hs.lens ]; sources = { mine = ./mine; }; } adds Hackage packages (at nixpkgs' versions) and local cabal packages. Its native compiler of the same version, with the page's flags and file name, is passthru.native.
  • engines.koka pkgs { sources = { my = ./my; }; } and engines.effekt add modules by name, a file or a directory each.
  • The logic packages take a default fragment (engines.logic pkgs { fragment = "intuitionistic"; }, likewise linear-logic, modal-logic, lambda, calculus), which a cell overrides with a line % fragment: minimal.

The old names, lib.mkOcamlEngine and the like, are lib aliases of these engines. lib.ocamlCheck is OCaml's Check and QCheck as a findlib package.

Adding a language

docs/guide.md is the route: the framework's guide, then what a language in this repository touches. The new-language skill walks it.

Development

Needs Nix with flakes. direnv allow (or nix develop) enters the dev shell; menu lists the commands.

tests        # unit tests
lint         # Biome and TypeScript
check        # every check, the gate before a commit
e2e          # the browser tests, in three browsers

The framework is the flake input code-playgrounds and, as an npm package, the link .playgrounds (nix build code-playgrounds#npm --out-link .playgrounds, for the lock only). A package's workers are built with only the framework's code-playgrounds/protocol and /worker (packages.node-modules-workers; a check that needs the rest says full = true), so a framework change to its UI leaves every package, and its binary-cache entry, as it was (docs/plan.md L9; checks.language-inputs).

The flake has two locks: flake.lock (nixpkgs, flake-parts and the framework) and nix/inputs/flake.lock (every other input: OxCaml's opam repositories, Rust's toolchains, GHC's WebAssembly backend). nix flake update --flake ./nix/inputs moves the second; up updates both.

nix build .#site builds the site of examples (site/). cache-push pushes what a site fetches to the binary cache, after main moves (docs/plan.md L7), then checks that each path is there and names any that is not. It needs a Cachix token with write access, in CACHIX_AUTH_TOKEN or stored with cachix authtoken.

Version control is Jujutsu. docs/plan.md records this repository's decisions; AGENTS.md is for coding agents.

Licence

GPL-3.0-or-later. See LICENSE. Vendored files keep their own licences beside them.

About

Ready-made languages for code-playgrounds: OCaml, Koka, Haskell, Python, Rust, Rocq, Agda, SQL, Typst, the logics of deduxit and more, each a sandboxed language package.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages