feat: add sepby1 combinator

`sepby1` is a common reusable combinator in Haskell Parsec.

This adds `mpc_sepby1(mpc_fold_t f, mpc_parser_t *sep, mpc_parser_t *a)` according to Haskell's implementation:

https://hackage.haskell.org/package/parsec-3.1.16.1/docs/src/Text.Parsec.Combinator.html#sepBy1

Reuses existing `mpc_and`, `mpc_many`, and `mpcf_snd_free`.
This commit is contained in:
steve-chavez
2023-08-08 14:15:55 -05:00
parent 6912695fe5
commit c24e27f0b8
4 changed files with 29 additions and 0 deletions

View File

@@ -356,6 +356,14 @@ Runs `a` one or more times until it fails. Results are combined with fold functi
* * *
```c
mpc_parser_t *mpc_sepby1(mpc_fold_t f, mpc_parser_t *sep, mpc_parser_t *a);
```
Runs `a` one or more times, separated by `sep`. Results are combined with fold function `f`.
* * *
```c
mpc_parser_t *mpc_count(int n, mpc_fold_t f, mpc_parser_t *a, mpc_dtor_t da);
```