call actions only on successful parse

This commit is contained in:
Sven M. Hallberg 2012-06-09 14:41:32 +02:00
parent 6d755efbde
commit 10154622b8
2 changed files with 6 additions and 2 deletions

View file

@ -426,6 +426,7 @@ static void test_action(void) {
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)");
g_check_parse_failed(action_, "XX", 2);
} }
static void test_not_in(void) { static void test_not_in(void) {

View file

@ -10,8 +10,11 @@ static HParseResult* parse_action(void *env, HParseState *state) {
if (a->p && a->action) { if (a->p && a->action) {
HParseResult *tmp = h_do_parse(a->p, state); HParseResult *tmp = h_do_parse(a->p, state);
//HParsedToken *tok = a->action(h_do_parse(a->p, state)); //HParsedToken *tok = a->action(h_do_parse(a->p, state));
const HParsedToken *tok = a->action(tmp); if(tmp) {
return make_result(state, (HParsedToken*)tok); const HParsedToken *tok = a->action(tmp);
return make_result(state, (HParsedToken*)tok);
} else
return NULL;
} 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;
} }