https://github.com/disnet/parser-lang
A parser combinator library with declarative superpowers
https://github.com/disnet/parser-lang
javascript parser-combinator parser-combinators parsing template-literal template-literals
Last synced: about 1 month ago
JSON representation
A parser combinator library with declarative superpowers
- Host: GitHub
- URL: https://github.com/disnet/parser-lang
- Owner: disnet
- Created: 2019-05-19T18:58:50.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2022-03-24T04:10:35.000Z (about 3 years ago)
- Last Synced: 2025-03-18T11:12:28.044Z (about 1 month ago)
- Topics: javascript, parser-combinator, parser-combinators, parsing, template-literal, template-literals
- Language: JavaScript
- Homepage:
- Size: 370 KB
- Stars: 27
- Watchers: 4
- Forks: 1
- Open Issues: 8
-
Metadata Files:
- Readme: readme.md
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
[](https://badge.fury.io/js/parser-lang) [](https://travis-ci.org/disnet/parser-lang) [](code-of-conduct.md)
# ParserLang
ParserLang is parser combinator library. It lets you make parsers by combining other parsers.
Its primary superpower is the ability to define parsers declaratively with template literals:
```js
import { lang } from 'parser-lang';let { calc } = lang`
num = /[0-9]+/ > ${ch => parseInt(ch, 10)};addExpr = num '+' multExpr > ${([left, op, right]) => left + right}
| num ;multExpr = addExpr '*' multExpr > ${([left, op, right]) => left * right}
| addExpr ;
calc = multExpr ;
`;calc.tryParse('1+1*2');
// 3
```It's monadic and stuff but don't get too hung up on that. It tries to be very friendly.
## Installing
```sh
npm install parser-lang
```## Documentation
- [Tutorial](./docs/tutorial.md)
- [API Reference](./docs/api-reference.md)## Related Projects/Papers
- [Parsimmon](https://github.com/jneen/parsimmon) - a JavaScript parser combinator library. ParserLang is heavily inspired by Parsimmon. Parsimmon is more coupled to parsing strings (ParserLang uses the [Context protocol](./docs/api-reference.md#context) to support a variety of input types) but also supports a wider variety of JavaScript runtimes.
- [Parsec](http://hackage.haskell.org/package/parsec) - a Haskell parser combinator library
- [Monadic Parser Combinators](http://www.cs.nott.ac.uk/~pszgmh/monparsing.pdf) - one of the seminal papers describing parser combinators