Got a lot of regex test cases working
This commit is contained in:
parent
f37a13ef41
commit
0600440b7c
11 changed files with 148 additions and 14 deletions
|
|
@ -1,3 +1,4 @@
|
|||
#include <assert.h>
|
||||
#include "parser_internal.h"
|
||||
|
||||
static HParseResult* parse_ch(void* env, HParseState *state) {
|
||||
|
|
@ -20,11 +21,26 @@ static HCFChoice* desugar_ch(HAllocator *mm__, void *env) {
|
|||
return ret;
|
||||
}
|
||||
|
||||
static bool h_svm_action_ch(HArena *arena, HSVMContext *ctx, void* env) {
|
||||
// BUG: relies un undefined behaviour: int64_t is a signed uint64_t; not necessarily true on 32-bit
|
||||
HParsedToken *top = ctx->stack[ctx->stack_count-1];
|
||||
assert(top->token_type == TT_BYTES);
|
||||
uint64_t res = 0;
|
||||
for (size_t i = 0; i < top->bytes.len; i++)
|
||||
res = (res << 8) | top->bytes.token[i]; // TODO: Handle other endiannesses.
|
||||
top->uint = res; // possibly cast to signed through union
|
||||
top->token_type = TT_UINT;
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool ch_ctrvm(HRVMProg *prog, void* env) {
|
||||
uint8_t c = (uint8_t)(unsigned long)(env);
|
||||
// TODO: Does this capture anything?
|
||||
h_rvm_insert_insn(prog, RVM_MATCH, c & c << 8);
|
||||
h_rvm_insert_insn(prog, RVM_PUSH, 0);
|
||||
h_rvm_insert_insn(prog, RVM_MATCH, c | c << 8);
|
||||
h_rvm_insert_insn(prog, RVM_STEP, 0);
|
||||
h_rvm_insert_insn(prog, RVM_CAPTURE, 0);
|
||||
h_rvm_insert_insn(prog, RVM_ACTION, h_rvm_create_action(prog, h_svm_action_ch, env));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue