reshape for h_sequence
This commit is contained in:
parent
e5300e2836
commit
e03513b59a
1 changed files with 23 additions and 0 deletions
|
|
@ -1,4 +1,5 @@
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
|
#include <assert.h>
|
||||||
#include "parser_internal.h"
|
#include "parser_internal.h"
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
|
@ -42,6 +43,27 @@ static bool sequence_isValidCF(void *env) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static const HParsedToken *reshape_sequence(const HParseResult *p) {
|
||||||
|
assert(p->ast);
|
||||||
|
assert(p->ast->token_type == TT_SEQUENCE);
|
||||||
|
|
||||||
|
HCountedArray *seq = h_carray_new(p->arena);
|
||||||
|
|
||||||
|
// drop all elements that are NULL
|
||||||
|
for(size_t i=0; i<p->ast->seq->used; i++) {
|
||||||
|
if(p->ast->seq->elements[i] != NULL)
|
||||||
|
h_carray_append(seq, p->ast->seq->elements[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
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 HCFChoice* desugar_sequence(HAllocator *mm__, void *env) {
|
static HCFChoice* desugar_sequence(HAllocator *mm__, void *env) {
|
||||||
HSequence *s = (HSequence*)env;
|
HSequence *s = (HSequence*)env;
|
||||||
HCFSequence *seq = h_new(HCFSequence, 1);
|
HCFSequence *seq = h_new(HCFSequence, 1);
|
||||||
|
|
@ -56,6 +78,7 @@ static HCFChoice* desugar_sequence(HAllocator *mm__, void *env) {
|
||||||
ret->seq[0] = seq;
|
ret->seq[0] = seq;
|
||||||
ret->seq[1] = NULL;
|
ret->seq[1] = NULL;
|
||||||
ret->action = NULL;
|
ret->action = NULL;
|
||||||
|
ret->reshape = reshape_sequence;
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue