Refactor ALL the things!
This commit is contained in:
parent
6a2f10df0c
commit
f2def8fa05
28 changed files with 930 additions and 855 deletions
32
src/parsers/attr_bool.c
Normal file
32
src/parsers/attr_bool.c
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
#include "parser_internal.h"
|
||||
|
||||
typedef struct {
|
||||
const HParser *p;
|
||||
HPredicate pred;
|
||||
} HAttrBool;
|
||||
|
||||
static HParseResult* parse_attr_bool(void *env, HParseState *state) {
|
||||
HAttrBool *a = (HAttrBool*)env;
|
||||
HParseResult *res = h_do_parse(a->p, state);
|
||||
if (res && res->ast) {
|
||||
if (a->pred(res))
|
||||
return res;
|
||||
else
|
||||
return NULL;
|
||||
} else
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static const HParserVtable attr_bool_vt = {
|
||||
.parse = parse_attr_bool,
|
||||
};
|
||||
|
||||
const HParser* h_attr_bool(const HParser* p, HPredicate pred) {
|
||||
HParser *res = g_new(HParser, 1);
|
||||
res->vtable = &attr_bool_vt;
|
||||
HAttrBool *env = g_new(HAttrBool, 1);
|
||||
env->p = p;
|
||||
env->pred = pred;
|
||||
res->env = (void*)env;
|
||||
return res;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue