hammer/src/parsers/nothing.c

37 lines
880 B
C
Raw Normal View History

2012-05-26 16:00:43 +02:00
#include "parser_internal.h"
static HParseResult* parse_nothing() {
// not a mistake, this parser always fails
return NULL;
}
static HCFChoice *desugar_nothing(HAllocator *mm__, void *env) {
HCFChoice *ret = h_new(HCFChoice, 1);
ret->type = HCF_CHOICE;
ret->seq = h_new(HCFSequence*, 1);
ret->seq[0] = NULL;
ret->action = NULL;
return ret;
}
2013-03-18 15:27:16 -07:00
static bool nothing_ctrvm(HRVMProg *prog, void* env) {
2013-04-26 20:36:54 -07:00
h_rvm_insert_insn(prog, RVM_MATCH, 0x0000);
h_rvm_insert_insn(prog, RVM_MATCH, 0xFFFF);
2013-03-18 15:27:16 -07:00
return true;
}
2012-05-26 16:00:43 +02:00
static const HParserVtable nothing_vt = {
.parse = parse_nothing,
.isValidRegular = h_true,
.isValidCF = h_true,
.desugar = desugar_nothing,
2013-03-18 15:27:16 -07:00
.compile_to_rvm = nothing_ctrvm,
2012-05-26 16:00:43 +02:00
};
2013-04-26 20:36:54 -07:00
HParser* h_nothing_p() {
2012-10-10 15:58:03 +02:00
return h_nothing_p__m(&system_allocator);
}
2013-04-26 20:36:54 -07:00
HParser* h_nothing_p__m(HAllocator* mm__) {
return h_new_parser(mm__, &nothing_vt, NULL);
2012-05-26 16:00:43 +02:00
}