Most of RVM desugaring done in first draft, for TQ to check.
This commit is contained in:
parent
a88c6c8a8a
commit
07d35c72ff
23 changed files with 182 additions and 4 deletions
|
|
@ -5,7 +5,7 @@
|
|||
// general case: parse sequence, pick one result
|
||||
//
|
||||
|
||||
typedef struct {
|
||||
typedef struct HIgnoreSeq_ {
|
||||
const HParser **parsers;
|
||||
size_t len; // how many parsers in 'ps'
|
||||
size_t which; // whose result to return
|
||||
|
|
@ -44,10 +44,37 @@ static bool is_isValidCF(void *env) {
|
|||
return true;
|
||||
}
|
||||
|
||||
static bool h_svm_action_ignoreseq(HArena *arena, HSVMContext *ctx, void* env) {
|
||||
HIgnoreSeq *seq = (HIgnoreSeq*)env;
|
||||
HParsedToken* save;
|
||||
// We can assume that each subitem generated at most one item on the
|
||||
// stack.
|
||||
for (int i = seq->len - 1; i>=0; i--) {
|
||||
if (i == seq->which && ctx->stack[ctx->stack_count]->token_type != TT_MARK)
|
||||
save = ctx->stack[ctx->stack_count-1];
|
||||
// skip over everything up to and including the mark.
|
||||
while (ctx->stack[--ctx->stack_count]->token_type != TT_MARK)
|
||||
;
|
||||
}
|
||||
ctx->stack[ctx->stack_count++] = save;
|
||||
}
|
||||
|
||||
static bool is_ctrvm(HRVMProg *prog, void* env) {
|
||||
HIgnoreSeq *seq = (HIgnoreSeq*)env;
|
||||
for (size_t i=0; i<seq->len; ++i) {
|
||||
h_rvm_insert_insn(prog, RVM_PUSH, 0);
|
||||
if (!h_compile_regex(prog, seq->parsers[i]->env))
|
||||
return false;
|
||||
}
|
||||
h_rvm_insert_insn(prog, RVM_ACTION, h_rvm_create_action(prog, h_svm_action_ignoreseq, env));
|
||||
return true;
|
||||
}
|
||||
|
||||
static const HParserVtable ignoreseq_vt = {
|
||||
.parse = parse_ignoreseq,
|
||||
.isValidRegular = is_isValidRegular,
|
||||
.isValidCF = is_isValidCF,
|
||||
.compile_to_rvm = is_ctrvm,
|
||||
};
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue