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
|
|
@ -9,7 +9,7 @@ static HParseResult* parse_charset(void *env, HParseState *state) {
|
|||
if (charset_isset(cs, in)) {
|
||||
HParsedToken *tok = a_new(HParsedToken, 1);
|
||||
tok->token_type = TT_UINT; tok->uint = in;
|
||||
return make_result(state, tok);
|
||||
return make_result(state->arena, tok);
|
||||
} else
|
||||
return NULL;
|
||||
}
|
||||
|
|
@ -22,17 +22,38 @@ static HCFChoice* desugar_charset(HAllocator *mm__, void *env) {
|
|||
return ret;
|
||||
}
|
||||
|
||||
// FUTURE: this is horribly inefficient
|
||||
static bool cs_ctrvm(HRVMProg *prog, void *env) {
|
||||
HCharset cs = (HCharset)env;
|
||||
uint16_t start = h_rvm_get_ip(prog);
|
||||
for (size_t i=0; i<256; ++i) {
|
||||
if (charset_isset(cs, i)) {
|
||||
uint16_t insn = h_rvm_insert_insn(prog, RVM_FORK, 0);
|
||||
h_rvm_insert_insn(prog, RVM_MATCH, i & i << 8);
|
||||
h_rvm_insert_insn(prog, RVM_GOTO, 0);
|
||||
h_rvm_patch_arg(prog, insn, h_rvm_get_ip(prog));
|
||||
}
|
||||
}
|
||||
uint16_t jump = h_rvm_insert_insn(prog, RVM_STEP, 0);
|
||||
for (size_t i=start; i<jump; ++i) {
|
||||
if (RVM_GOTO == prog->insns[i].op)
|
||||
h_rvm_patch_arg(prog, i, jump);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
static const HParserVtable charset_vt = {
|
||||
.parse = parse_charset,
|
||||
.isValidRegular = h_true,
|
||||
.isValidCF = h_true,
|
||||
.desugar = desugar_charset,
|
||||
.compile_to_rvm = cs_ctrvm,
|
||||
};
|
||||
|
||||
const HParser* h_ch_range(const uint8_t lower, const uint8_t upper) {
|
||||
HParser* h_ch_range(const uint8_t lower, const uint8_t upper) {
|
||||
return h_ch_range__m(&system_allocator, lower, upper);
|
||||
}
|
||||
const HParser* h_ch_range__m(HAllocator* mm__, const uint8_t lower, const uint8_t upper) {
|
||||
HParser* h_ch_range__m(HAllocator* mm__, const uint8_t lower, const uint8_t upper) {
|
||||
HCharset cs = new_charset(mm__);
|
||||
for (int i = 0; i < 256; i++)
|
||||
charset_set(cs, i, (lower <= i) && (i <= upper));
|
||||
|
|
@ -40,7 +61,7 @@ const HParser* h_ch_range__m(HAllocator* mm__, const uint8_t lower, const uint8_
|
|||
}
|
||||
|
||||
|
||||
static const HParser* h_in_or_not__m(HAllocator* mm__, const uint8_t *options, size_t count, int val) {
|
||||
static HParser* h_in_or_not__m(HAllocator* mm__, const uint8_t *options, size_t count, int val) {
|
||||
HCharset cs = new_charset(mm__);
|
||||
for (size_t i = 0; i < 256; i++)
|
||||
charset_set(cs, i, 1-val);
|
||||
|
|
@ -50,19 +71,19 @@ static const HParser* h_in_or_not__m(HAllocator* mm__, const uint8_t *options, s
|
|||
return h_new_parser(mm__, &charset_vt, cs);
|
||||
}
|
||||
|
||||
const HParser* h_in(const uint8_t *options, size_t count) {
|
||||
HParser* h_in(const uint8_t *options, size_t count) {
|
||||
return h_in_or_not__m(&system_allocator, options, count, 1);
|
||||
}
|
||||
|
||||
const HParser* h_in__m(HAllocator* mm__, const uint8_t *options, size_t count) {
|
||||
HParser* h_in__m(HAllocator* mm__, const uint8_t *options, size_t count) {
|
||||
return h_in_or_not__m(mm__, options, count, 1);
|
||||
}
|
||||
|
||||
const HParser* h_not_in(const uint8_t *options, size_t count) {
|
||||
HParser* h_not_in(const uint8_t *options, size_t count) {
|
||||
return h_in_or_not__m(&system_allocator, options, count, 0);
|
||||
}
|
||||
|
||||
const HParser* h_not_in__m(HAllocator* mm__, const uint8_t *options, size_t count) {
|
||||
HParser* h_not_in__m(HAllocator* mm__, const uint8_t *options, size_t count) {
|
||||
return h_in_or_not__m(mm__, options, count, 0);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue