# peggy-tracks

> `peggy-tracks` creates railroad track diagrams of [peggy](https://peggyjs.org/) grammars.

Latest version **3.2.2** (published 2026-03-08) · MIT license · 0 weekly downloads

## Install

```sh
npm install peggy-tracks
pnpm add peggy-tracks
yarn add peggy-tracks
bun add peggy-tracks
```

Provides the command `peggy-tracks`.

## Health

**Score 60/100 (C)** — status: stable.

Positive: has types; esm support; no vulnerabilities; has provenance.

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 3.2.2 |
| Published | 2026-03-08 |
| First published | 2021-09-03 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=20 |
| Dependencies | 2 |
| Unpacked size | 76.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 4 |
| Author | Joe Hildebrand |
| Maintainers | hildjj |
| Keywords | railroad, diagram, grammar, peggy, peg.js |

## Links

- npm: https://www.npmjs.com/package/peggy-tracks
- Repository: https://github.com/peggyjs/peggy-tracks
- Homepage: https://github.com/peggyjs/peggy-tracks#readme
- Issues: https://github.com/peggyjs/peggy-tracks/issues
- npm.io page: https://npm.io/package/peggy-tracks

## Dependencies (2)

- [peggy](https://npm.io/package/peggy.md) ^5.1.0
- [commander](https://npm.io/package/commander.md) ^14.0.3

## Recent versions

- 3.2.2 (latest) — 2026-03-08
- 3.2.0 — 2024-02-29
- 3.1.0 — 2024-02-28
- 3.0.1 — 2024-02-26
- 3.0.0 — 2024-02-24
- 2.0.1 — 2023-11-10
- 1.1.0 — 2021-09-03
- 1.0.0 — 2021-09-03

## README

# peggy-tracks

`peggy-tracks` creates railroad track diagrams of [peggy](https://peggyjs.org/) grammars.

## Example

A quick example, generated with `peggy-tracks -s comment`:

![comments](./test/output/comment.svg)

Alternately, you can have rule references expanded using `-e`:

![comments-expanded](./test/output/test.svg)

## Installation

```bash
npm install -g peggy-tracks
```

## Command line

```txt
Usage: peggy-tracks [options] [input_file]

Options:
  -a,--action              Wrap actions in a box
  -c,--css [file name]     With no file name, outputs the default CSS.  With a
                           filename, substitutes the CSS in that file
  -d,--depth <number>      Maximum depth to expand references
  -e,--expand              Expand rule references without depth limit
  -o,--output <file name>  File in which to save output
  -q,--quote <string>      Quote character for literals (default: "\"")
  -s,--start <rule name>   Rule to start with
  -h, --help               display help for command
```

## More control

To change the look and feel of the output, you can output the default CSS that
will be placed in the SVG:

```sh
peggy-tracks -c > my.css
```

Edit `my.css`, and pass it back in to peggy-tracks:

```sh
peggy-tracks -c my.css --action -o action.svg -s number test.peggy
```

Generates this:

![comments-expanded](./test/output/action.svg)

Note that the `--action` flag has created extra boxes around parts of the
grammar, that when moused over show the code that will be executed when the
fragment matches.

## API

Only supports module-style:

```js
import {tracks, defaultCSS} from "peggy-tracks";

const diagram = tracks({
  // "text" is the only required option
  text: `
foo = bar*
bar = n:[0-9] { return parseInt(n) }
`,
  start: "bar",
  action: true,
  expand: false,
  parserOptions: {
    grammarSource: "filename"
  },
});

console.log(diagram.toStandalone(`
/* Optional: Full CSS desired.  If none specified, uses defaultCSS */
svg {
  background-color: hsl(30,20%,95%);
}
...
`));
```

[![Tests](https://github.com/peggyjs/peggy-tracks/actions/workflows/node.js.yml/badge.svg)](https://github.com/peggyjs/peggy-tracks/actions/workflows/node.js.yml)
[![codecov](https://codecov.io/gh/peggyjs/peggy-tracks/branch/main/graph/badge.svg?token=KX7ED6FH85)](https://codecov.io/gh/peggyjs/peggy-tracks)

---
_Source: https://npm.io/package/peggy-tracks · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
