Choo Choo is a JavaScript library that generates visual railroad diagrams from Extended Backus-Naur Form (EBNF) grammars. Railroad diagrams provide an intuitive, graphical representation of formal language syntax rules, making it easier to understand and document complex grammars.
The library partially supports the ISO/IEC 14977 EBNF syntax and includes features like:
- Optional sequences
[ ... ]
- Repetitions
{ ... }
- Grouping
( ... )
- Specials
? ... ?
- Choices
|
- Sequences
,
- Terminal strings
" ... "
- Comment blocks
(* ... *)
Check docs/ebnf.ebnf for specific details of the supported features.
Note
I started writing this library while studying the Parser from scratch course from @dmitrysoshnikov, so you may find several similarities with his approach to recursive descent parser. Following his course[s] will definitely help you understanding this codebase.
Warning
Until this library is considered battle ready, it won't be uploaded to any package repository. Also, no releases will be created until that point. Use it at your discretion and remember that it's an unfinished piece of software shared without any warrant.
git clone https://github.com/estudio-hawara/choo-choo
cd choo-choo
pnpm install
Run the unit test suite to verify functionality:
pnpm run test
Generate a test coverage report to ensure code quality:
pnpm run coverage
# or with full details
pnpm run coverage --verbose
Open an interative test session from Node:
# node
const Choo = require('./dist/cjs');
const parser = new Choo.Parser;
parser.parse('identifier = "a";');
Build both ESM and CommonJS versions of the library:
pnpm run build