Skip to content

Choo Choo

Choo Choo is a TypeScript library that turns a grammar into an SVG railroad diagram. It supports three grammar formalisms (EBNF, ANTLR4, PEG) and four framework bindings (vanilla JS, React, Vue, Astro). Rendering is pure — a tree in, an SVG string out — so the renderer runs anywhere JavaScript does.

Quick start

The simplest path is the custom element from @choo-choo/vanilla:

Terminal window
pnpm add @choo-choo/vanilla @choo-choo/parser-ebnf
<script type="module">
import "@choo-choo/vanilla";
import "@choo-choo/vanilla/styles.css";
import { ebnfParser } from "@choo-choo/parser-ebnf";
const el = document.querySelector("choo-choo");
el.parser = ebnfParser;
</script>
<choo-choo compose="grouped">
digit = ? 0-9 ?;
number = digit , { digit };
</choo-choo>

The three layers

LayerModuleDescription
CoreArchitectureChoo Choo architecture
CoreIntermediate representationRepresentation for manual renders
CoreRendererSVG renderer
CoreManual builderManual builder
ParsersEBNFParser for EBNF grammars
ParsersANTLRParser for ANTLR grammars
ParsersPEGParser for PEG grammars
BindingsVanillaBindings for Vanilla
BindingsReactBindings for React
BindingsVueBindings for Vie
BindingsAstroBindings for Astro