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;
|
2013-05-23 03:38:22 -07:00
|
|
|
return p->vtable->isValidCF(p->env);
|
2012-12-18 18:10:40 -05:00
|
|
|
}
|
|
|
|
|
|
2013-05-25 03:35:42 +02:00
|
|
|
static void desugar_indirect(HAllocator *mm__, HCFStack *stk__, void *env) {
|
2013-06-14 12:27:35 +02:00
|
|
|
HCFS_DESUGAR( (HParser *)env );
|
2013-02-03 02:18:19 -05:00
|
|
|
}
|
|
|
|
|
|
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,
|
2013-04-22 18:06:17 -07:00
|
|
|
.compile_to_rvm = h_not_regular,
|
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__) {
|
2013-04-27 04:17:47 +02:00
|
|
|
return h_new_parser(mm__, &indirect_vt, NULL);
|
2012-05-26 16:00:43 +02:00
|
|
|
}
|