Finshed up the regex backend
This commit is contained in:
parent
204147a3d2
commit
13088c9d7a
39 changed files with 481 additions and 250 deletions
|
|
@ -1,3 +1,4 @@
|
|||
#include <assert.h>
|
||||
#include "parser_internal.h"
|
||||
|
||||
static HParseResult* parse_optional(void* env, HParseState* state) {
|
||||
|
|
@ -21,12 +22,25 @@ static bool opt_isValidCF(void *env) {
|
|||
return p->vtable->isValidCF(p->env);
|
||||
}
|
||||
|
||||
static bool h_svm_action_optional(HArena *arena, HSVMContext *ctx, void *env) {
|
||||
if (ctx->stack[ctx->stack_count-1]->token_type == TT_MARK) {
|
||||
ctx->stack[ctx->stack_count-1]->token_type = TT_NONE;
|
||||
} else {
|
||||
ctx->stack_count--;
|
||||
assert(ctx->stack[ctx->stack_count-1]->token_type == TT_MARK);
|
||||
ctx->stack[ctx->stack_count-1] = ctx->stack[ctx->stack_count];
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool opt_ctrvm(HRVMProg *prog, void* env) {
|
||||
h_rvm_insert_insn(prog, RVM_PUSH, 0);
|
||||
uint16_t insn = h_rvm_insert_insn(prog, RVM_FORK, 0);
|
||||
HParser *p = (HParser*) env;
|
||||
if (!h_compile_regex(prog, p->env))
|
||||
return false;
|
||||
h_rvm_patch_arg(prog, insn, h_rvm_get_ip(prog));
|
||||
h_rvm_insert_insn(prog, RVM_ACTION, h_rvm_create_action(prog, h_svm_action_optional, NULL));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -37,10 +51,10 @@ static const HParserVtable optional_vt = {
|
|||
.compile_to_rvm = opt_ctrvm,
|
||||
};
|
||||
|
||||
const HParser* h_optional(const HParser* p) {
|
||||
HParser* h_optional(const HParser* p) {
|
||||
return h_optional__m(&system_allocator, p);
|
||||
}
|
||||
const HParser* h_optional__m(HAllocator* mm__, const HParser* p) {
|
||||
HParser* h_optional__m(HAllocator* mm__, const HParser* p) {
|
||||
// TODO: re-add this
|
||||
//assert_message(p->vtable != &ignore_vt, "Thou shalt ignore an option, rather than the other way 'round.");
|
||||
HParser *ret = h_new(HParser, 1);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue