Add mpc_check and mpc_check_with combinators.

This commit is contained in:
Jerome M. BERGER
2018-03-23 10:50:09 +01:00
parent ca1404cabb
commit 6ac5594c4f
3 changed files with 147 additions and 39 deletions

View File

@@ -311,6 +311,15 @@ Returns a parser that applies function `f` (optionality taking extra input `x`)
* * *
```c
mpc_parser_t *mpc_check(mpc_parser_t *a, mpc_check_t f, const char *e);
mpc_parser_t *mpc_check_with(mpc_parser_t *a, mpc_check_with_t f, void *x, const char *e);
```
Returns a parser that applies function `f` (optionally taking extra input `x`) to the result of parser `a`. If `f` returns non-zero, then the parser succeeds and returns the value of `a` (possibly modified by `f`). If `f` returns zero, then the parser fails with message `e`.
* * *
```c
mpc_parser_t *mpc_not(mpc_parser_t *a, mpc_dtor_t da);
mpc_parser_t *mpc_not_lift(mpc_parser_t *a, mpc_dtor_t da, mpc_ctor_t lf);
@@ -410,6 +419,15 @@ This takes in some pointer to data and outputs some new or modified pointer to d
* * *
```c
typedef int(*mpc_check_t)(mpc_val_t**);
typedef int(*mpc_check_with_t)(mpc_val_t**,void*);
```
This takes in some pointer to data and outputs 0 if parsing should stop with an error. Additionally, this may change or free the input data. The `check_with` variation takes in an extra pointer to some data such as global state.
* * *
```c
typedef mpc_val_t*(*mpc_fold_t)(int,mpc_val_t**);
```