Finished attr_bool, cleaned up header a little.
This commit is contained in:
parent
3d5e9399c4
commit
b10a3d8ae9
2 changed files with 175 additions and 52 deletions
22
src/hammer.c
22
src/hammer.c
|
|
@ -759,15 +759,31 @@ parser_t* indirect() {
|
|||
}
|
||||
|
||||
typedef struct {
|
||||
const parser_t *p;
|
||||
predicate_t pred;
|
||||
} attr_bool_t;
|
||||
|
||||
static parse_result_t* parse_attr_bool(void *env, parse_state_t *state) {
|
||||
|
||||
|
||||
attr_bool_t *a = (attr_bool_t*)env;
|
||||
parse_result_t *res = do_parse(a->p, state);
|
||||
if (res) {
|
||||
if (a->pred(res))
|
||||
return res;
|
||||
else
|
||||
return NULL;
|
||||
} else
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const parser_t* attr_bool(const parser_t* p, attr_bool_t a) { return &unimplemented; }
|
||||
const parser_t* attr_bool(const parser_t* p, predicate_t pred) {
|
||||
parser_t *res = g_new(parser_t, 1);
|
||||
res->fn = parse_attr_bool;
|
||||
attr_bool_t *env = g_new(attr_bool_t, 1);
|
||||
env->p = p;
|
||||
env->pred = pred;
|
||||
res->env = (void*)env;
|
||||
return res;
|
||||
}
|
||||
|
||||
const parser_t* and(const parser_t* p) { return &unimplemented; }
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue