Finished action. On to testing.

This commit is contained in:
Meredith L. Patterson 2012-05-18 12:35:40 +02:00
parent b10a3d8ae9
commit 642df1f238
2 changed files with 25 additions and 1 deletions

View file

@ -297,7 +297,29 @@ const parser_t* whitespace(const parser_t* p) {
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) {
uint8_t in = read_bits(&state->input_stream, 8, false);

View file

@ -36,6 +36,7 @@ typedef enum token_type {
TT_SINT,
TT_UINT,
TT_SEQUENCE,
TT_USER = 64,
TT_ERR,
TT_MAX
} token_type_t;
@ -59,6 +60,7 @@ typedef struct parsed_token {
double dbl;
float flt;
counted_array_t *seq; // a sequence of parsed_token_t's
void *user;
};
size_t index;
char bit_offset;