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
|
|
@ -1,3 +1,4 @@
|
|||
#include <assert.h>
|
||||
#include "parser_internal.h"
|
||||
|
||||
static HParseResult* parse_optional(void* env, HParseState* state) {
|
||||
|
|
@ -8,7 +9,7 @@ static HParseResult* parse_optional(void* env, HParseState* state) {
|
|||
state->input_stream = bak;
|
||||
HParsedToken *ast = a_new(HParsedToken, 1);
|
||||
ast->token_type = TT_NONE;
|
||||
return make_result(state, ast);
|
||||
return make_result(state->arena, ast);
|
||||
}
|
||||
|
||||
static bool opt_isValidRegular(void *env) {
|
||||
|
|
@ -26,17 +27,40 @@ static HCFChoice* desugar_optional(HAllocator *mm__, void *env) {
|
|||
return h_desugar(mm__, p);
|
||||
}
|
||||
|
||||
static bool h_svm_action_optional(HArena *arena, HSVMContext *ctx, void *env) {
|
||||
if (ctx->stack[ctx->stack_count-1]->token_type == TT_MARK) {
|
||||
ctx->stack[ctx->stack_count-1]->token_type = TT_NONE;
|
||||
} else {
|
||||
ctx->stack_count--;
|
||||
assert(ctx->stack[ctx->stack_count-1]->token_type == TT_MARK);
|
||||
ctx->stack[ctx->stack_count-1] = ctx->stack[ctx->stack_count];
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool opt_ctrvm(HRVMProg *prog, void* env) {
|
||||
h_rvm_insert_insn(prog, RVM_PUSH, 0);
|
||||
uint16_t insn = h_rvm_insert_insn(prog, RVM_FORK, 0);
|
||||
HParser *p = (HParser*) env;
|
||||
if (!h_compile_regex(prog, p->env))
|
||||
return false;
|
||||
h_rvm_patch_arg(prog, insn, h_rvm_get_ip(prog));
|
||||
h_rvm_insert_insn(prog, RVM_ACTION, h_rvm_create_action(prog, h_svm_action_optional, NULL));
|
||||
return true;
|
||||
}
|
||||
|
||||
static const HParserVtable optional_vt = {
|
||||
.parse = parse_optional,
|
||||
.isValidRegular = opt_isValidRegular,
|
||||
.isValidCF = opt_isValidCF,
|
||||
.desugar = desugar_optional,
|
||||
.compile_to_rvm = opt_ctrvm,
|
||||
};
|
||||
|
||||
const HParser* h_optional(const HParser* p) {
|
||||
HParser* h_optional(const HParser* p) {
|
||||
return h_optional__m(&system_allocator, p);
|
||||
}
|
||||
const HParser* h_optional__m(HAllocator* mm__, const HParser* p) {
|
||||
HParser* h_optional__m(HAllocator* mm__, const HParser* p) {
|
||||
// TODO: re-add this
|
||||
//assert_message(p->vtable != &ignore_vt, "Thou shalt ignore an option, rather than the other way 'round.");
|
||||
return h_new_parser(mm__, &optional_vt, (void *)p);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue