Updated testing framework

This commit is contained in:
Daniel Holden
2013-09-23 22:41:58 +01:00
parent 4daf2527a0
commit 48812155a1
10 changed files with 1429 additions and 219 deletions

View File

@@ -3,18 +3,24 @@ Micro Parser Combinators
_mpc_ is a lightweight Parser Combinator library for C.
The current main alternative is a branch of (https://github.com/wbhart/Cesium3)[Cesium3].
Features & Advantages
---------------------
Features
--------
* Full Type Generic Parser Combinator
* Error Message Support
* Regular Expression Support
* Parser Grammar Support
* Works for Generic Types
* AST Extension
* Single source & header files
* Packaged with AST generator
* Easy to including in source
* Written in clean ANSI C
Alternatives
------------
The current main alternative is a branch of (https://github.com/wbhart/Cesium3)[Cesium3].
The main advantages of _mpc_ over this are:
* Works for Generic Types
* Doesn't rely on Boehm-Demers-Weiser Garbage Collection
* Doesn't use `setjmp` and `longjmp` for errors
* Doesn't pollute namespace
@@ -24,51 +30,8 @@ Example
```c
mpc_val_t* combine_maths(int n, mpc_val_t** xs) {
int** vs = (int**)xs;
if (*vs[1] == '*') { *vs[0] *= *vs[2]; }
if (*vs[1] == '/') { *vs[0] /= *vs[2]; }
if (*vs[1] == '+') { *vs[0] += *vs[2]; }
if (*vs[1] == '-') { *vs[0] -= *vs[2]; }
free(vs[1]);
free(vs[2]);
return vs[0];
}
int main(int argc, char** argv) {
mpc_parser_t* Expr = mpc_new();
mpc_parser_t* Factor = mpc_new();
mpc_parser_t* Term = mpc_new();
mpc_parser_t* Maths = mpc_new();
mpc_define(Expr,
mpc_pc("cmaths ( fact ['*' | '/'] fact ) | fact",
combine_maths, Factor, free, Factor, free, Factor),
);
mpc_define(Factor,
mpc_pc("cmaths ( term ['+' | '-'] term ) | term",
combine_maths, Term, free, Term, free, Term),
);
mpc_define(Term,
mpc_pc("num | snd ('(' expr ')')",
mpc_int(), mpcf_asnd_free, Expr, free)
);
mpc_define(Maths, mpc_ends(Expr, free));
mpc_delete(Expr);
mpc_delete(Factor);
mpc_delete(Term);
mpc_delete(Maths);
}
```
Parsers
@@ -90,6 +53,17 @@ Combinator Grammars
Abstract Syntax Tree
--------------------
If you want to do all the data processing after the parsing stage _mpc_ comes packaged with a basic AST type which makes the grammar declaration much cleaner as you don't have to pass around destructors and fold functions. All these functions reside under `mpca_*`.
This also allows for the use of parser grammars that can be declared directly in C strings similarly to regular expressions.
```c
```
Reference
---------