prsc is a compact parser combinators library for both JavaScript and TypeScript, heavily influenced by the Rust parsing library `nom`. It enables developers to construct complex parsers from simpler ones for string inputs, offering primitive parsers like `token` and combinators such as `map`, `filter`, `then`, and `star`. The library ships with ES6 modules (`.mjs`), UMD bundles (`.js`), and comprehensive TypeScript typings, facilitating its use across various environments, including Node.js and browsers. The current stable version is 4.0.0. Releases are somewhat frequent, with minor features and bug fixes rolled out between major versions, indicating active maintenance and continuous improvement in performance and usability for writing fast, reliable parsers.
npm install prscVerified import paths — ran on the pinned version, not inferred.
This example demonstrates building a parser for a simple arithmetic language supporting addition and multiplication, showcasing primitive parsers, combinators like `map`, `then`, `star`, and handling recursive grammar rules.
Ensure you are using standard ESM imports (`import ... from 'prsc'`) in Node.js and modern browser environments. If you rely on direct paths to the UMD bundle for CJS, check the new file names in `dist/`.
If you need the matched string value from `range`, combine it with the `recognize` combinator: `map(recognize(range(...)), value => ...)`.
Wrap the recursive parser call in a function (e.g., `const parser = (input, offset) => actualParser(input, offset);`) and pass this function for the recursive part.
Always ensure that parsers wrapped by `star` or `plus` consume at least one unit of input if they succeed. If a parser fails to consume input, it should return an `error` result.
For TypeScript, use `import type { Parser } from 'prsc';`. For JavaScript, you likely don't need to import `Parser` itself as it's a type, not a runtime class.Ensure you are using named ESM imports: `import { map, then } from 'prsc';`. Avoid `const prsc = require('prsc'); prsc.map;` for modern versions.If you need the value, wrap `range` with `recognize`: `const valueParser = map(recognize(range('a', 'z')), str => str);`.No dependency data recorded yet.