2013-04-26 20:36:54 -07:00
|
|
|
#include <assert.h>
|
2012-05-26 16:00:43 +02:00
|
|
|
#include "parser_internal.h"
|
|
|
|
|
|
|
|
|
|
static HParseResult* parse_ignore(void* env, HParseState* state) {
|
|
|
|
|
HParseResult *res0 = h_do_parse((HParser*)env, state);
|
|
|
|
|
if (!res0)
|
|
|
|
|
return NULL;
|
|
|
|
|
HParseResult *res = a_new(HParseResult, 1);
|
|
|
|
|
res->ast = NULL;
|
|
|
|
|
res->arena = state->arena;
|
|
|
|
|
return res;
|
|
|
|
|
}
|
|
|
|
|
|
2012-12-18 18:10:40 -05:00
|
|
|
static bool ignore_isValidRegular(void *env) {
|
|
|
|
|
HParser *p = (HParser*)env;
|
|
|
|
|
return (p->vtable->isValidRegular(p->env));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static bool ignore_isValidCF(void *env) {
|
|
|
|
|
HParser *p = (HParser*)env;
|
|
|
|
|
return (p->vtable->isValidCF(p->env));
|
|
|
|
|
}
|
|
|
|
|
|
2013-02-03 02:18:19 -05:00
|
|
|
static HCFChoice* desugar_ignore(HAllocator *mm__, void *env) {
|
2013-02-20 18:58:15 -05:00
|
|
|
HParser *p = (HParser*)env;
|
2013-03-17 13:25:02 -07:00
|
|
|
return (h_desugar(mm__, p));
|
2013-02-03 02:18:19 -05:00
|
|
|
}
|
|
|
|
|
|
2013-04-26 20:36:54 -07:00
|
|
|
static bool h_svm_action_pop(HArena *arena, HSVMContext *ctx, void* arg) {
|
|
|
|
|
assert(ctx->stack_count > 0);
|
|
|
|
|
ctx->stack_count--;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2013-04-22 18:06:17 -07:00
|
|
|
static bool ignore_ctrvm(HRVMProg *prog, void *env) {
|
|
|
|
|
HParser *p = (HParser*)env;
|
|
|
|
|
h_compile_regex(prog, p->env);
|
2013-04-26 20:36:54 -07:00
|
|
|
h_rvm_insert_insn(prog, RVM_ACTION, h_rvm_create_action(prog, h_svm_action_pop, NULL));
|
2013-04-22 18:06:17 -07:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2012-05-26 16:00:43 +02:00
|
|
|
static const HParserVtable ignore_vt = {
|
|
|
|
|
.parse = parse_ignore,
|
2012-12-18 18:10:40 -05:00
|
|
|
.isValidRegular = ignore_isValidRegular,
|
|
|
|
|
.isValidCF = ignore_isValidCF,
|
2013-02-03 02:18:19 -05:00
|
|
|
.desugar = desugar_ignore,
|
2013-04-22 18:06:17 -07:00
|
|
|
.compile_to_rvm = ignore_ctrvm,
|
2012-05-26 16:00:43 +02:00
|
|
|
};
|
|
|
|
|
|
2013-04-26 20:36:54 -07:00
|
|
|
HParser* h_ignore(const HParser* p) {
|
2012-10-10 15:58:03 +02:00
|
|
|
return h_ignore__m(&system_allocator, p);
|
|
|
|
|
}
|
2013-04-26 20:36:54 -07:00
|
|
|
HParser* h_ignore__m(HAllocator* mm__, const HParser* p) {
|
2013-04-27 04:17:47 +02:00
|
|
|
return h_new_parser(mm__, &ignore_vt, (void *)p);
|
2012-05-26 16:00:43 +02:00
|
|
|
}
|