Peggy is a robust, open-source parser generator for JavaScript that serves as the successor to the popular PEG.js project. It enables developers to define grammars using a simple and expressive syntax based on parsing expression grammar (PEG) formalism, which is more powerful than traditional LL(k) and LR(k) parsers. Peggy integrates both lexical and syntactical analysis and produces fast parsers with excellent error reporting capabilities. The current stable version is 5.1.0, with regular patch and minor releases, and major versions released less frequently. Key differentiators include its superior error reporting, integration of lexical and syntactical analysis, and being usable across various environments: browsers (via an online tool), command line, and as a JavaScript API. It also provides source map support and ships with TypeScript definitions, making it well-suited for modern JavaScript and TypeScript development workflows. It requires Node.js version 20 or higher.
npm install peggyVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to define a simple arithmetic grammar, generate a parser using `peggy.generate`, and then use the generated parser to process an input string. It also illustrates how to catch and handle `SyntaxError` instances thrown by the parser.
Transpile your generated parser code using Babel or a similar tool if targeting environments older than ES2020, or update your runtime to Node.js >=20.
Replace all instances of `pegjs` with `peggy` in your code and build scripts.
Review your build pipeline and any polyfill assumptions if you encounter unexpected runtime issues after upgrading to v5.0.6 or later, especially if you use Peggy programmatically.
Ensure your development and production environments are running Node.js version 20 or newer.
Upgrade to the latest `5.x.x` patch release to benefit from TypeScript definition fixes, such as `5.1.0` or newer.
Globally replace `pegjs` with `peggy` in your project's source code and configuration files.
For Peggy imports, use `import ... from 'peggy';`. For generated parsers in v5+, ensure your project is configured for ESM or transpile the output if targeting an older CJS environment or browser.
Update Peggy to the latest `5.x.x` patch version (e.g., 5.1.0) to get the corrected TypeScript definitions.
Ensure `text()` is called within a rule's action block and that the rule has successfully matched some input. Verify that the `text()` function is correctly defined and accessible in the context of your generated parser's actions.
No dependency data recorded yet.