hammer/src/parsers/indirect.c

24 lines
612 B
C
Raw Normal View History

2012-05-26 16:00:43 +02:00
#include "parser_internal.h"
static HParseResult* parse_indirect(void* env, HParseState* state) {
return h_do_parse(env, state);
}
static const HParserVtable indirect_vt = {
.parse = parse_indirect,
};
2012-06-01 20:00:10 +02:00
void h_bind_indirect(HParser* indirect, const HParser* inner) {
2012-05-26 16:00:43 +02:00
assert_message(indirect->vtable == &indirect_vt, "You can only bind an indirect parser");
2012-06-01 20:00:10 +02:00
indirect->env = (void*)inner;
2012-05-26 16:00:43 +02:00
}
HParser* h_indirect() {
2012-10-10 15:58:03 +02:00
return h_indirect__m(&system_allocator);
}
HParser* h_indirect__m(HAllocator* mm__) {
HParser *res = h_new(HParser, 1);
2012-05-26 16:00:43 +02:00
res->vtable = &indirect_vt;
res->env = NULL;
return res;
}