peberminta is a simple, transparent, and highly generic parser combinator toolkit for TypeScript/JavaScript, currently at version 0.10.0 and appearing actively maintained. Its core design principle is to be agnostic to token types, options, and output, making it suitable for 'weird things with parsers' where traditional string-based parsers fall short. It is lightweight with zero dependencies and provides a comprehensive set of building blocks, enabling users to easily define custom parsing logic. A key differentiator is its emphasis on transparency, allowing full access to the parser state, and its opinionated stance on input, accepting only fixed arrays of tokens rather than streams. It does not include a built-in lexer, requiring users to supply their own. The library prioritizes practicality and clear typing, offering a robust foundation for complex parsing tasks without imposing strict constraints on input structures.
npm install pebermintaVerified import paths — ran on the pinned version, not inferred.
Demonstrates defining and using basic parser combinators to parse a hexadecimal color string, including tokenization and result handling.
Ensure your input is fully tokenized into an array before passing it to any parser. If you need streaming capabilities, consider a different library or implement an external streaming tokenization layer.
Refer to the `CHANGELOG.md` (linked in README) with each update and thoroughly test your parsing logic after upgrading to new minor versions.
Implement a custom tokenizer or use a separate lexing library (like `leac` mentioned in the README) to preprocess your input into an array of tokens before passing it to `peberminta` parsers.
Prefer using `import` statements in projects configured for ESM. If strictly in a CommonJS environment, ensure Node.js is configured to handle ESM imports, or consider transpilation.
Convert your project or the specific file to an ES Module by adding `"type": "module"` to your `package.json` or by changing the file extension to `.mjs`. Then use `import * as p from 'peberminta';`.
Ensure that the `tokens` array in your `PState` matches the expected token type of your parser. If your parser expects `char` tokens (strings of length 1), make sure your `tokens` array contains `string[]`. Explicitly typing `PState<YourTokenType>` can help resolve ambiguities.
Always check the `type` property of the `ParseResult` object. Use a conditional check like `if (result.type === 'Ok') { /* access result.value */ } else { /* handle error */ }`.Review the documentation and type definitions for the specific combinator function. Ensure all required arguments are present and their types (especially the generic `Parser<TOutput, TToken>`) match the expected signature. For example, `p.seq` expects an array of parsers.
No dependency data recorded yet.