All tests pass; lots of stuff is no longer const
This commit is contained in:
parent
b9a33f2c98
commit
d71215d494
24 changed files with 216 additions and 120 deletions
|
|
@ -1,3 +1,4 @@
|
|||
#include <assert.h>
|
||||
#include "parser_internal.h"
|
||||
|
||||
typedef struct {
|
||||
|
|
@ -45,9 +46,35 @@ static bool action_isValidCF(void *env) {
|
|||
return a->p->vtable->isValidCF(a->p->env);
|
||||
}
|
||||
|
||||
static bool h_svm_action_action(HArena *arena, HSVMContext *ctx, void* arg) {
|
||||
HParseResult res;
|
||||
HAction action = arg;
|
||||
assert(ctx->stack_count >= 1);
|
||||
if (ctx->stack[ctx->stack_count-1]->token_type != TT_MARK) {
|
||||
assert(ctx->stack_count >= 2 && ctx->stack[ctx->stack_count-2]->token_type == TT_MARK);
|
||||
res.ast = ctx->stack[ctx->stack_count-2] = ctx->stack[ctx->stack_count-1];
|
||||
ctx->stack_count--;
|
||||
// mark replaced.
|
||||
} else {
|
||||
res.ast = NULL;
|
||||
}
|
||||
res.arena = arena;
|
||||
|
||||
HParsedToken *tok = action(&res);
|
||||
if (tok != NULL)
|
||||
ctx->stack[ctx->stack_count-1] = tok;
|
||||
else
|
||||
ctx->stack_count--;
|
||||
return true; // action can't fail
|
||||
}
|
||||
|
||||
static bool action_ctrvm(HRVMProg *prog, void* env) {
|
||||
HParseAction *a = (HParseAction*)env;
|
||||
return a->p->vtable->compile_to_rvm(prog, a->p->env);
|
||||
h_rvm_insert_insn(prog, RVM_PUSH, 0);
|
||||
if (!h_compile_regex(prog, a->p))
|
||||
return false;
|
||||
h_rvm_insert_insn(prog, RVM_ACTION, h_rvm_create_action(prog, h_svm_action_action, a->action));
|
||||
return true;
|
||||
}
|
||||
|
||||
static const HParserVtable action_vt = {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue