fix reshape for h_many
This commit is contained in:
parent
db95cda229
commit
7319c48e59
1 changed files with 28 additions and 2 deletions
|
|
@ -59,6 +59,32 @@ static bool many_isValidCF(void *env) {
|
|||
repeat->sep->vtable->isValidCF(repeat->sep->env)));
|
||||
}
|
||||
|
||||
// turn (_ x (_ y (_ z ()))) into (x y z) where '_' are optional
|
||||
static HParsedToken *reshape_many(const HParseResult *p, void *user)
|
||||
{
|
||||
HCountedArray *seq = h_carray_new(p->arena);
|
||||
|
||||
const HParsedToken *tok = p->ast;
|
||||
while(tok) {
|
||||
assert(tok->token_type == TT_SEQUENCE);
|
||||
if(tok->seq->used > 0) {
|
||||
size_t n = tok->seq->used;
|
||||
assert(n <= 3);
|
||||
h_carray_append(seq, tok->seq->elements[n-2]);
|
||||
tok = tok->seq->elements[n-1];
|
||||
} else {
|
||||
tok = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
HParsedToken *res = a_new_(p->arena, HParsedToken, 1);
|
||||
res->token_type = TT_SEQUENCE;
|
||||
res->seq = seq;
|
||||
res->index = p->ast->index;
|
||||
res->bit_offset = p->ast->bit_offset;
|
||||
return res;
|
||||
}
|
||||
|
||||
static void desugar_many(HAllocator *mm__, HCFStack *stk__, void *env) {
|
||||
// TODO: refactor this.
|
||||
HRepeat *repeat = (HRepeat*)env;
|
||||
|
|
@ -93,7 +119,7 @@ static void desugar_many(HAllocator *mm__, HCFStack *stk__, void *env) {
|
|||
HCFS_BEGIN_CHOICE() { // Mar
|
||||
HCFS_BEGIN_SEQ() {
|
||||
if (repeat->sep != NULL) {
|
||||
HCFS_DESUGAR(h_ignore__m(mm__, repeat->sep));
|
||||
HCFS_DESUGAR(repeat->sep);
|
||||
}
|
||||
//stk__->last_completed->reshape = h_act_ignore; // BUG: This modifies a memoized entry.
|
||||
HCFS_DESUGAR(repeat->p);
|
||||
|
|
@ -108,7 +134,7 @@ static void desugar_many(HAllocator *mm__, HCFStack *stk__, void *env) {
|
|||
//HCFS_DESUGAR(h_ignore__m(mm__, h_epsilon_p()));
|
||||
} HCFS_END_SEQ();
|
||||
}
|
||||
HCFS_THIS_CHOICE->reshape = h_act_flatten;
|
||||
HCFS_THIS_CHOICE->reshape = reshape_many;
|
||||
} HCFS_END_CHOICE();
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue