`pratt-parser` is a JavaScript/TypeScript library that implements a Top Down Operator Precedence (TDOP) parser, commonly known as a Pratt parser. It draws inspiration from both the general TDOP concept and specific implementations like Douglas Crockford's TDOP work. The library enables developers to construct custom parsers for various syntaxes, such as mathematical expressions or domain-specific languages, by defining tokens, null denotation (nud) functions for prefix operators, and left denotation (led) functions for infix operators, along with their respective precedences. The current stable version is 12.0.6, indicating active maintenance and frequent, albeit minor, updates. Major versions introduce breaking changes primarily related to API refinement and Node.js compatibility. It provides comprehensive TypeScript type definitions, making it suitable for modern TypeScript projects seeking a robust and extensible parsing solution.
npm install pratt-parserVerified import paths — ran on the pinned version, not inferred.
This code demonstrates how to define a basic arithmetic grammar using `pratt-parser`, including custom tokens, prefix, and infix operators, then parses and evaluates an example expression.
Update all calls from `parserInstance.parseString(input)` to `parserInstance.parse(input)`.
Upgrade your Node.js installation to version 22.15.0 or newer. Tools like `nvm` (Node Version Manager) can simplify switching between Node.js versions.
Ensure your project's `package.json` includes `"type": "module"` for ESM compatibility, and use `import` statements. If a mixed CommonJS/ESM setup is unavoidable, use dynamic `import('pratt-parser')` within CommonJS.Change your import statement to `import { Parser } from 'pratt-parser';` and ensure your project's `package.json` has `"type": "module"` set for your entry files, or that you are in an ESM context.Replace all occurrences of `parserInstance.parseString(source)` with `parserInstance.parse(source)`.
Upgrade your Node.js environment to version 22.15.0 or newer. You might need to use `nvm install 22` or update your Node.js distribution.
No dependency data recorded yet.