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
|
|
@ -54,34 +54,53 @@ static HCFChoice* desugar_choice(HAllocator *mm__, void *env) {
|
|||
return ret;
|
||||
}
|
||||
|
||||
static bool choice_ctrvm(HRVMProg *prog, void* env) {
|
||||
HSequence *s = (HSequence*)env;
|
||||
uint16_t gotos[s->len];
|
||||
uint16_t start = h_rvm_get_ip(prog);
|
||||
for (size_t i=0; i<s->len; ++i) {
|
||||
uint16_t insn = h_rvm_insert_insn(prog, RVM_FORK, 0);
|
||||
if (!h_compile_regex(prog, s->p_array[i]->env))
|
||||
return false;
|
||||
gotos[i] = 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<s->len; ++i) {
|
||||
h_rvm_patch_arg(prog, gotos[i], jump);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
static const HParserVtable choice_vt = {
|
||||
.parse = parse_choice,
|
||||
.isValidRegular = choice_isValidRegular,
|
||||
.isValidCF = choice_isValidCF,
|
||||
.desugar = desugar_choice,
|
||||
.compile_to_rvm = choice_ctrvm,
|
||||
};
|
||||
|
||||
const HParser* h_choice(const HParser* p, ...) {
|
||||
HParser* h_choice(const HParser* p, ...) {
|
||||
va_list ap;
|
||||
va_start(ap, p);
|
||||
const HParser* ret = h_choice__mv(&system_allocator, p, ap);
|
||||
HParser* ret = h_choice__mv(&system_allocator, p, ap);
|
||||
va_end(ap);
|
||||
return ret;
|
||||
}
|
||||
|
||||
const HParser* h_choice__m(HAllocator* mm__, const HParser* p, ...) {
|
||||
HParser* h_choice__m(HAllocator* mm__, const HParser* p, ...) {
|
||||
va_list ap;
|
||||
va_start(ap, p);
|
||||
const HParser* ret = h_choice__mv(mm__, p, ap);
|
||||
HParser* ret = h_choice__mv(mm__, p, ap);
|
||||
va_end(ap);
|
||||
return ret;
|
||||
}
|
||||
|
||||
const HParser* h_choice__v(const HParser* p, va_list ap) {
|
||||
HParser* h_choice__v(const HParser* p, va_list ap) {
|
||||
return h_choice__mv(&system_allocator, p, ap);
|
||||
}
|
||||
|
||||
const HParser* h_choice__mv(HAllocator* mm__, const HParser* p, va_list ap_) {
|
||||
HParser* h_choice__mv(HAllocator* mm__, const HParser* p, va_list ap_) {
|
||||
va_list ap;
|
||||
size_t len = 0;
|
||||
HSequence *s = h_new(HSequence, 1);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue