Adding desugar

This commit is contained in:
Rob Zinkov 2013-03-17 13:25:02 -07:00
parent f7246e9589
commit 4e11c90664
10 changed files with 15 additions and 13 deletions

View file

@ -23,7 +23,7 @@ static HCFChoice* desugar_action(HAllocator *mm__, void *env) {
HParseAction *a = (HParseAction*)env;
HCFSequence *seq = h_new(HCFSequence, 1);
seq->items = h_new(HCFChoice*, 2);
seq->items[0] = a->p->vtable->desugar(mm__, a->p->env);
seq->items[0] = h_desugar(mm__, a->p);
seq->items[1] = NULL;
HCFChoice *ret = h_new(HCFChoice, 1);
ret->type = HCF_CHOICE;

View file

@ -36,7 +36,7 @@ static HCFChoice* desugar_ab(HAllocator *mm__, void *env) {
HAttrBool *a = (HAttrBool*)env;
HCFSequence *seq = h_new(HCFSequence, 1);
seq->items = h_new(HCFChoice*, 2);
seq->items[0] = a->p->vtable->desugar(mm__, a->p->env);
seq->items[0] = h_desugar(mm__, a->p);
seq->items[1] = NULL;
HCFChoice *ret = h_new(HCFChoice, 1);
ret->type = HCF_CHOICE;

View file

@ -47,7 +47,7 @@ static HCFChoice* desugar_choice(HAllocator *mm__, void *env) {
for (size_t i=0; i<s->len; ++i) {
ret->seq[i] = h_new(HCFSequence, 1);
ret->seq[i]->items = h_new(HCFChoice*, 2);
ret->seq[i]->items[0] = s->p_array[i]->vtable->desugar(mm__, s->p_array[i]->env);
ret->seq[i]->items[0] = h_desugar(mm__, s->p_array[i]);
ret->seq[i]->items[1] = NULL;
}
ret->seq[s->len] = NULL;

View file

@ -22,7 +22,7 @@ static bool ignore_isValidCF(void *env) {
static HCFChoice* desugar_ignore(HAllocator *mm__, void *env) {
HParser *p = (HParser*)env;
return (p->vtable->desugar(mm__, p->env));
return (h_desugar(mm__, p));
}
static const HParserVtable ignore_vt = {

View file

@ -31,7 +31,7 @@ static HCFChoice* desugar_ignoreseq(HAllocator *mm__, void *env) {
HCFSequence *hseq = h_new(HCFSequence, 1);
hseq->items = h_new(HCFChoice*, 1+seq->len);
for (size_t i=0; i<seq->len; ++i) {
hseq->items[i] = seq->parsers[i]->vtable->desugar(mm__, seq->parsers[i]->env);
hseq->items[i] = h_desugar(mm__, seq->parsers[i]);
}
hseq->items[seq->len] = NULL;
HCFChoice *ret = h_new(HCFChoice, 1);

View file

@ -76,7 +76,7 @@ static HCFChoice* desugar_many(HAllocator *mm__, void *env) {
/* create first subrule */
HCFChoice *ma = h_new(HCFChoice, 3);
ma->type = HCF_CHOICE;
ma->seq[0]->items[0] = repeat->p->vtable->desugar(mm__, repeat->p->env);
ma->seq[0]->items[0] = h_desugar(mm__, repeat->p);
/* create second subrule */
HCFChoice *mar = h_new(HCFChoice, 3);
@ -84,8 +84,8 @@ static HCFChoice* desugar_many(HAllocator *mm__, void *env) {
mar->seq = h_new(HCFSequence*, 2);
mar->seq[0] = h_new(HCFSequence, 1);
mar->seq[0]->items = h_new(HCFChoice*, 4);
mar->seq[0]->items[0] = repeat->sep->vtable->desugar(mm__, repeat->sep->env);
mar->seq[0]->items[1] = repeat->p->vtable->desugar(mm__, repeat->p->env);
mar->seq[0]->items[0] = h_desugar(mm__, repeat->sep);
mar->seq[0]->items[1] = h_desugar(mm__, repeat->p);
mar->seq[0]->items[2] = mar; // woo recursion!
mar->seq[0]->items[3] = NULL;
mar->seq[1]->items = h_new(HCFChoice*, 2);

View file

@ -23,7 +23,7 @@ static bool opt_isValidCF(void *env) {
static HCFChoice* desugar_optional(HAllocator *mm__, void *env) {
HParser *p = (HParser*) env;
return p->vtable->desugar(mm__, p->env);
return h_desugar(mm__, p);
}
static const HParserVtable optional_vt = {

View file

@ -47,7 +47,7 @@ static HCFChoice* desugar_sequence(HAllocator *mm__, void *env) {
HCFSequence *seq = h_new(HCFSequence, 1);
seq->items = h_new(HCFChoice*, s->len+1);
for (size_t i=0; i<s->len; ++i) {
seq->items[i] = h_desugar(s->p_array[i]);
seq->items[i] = h_desugar(mm__, s->p_array[i]);
}
seq->items[s->len] = NULL;
HCFChoice *ret = h_new(HCFChoice, 1);