Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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: 3 months 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 (over 5 years ago)
- Default Branch: master
- Last Pushed: 2022-03-24T04:10:35.000Z (almost 3 years ago)
- Last Synced: 2024-10-14T22:18:53.873Z (3 months ago)
- Topics: javascript, parser-combinator, parser-combinators, parsing, template-literal, template-literals
- Language: JavaScript
- Homepage:
- Size: 370 KB
- Stars: 27
- Watchers: 5
- Forks: 1
- Open Issues: 8
-
Metadata Files:
- Readme: readme.md
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
[![npm version](https://badge.fury.io/js/parser-lang.svg)](https://badge.fury.io/js/parser-lang) [![Build Status](https://travis-ci.org/disnet/parser-lang.svg?branch=master)](https://travis-ci.org/disnet/parser-lang) [![Contributor Covenant](https://img.shields.io/badge/Contributor%20Covenant-v1.4%20adopted-ff69b4.svg)](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