Finished action. On to testing.
This commit is contained in:
parent
b10a3d8ae9
commit
642df1f238
2 changed files with 25 additions and 1 deletions
24
src/hammer.c
24
src/hammer.c
|
|
@ -297,7 +297,29 @@ const parser_t* whitespace(const parser_t* p) {
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
const parser_t* action(const parser_t* p, const action_t a) { return &unimplemented; }
|
typedef struct {
|
||||||
|
const parser_t *p;
|
||||||
|
action_t action;
|
||||||
|
} parse_action_t;
|
||||||
|
|
||||||
|
static parse_result_t* parse_action(void *env, parse_state_t *state) {
|
||||||
|
parse_action_t *a = (parse_action_t*)env;
|
||||||
|
if (a->p && a->action) {
|
||||||
|
parse_result_t *ret = a->action(do_parse(a->p, state));
|
||||||
|
return ret;
|
||||||
|
} else // either the parser's missing or the action's missing
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
const parser_t* action(const parser_t* p, const action_t a) {
|
||||||
|
parser_t *res = g_new(parser_t, 1);
|
||||||
|
res->fn = parse_action;
|
||||||
|
parse_action_t *env = g_new(parse_action_t, 1);
|
||||||
|
env->p = p;
|
||||||
|
env->action = a;
|
||||||
|
res->env = (void*)env;
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
static parse_result_t* parse_charset(void *env, parse_state_t *state) {
|
static parse_result_t* parse_charset(void *env, parse_state_t *state) {
|
||||||
uint8_t in = read_bits(&state->input_stream, 8, false);
|
uint8_t in = read_bits(&state->input_stream, 8, false);
|
||||||
|
|
|
||||||
|
|
@ -36,6 +36,7 @@ typedef enum token_type {
|
||||||
TT_SINT,
|
TT_SINT,
|
||||||
TT_UINT,
|
TT_UINT,
|
||||||
TT_SEQUENCE,
|
TT_SEQUENCE,
|
||||||
|
TT_USER = 64,
|
||||||
TT_ERR,
|
TT_ERR,
|
||||||
TT_MAX
|
TT_MAX
|
||||||
} token_type_t;
|
} token_type_t;
|
||||||
|
|
@ -59,6 +60,7 @@ typedef struct parsed_token {
|
||||||
double dbl;
|
double dbl;
|
||||||
float flt;
|
float flt;
|
||||||
counted_array_t *seq; // a sequence of parsed_token_t's
|
counted_array_t *seq; // a sequence of parsed_token_t's
|
||||||
|
void *user;
|
||||||
};
|
};
|
||||||
size_t index;
|
size_t index;
|
||||||
char bit_offset;
|
char bit_offset;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue