<commit_before># loquat
[![Build Status](https://travis-ci.com/susisu/loquat.svg?branch=master)](https://travis-ci.com/susisu/loquat)

Monadic parser combinators for JavScript, inspired by [Parsec](https://github.com/haskell/parsec).

``` javascript
import * as lq from "@loquat/simple";

const nat = lq.digit.manyChars1().map(str => parseInt(str, 10));
const plus = lq.char("+");
const expr =
  nat.bind(a =>
    plus.and(
      nat.map(b =>
        a + b
      )
    )
  );

const res = expr.parse("", "14+28"); // { success: true, value: 42 }
```

## Packages
If you are not familiar with loquat, or you are using TypeScript, `@loquat/simple` is recommended.

- [simple](https://github.com/susisu/loquat/tree/master/packages/simple)

For a more flexible and extensible framework, use `@loquat/framework`.

- [framework](https://github.com/susisu/loquat/tree/master/packages/framework)

The core features and extensions are provided as separate packages.

- [core](https://github.com/susisu/loquat/tree/master/packages/core)
- [prim](https://github.com/susisu/loquat/tree/master/packages/prim)
- [char](https://github.com/susisu/loquat/tree/master/packages/char)
- [combinators](https://github.com/susisu/loquat/tree/master/packages/combinators)<commit_msg>doc: demonstrate `choice` in synopsis<commit_after># loquat
[![Build Status](https://travis-ci.com/susisu/loquat.svg?branch=master)](https://travis-ci.com/susisu/loquat)

Monadic parser combinators for JavScript, inspired by [Parsec](https://github.com/haskell/parsec).

``` javascript
import * as lq from "@loquat/simple";

const nat = lq.digit.manyChars1().map(str => parseInt(str, 10));
const op = lq.choice([
  lq.char("+").return((a, b) => a + b),
  lq.char("-").return((a, b) => a - b)
]);
const expr =
  nat.bind(a =>
    op.bind(f =>
      nat.map(b =>
        f(a, b)
      )
    )
  );

const res = expr.parse("", "14+28"); // { success: true, value: 42 }
```

## Packages
If you are not familiar with loquat, or you are using TypeScript, `@loquat/simple` is recommended.

- [simple](https://github.com/susisu/loquat/tree/master/packages/simple)

For a more flexible and extensible framework, use `@loquat/framework`.

- [framework](https://github.com/susisu/loquat/tree/master/packages/framework)

The core features and extensions are provided as separate packages.

- [core](https://github.com/susisu/loquat/tree/master/packages/core)
- [prim](https://github.com/susisu/loquat/tree/master/packages/prim)
- [char](https://github.com/susisu/loquat/tree/master/packages/char)
- [combinators](https://github.com/susisu/loquat/tree/master/packages/combinators)
{'fraction_non_alphanumeric': 0.1785986290936786, 'fraction_numerical': 0.006854531607006854, 'mean_word_length': 4.130859375, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 12, 'https://': 18, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7401983', 'n_tokens_mistral': 989, 'n_tokens_neox': 928, 'n_words': 175}