action() works. Will finish DNS tomorrow.
This commit is contained in:
parent
e2af24fe80
commit
f921ece53f
3 changed files with 33 additions and 13 deletions
40
src/hammer.c
40
src/hammer.c
|
|
@ -344,8 +344,10 @@ typedef struct {
|
||||||
static parse_result_t* parse_action(void *env, parse_state_t *state) {
|
static parse_result_t* parse_action(void *env, parse_state_t *state) {
|
||||||
parse_action_t *a = (parse_action_t*)env;
|
parse_action_t *a = (parse_action_t*)env;
|
||||||
if (a->p && a->action) {
|
if (a->p && a->action) {
|
||||||
parsed_token_t *tok = a->action(do_parse(a->p, state));
|
parse_result_t *tmp = do_parse(a->p, state);
|
||||||
return make_result(state, tok);
|
//parsed_token_t *tok = a->action(do_parse(a->p, state));
|
||||||
|
const parsed_token_t *tok = a->action(tmp);
|
||||||
|
return make_result(state, (parsed_token_t*)tok);
|
||||||
} else // either the parser's missing or the action's missing
|
} else // either the parser's missing or the action's missing
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
@ -1046,21 +1048,35 @@ static void test_whitespace(void) {
|
||||||
|
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
|
|
||||||
parsed_token_t* upcase(parse_result_t *p) {
|
const parsed_token_t* upcase(parse_result_t *p) {
|
||||||
switch(p->ast->token_type) {
|
switch(p->ast->token_type) {
|
||||||
case TT_SEQUENCE:
|
case TT_SEQUENCE:
|
||||||
for (size_t i=0; i<p->ast->seq->used; ++i) {
|
{
|
||||||
upcase((parse_result_t*)p->ast->seq->elements[i]);
|
parsed_token_t *ret = a_new_(p->arena, parsed_token_t, 1);
|
||||||
return (parsed_token_t*)p->ast;
|
counted_array_t *seq = carray_new_sized(p->arena, p->ast->seq->used);
|
||||||
|
ret->token_type = TT_SEQUENCE;
|
||||||
|
for (size_t i=0; i<p->ast->seq->used; ++i) {
|
||||||
|
if (TT_UINT == ((parsed_token_t*)p->ast->seq->elements[i])->token_type) {
|
||||||
|
parsed_token_t *tmp = a_new_(p->arena, parsed_token_t, 1);
|
||||||
|
tmp->token_type = TT_UINT;
|
||||||
|
tmp->uint = toupper(((parsed_token_t*)p->ast->seq->elements[i])->uint);
|
||||||
|
carray_append(seq, tmp);
|
||||||
|
} else {
|
||||||
|
carray_append(seq, p->ast->seq->elements[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ret->seq = seq;
|
||||||
|
return (const parsed_token_t*)ret;
|
||||||
}
|
}
|
||||||
case TT_UINT:
|
case TT_UINT:
|
||||||
{
|
{
|
||||||
parsed_token_t *ret = (parsed_token_t*)p->ast;
|
parsed_token_t *ret = a_new_(p->arena, parsed_token_t, 1);
|
||||||
ret->uint = toupper(ret->uint);
|
ret->token_type = TT_UINT;
|
||||||
return ret;
|
ret->uint = toupper(p->ast->uint);
|
||||||
|
return (const parsed_token_t*)ret;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
return (parsed_token_t*)p->ast;
|
return p->ast;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1074,8 +1090,8 @@ static void test_action(void) {
|
||||||
NULL),
|
NULL),
|
||||||
upcase);
|
upcase);
|
||||||
|
|
||||||
g_check_parse_ok(action_, "ab", 2, "(u0x41, u0x42)");
|
g_check_parse_ok(action_, "ab", 2, "(u0x41 u0x42)");
|
||||||
g_check_parse_ok(action_, "AB", 2, "(u0x41, u0x42)");
|
g_check_parse_ok(action_, "AB", 2, "(u0x41 u0x42)");
|
||||||
}
|
}
|
||||||
|
|
||||||
static void test_not_in(void) {
|
static void test_not_in(void) {
|
||||||
|
|
|
||||||
|
|
@ -87,7 +87,7 @@ typedef struct parse_result {
|
||||||
* say, structs) and stuff values for them into the void* in the
|
* say, structs) and stuff values for them into the void* in the
|
||||||
* tagged union in parsed_token_t.
|
* tagged union in parsed_token_t.
|
||||||
*/
|
*/
|
||||||
typedef parsed_token_t* (*action_t)(parse_result_t *p);
|
typedef const parsed_token_t* (*action_t)(parse_result_t *p);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Type of a boolean attribute-checking function, used in the
|
* Type of a boolean attribute-checking function, used in the
|
||||||
|
|
|
||||||
|
|
@ -94,6 +94,10 @@ static inline void append_buf_c(struct result_buf *buf, char v) {
|
||||||
static void unamb_sub(const parsed_token_t* tok, struct result_buf *buf) {
|
static void unamb_sub(const parsed_token_t* tok, struct result_buf *buf) {
|
||||||
char* tmpbuf;
|
char* tmpbuf;
|
||||||
int len;
|
int len;
|
||||||
|
if (!tok) {
|
||||||
|
append_buf(buf, "NULL", 4);
|
||||||
|
return;
|
||||||
|
}
|
||||||
switch (tok->token_type) {
|
switch (tok->token_type) {
|
||||||
case TT_NONE:
|
case TT_NONE:
|
||||||
append_buf(buf, "null", 4);
|
append_buf(buf, "null", 4);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue