Merge remote-tracking branch 'tq/master' into LL such that it compiles
Conflicts: src/Makefile src/backends/packrat.c src/compile.c src/hammer.h src/internal.h src/parsers/action.c src/parsers/and.c src/parsers/attr_bool.c src/parsers/bits.c src/parsers/butnot.c src/parsers/ch.c src/parsers/charset.c src/parsers/choice.c src/parsers/difference.c src/parsers/end.c src/parsers/epsilon.c src/parsers/ignore.c src/parsers/ignoreseq.c src/parsers/indirect.c src/parsers/int_range.c src/parsers/many.c src/parsers/not.c src/parsers/nothing.c src/parsers/optional.c src/parsers/sequence.c src/parsers/token.c src/parsers/unimplemented.c src/parsers/whitespace.c src/parsers/xor.c
This commit is contained in:
commit
c64a4e435e
46 changed files with 1289 additions and 263 deletions
|
|
@ -121,17 +121,39 @@ static HCFChoice* desugar_int_range(HAllocator *mm__, void *env) {
|
|||
return gen_int_range(mm__, r->lower, r->upper, bytes);
|
||||
}
|
||||
|
||||
bool h_svm_action_validate_int_range(HArena *arena, HSVMContext *ctx, void* env) {
|
||||
HRange *r_env = (HRange*)env;
|
||||
HParsedToken *head = ctx->stack[ctx->stack_count-1];
|
||||
switch (head-> token_type) {
|
||||
case TT_SINT:
|
||||
return head->sint >= r_env->lower && head->sint <= r_env->upper;
|
||||
case TT_UINT:
|
||||
return head->uint >= (uint64_t)r_env->lower && head->uint <= (uint64_t)r_env->upper;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
static bool ir_ctrvm(HRVMProg *prog, void *env) {
|
||||
HRange *r_env = (HRange*)env;
|
||||
|
||||
h_compile_regex(prog, r_env->p);
|
||||
h_rvm_insert_insn(prog, RVM_ACTION, h_rvm_create_action(prog, h_svm_action_validate_int_range, env));
|
||||
return false;
|
||||
}
|
||||
|
||||
static const HParserVtable int_range_vt = {
|
||||
.parse = parse_int_range,
|
||||
.isValidRegular = h_true,
|
||||
.isValidCF = h_true,
|
||||
.desugar = desugar_int_range,
|
||||
.compile_to_rvm = ir_ctrvm,
|
||||
};
|
||||
|
||||
const HParser* h_int_range(const HParser *p, const int64_t lower, const int64_t upper) {
|
||||
HParser* h_int_range(const HParser *p, const int64_t lower, const int64_t upper) {
|
||||
return h_int_range__m(&system_allocator, p, lower, upper);
|
||||
}
|
||||
const HParser* h_int_range__m(HAllocator* mm__, const HParser *p, const int64_t lower, const int64_t upper) {
|
||||
HParser* h_int_range__m(HAllocator* mm__, const HParser *p, const int64_t lower, const int64_t upper) {
|
||||
// p must be an integer parser, which means it's using parse_bits
|
||||
// TODO: re-add this check
|
||||
//assert_message(p->vtable == &bits_vt, "int_range requires an integer parser");
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue