Peggy

Parser generator for JavaScript using parsing expression grammars (PEG)

Tool
npm
v5.1.0
1,180 stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum. How we score it →
50 /100 Fair
Development Activity 4
Maintenance 32
Community 64
Maturity 60
Momentum 40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation. How we score it →
72 /100 Good
Architecture 75
Code Quality 78
Innovation 68
Learning Curve 65

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 peggy CLI (bin/peggy.js) that compiles .peggy/.pegjs grammar 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

TypeScript
95%
MIT

Actual

Invoicing Finance

29,186

Local-first personal finance with envelope budgeting, end-to-end encryption, and multi-device sync — no subscription required.

View details
93
Repo Health
85
Technical
73
Dependency
Built with
TypeScript 95%
Updated 4 days ago
TypeScript
98%
Other

Kibana

Analytics · Monitoring

21,301

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.

View details
98
Repo Health
87
Technical
63
Dependency
Built with
TypeScript 98%
Updated 4 days ago
TypeScript
97%
Other

Lightdash

Analytics · Data Engineering

6,166

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.

View details
93
Repo Health
84
Technical
64
Dependency
Built with
TypeScript 97%
Updated 4 days ago
TypeScript
97%
Other

Rocket.Chat

Team Chat

46,180

The secure, self-hosted team communications platform for organizations that cannot compromise on data sovereignty.

View details
96
Repo Health
79
Technical
66
Dependency
Built with
TypeScript 97%
Updated 4 days ago
Python
57%
Other

Sentry

Analytics · Developer Tools · Monitoring

44,862

Developer-first error tracking and performance monitoring platform with AI-powered root-cause analysis across 20+ languages and frameworks.

View details
95
Repo Health
80
Technical
69
Dependency
Built with
Python 57%
TypeScript 41%
Updated 4 days ago

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers