Peggy
Parser generator for JavaScript using parsing expression grammars (PEG)
Repository Health
Technical Analysis
Peggy is a parser generator for JavaScript that compiles a parsing expression grammar (PEG) into a fast, standalone parser with excellent built-in error reporting. It is the actively maintained successor to PEG.js, offering near drop-in API compatibility for anyone migrating.
Peggy integrates lexical and syntactic analysis into a single grammar, letting developers process complex data formats or design custom languages — building interpreters, compilers, config-file parsers, and other language tools — without hand-writing a tokenizer and parser separately. It’s usable from the command line, as a JavaScript/TypeScript API, or directly in the browser.
What You Get
- A
peggyCLI (bin/peggy.js) that compiles.peggy/.pegjsgrammar files into standalone parser modules - A JavaScript/TypeScript API (
peggy.generate()) for compiling grammars programmatically at build time or runtime - PEG (parsing expression grammar) semantics — more expressive and predictable than traditional LL(k)/LR(k) parser generators
- Source map support for debugging generated parsers back to the original grammar
- A browser-ready bundle (
browser/peggy.min.js) for client-side grammar compilation
Common Use Cases
- Parsing custom domain-specific languages (DSLs), config formats, or query languages in a Node.js or browser app
- Replacing hand-rolled regex-based parsers with a maintainable, testable formal grammar
- Migrating existing PEG.js-based parsers to actively maintained tooling with minimal code changes
- Building compilers, interpreters, or linters that need a robust parsing front-end with rich error messages
Under The Hood
Architecture: Peggy’s own grammar parser is bootstrapped from a src/parser.pegjs grammar file (compiled by Peggy itself) into lib/parser.js, and the lib/compiler/ directory implements a multi-pass compiler pipeline that walks the parsed grammar AST, performs semantic checks (via grammar-error.js for structured error reporting with source locations), and emits generated parser JavaScript. The CLI (bin/peggy.js) and the public peg.js API both funnel into this shared compiler core, so command-line and programmatic usage produce identical output. Tech Stack: Built with a pnpm workspace, TypeScript type declarations (peg.d.ts) ship alongside the JS output via tsup, and the build pipeline (npm run build) chains grammar self-compilation, TS type generation, docs, and a browser bundle target (browser/peggy.min.js) distributed via unpkg/jsDelivr. Code Quality: The test suite is large relative to the implementation — roughly 12,000 lines of tests (test/api, test/behavior, test/cli, test/unit) against about 9,900 lines of lib/ source — covering the CLI, the generate API, and the behavior of generated parsers themselves; CI runs via GitHub Actions with Codecov coverage tracking. API Design: peggy.generate(grammar, options) is a single clear entry point returning either a parser module or generated source, and the CLI mirrors the same option surface, so switching between build-time codegen and runtime compilation requires no relearning — a deliberate design carried over from PEG.js to ease migration.
Used by 5 apps in this directory
Actual
Invoicing Finance
Local-first personal finance with envelope budgeting, end-to-end encryption, and multi-device sync — no subscription required.
Kibana
Analytics · Monitoring
Your open source window into the Elastic Stack — query, visualize, and act on data stored in Elasticsearch with real-time dashboards, AI-assisted search, and automated alerting.
Lightdash
Analytics · Data Engineering
The open-source Looker alternative that turns your dbt project's metrics and dimensions into governed, self-serve charts and dashboards — no license key required.
Rocket.Chat
Team Chat
The secure, self-hosted team communications platform for organizations that cannot compromise on data sovereignty.
Sentry
Security · Developer Tools · Monitoring
Developer-first error tracking and performance monitoring platform with AI-powered root-cause analysis across 20+ languages and frameworks.