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);
|
|
|
|
|
}
|
2012-12-18 18:10:40 -05:00
|
|
|
|
|
|
|
|
static bool indirect_isValidCF(void *env) {
|
|
|
|
|
HParser *p = (HParser*)env;
|
|
|
|
|
HParser *inner = (HParser*)p->env;
|
|
|
|
|
return inner->vtable->isValidCF(inner->env);
|
|
|
|
|
}
|
|
|
|
|
|
2013-02-03 02:18:19 -05:00
|
|
|
static HCFChoice desugar_indirect(HAllocator *mm__, void *env) {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2012-05-26 16:00:43 +02:00
|
|
|
static const HParserVtable indirect_vt = {
|
|
|
|
|
.parse = parse_indirect,
|
2012-12-18 18:10:40 -05:00
|
|
|
.isValidRegular = h_false,
|
|
|
|
|
.isValidCF = indirect_isValidCF,
|
2013-02-03 02:18:19 -05:00
|
|
|
.desugar = desugar_indirect,
|
2012-05-26 16:00:43 +02:00
|
|
|
};
|
|
|
|
|
|
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;
|
|
|
|
|
}
|