Implemented a bunch more desugaring
This commit is contained in:
parent
5ae267f3ed
commit
101e90ad9b
11 changed files with 51 additions and 35 deletions
|
|
@ -9,7 +9,7 @@ static HParseResult *parse_and(void* env, HParseState* state) {
|
|||
return NULL;
|
||||
}
|
||||
|
||||
static const HCFChoice* desugar_and(HAllocator *mm__, void *env) {
|
||||
static HCFChoice* desugar_and(HAllocator *mm__, void *env) {
|
||||
assert_message(0, "Not context-free, can't be desugared");
|
||||
return NULL;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,13 +22,30 @@ static bool ab_isValidRegular(void *env) {
|
|||
return ab->p->vtable->isValidRegular(ab->p->env);
|
||||
}
|
||||
|
||||
/* Strictly speaking, this does not adhere to the definition of context-free.
|
||||
However, for the purpose of making it easier to handle weird constraints on
|
||||
fields, we've decided to allow boolean attribute validation at parse time
|
||||
for now. We might change our minds later. */
|
||||
|
||||
static bool ab_isValidCF(void *env) {
|
||||
HAttrBool *ab = (HAttrBool*)env;
|
||||
return ab->p->vtable->isValidCF(ab->p->env);
|
||||
}
|
||||
|
||||
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[1] = NULL;
|
||||
HCFChoice *ret = h_new(HCFChoice, 1);
|
||||
ret->type = HCF_CHOICE;
|
||||
ret->seq = h_new(HCFSequence*, 2);
|
||||
ret->seq[0] = seq;
|
||||
ret->seq[1] = NULL;
|
||||
/* TODO: need to process this as an HPredicate */
|
||||
ret->action = a->action;
|
||||
return ret;
|
||||
}
|
||||
|
||||
static const HParserVtable attr_bool_vt = {
|
||||
|
|
|
|||
|
|
@ -35,20 +35,15 @@ static HParseResult* parse_butnot(void *env, HParseState *state) {
|
|||
}
|
||||
}
|
||||
|
||||
static bool bn_isValidCF(void *env) {
|
||||
HTwoParsers *tp = (HTwoParsers*)env;
|
||||
return (tp->p1->vtable->isValidCF(tp->p1->env) &&
|
||||
tp->p2->vtable->isValidCF(tp->p2->env));
|
||||
}
|
||||
|
||||
static HCFChoice* desugar_butnot(HAllocator *mm__, void *env) {
|
||||
|
||||
assert_message(0, "'h_butnot' is not context-free, can't be desugared");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static const HParserVtable butnot_vt = {
|
||||
.parse = parse_butnot,
|
||||
.isValidRegular = h_false,
|
||||
.isValidCF = bn_isValidCF,
|
||||
.isValidCF = h_false,
|
||||
.desugar = desugar_butnot,
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -34,20 +34,15 @@ static HParseResult* parse_difference(void *env, HParseState *state) {
|
|||
}
|
||||
}
|
||||
|
||||
static bool diff_isValidCF(void *env) {
|
||||
HTwoParsers *tp = (HTwoParsers*)env;
|
||||
return (tp->p1->vtable->isValidCF(tp->p1->env) &&
|
||||
tp->p2->vtable->isValidCF(tp->p2->env));
|
||||
}
|
||||
|
||||
static HCFChoice* desugar_difference(HAllocator *mm__, void *env) {
|
||||
|
||||
assert_message(0, "'h_difference' is not context-free, can't be desugared");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static HParserVtable difference_vt = {
|
||||
.parse = parse_difference,
|
||||
.isValidRegular = h_false,
|
||||
.isValidCF = diff_isValidCF,
|
||||
.isValidCF = h_false,
|
||||
.desugar = desugar_difference,
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -9,11 +9,13 @@ static HParseResult* parse_epsilon(void* env, HParseState* state) {
|
|||
}
|
||||
|
||||
static HCFChoice* desugar_epsilon(HAllocator *mm__, void *env) {
|
||||
static HCFSequence res_seq = {NULL};
|
||||
static HCFChoice *res_seq_l[] = {NULL};
|
||||
static HCFSequence res_seq = {res_seq_l};
|
||||
static HCFSequence *res_ch_l[] = {&res_seq, NULL};
|
||||
static HCFChoice res_ch = {
|
||||
.type = HCF_CHOICE,
|
||||
.seq = &res_seq,
|
||||
.action = NULL;
|
||||
.seq = res_ch_l,
|
||||
.action = NULL
|
||||
};
|
||||
|
||||
return &res_ch;
|
||||
|
|
|
|||
|
|
@ -21,7 +21,8 @@ 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));
|
||||
}
|
||||
|
||||
static const HParserVtable ignore_vt = {
|
||||
|
|
|
|||
|
|
@ -57,7 +57,6 @@ static bool many_isValidCF(void *env) {
|
|||
}
|
||||
|
||||
static HCFChoice* desugar_many(HAllocator *mm__, void *env) {
|
||||
|
||||
}
|
||||
|
||||
static const HParserVtable many_vt = {
|
||||
|
|
@ -164,10 +163,16 @@ static HParseResult* parse_length_value(void *env, HParseState *state) {
|
|||
return parse_many(&repeat, state);
|
||||
}
|
||||
|
||||
static HCFChoice* desugar_length_value(HAllocator *mm__, void *env) {
|
||||
assert_message(0, "'h_length_value' is not context-free, can't be desugared");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static const HParserVtable length_value_vt = {
|
||||
.parse = parse_length_value,
|
||||
.isValidRegular = h_false,
|
||||
.isValidCF = h_false,
|
||||
.desugar = desugar_length_value,
|
||||
};
|
||||
|
||||
const HParser* h_length_value(const HParser* length, const HParser* value) {
|
||||
|
|
|
|||
|
|
@ -10,8 +10,8 @@ static HParseResult* parse_not(void* env, HParseState* state) {
|
|||
}
|
||||
}
|
||||
|
||||
static const HCFChoice* desugar_not(HAllocator *mm__, void *env) {
|
||||
assert_message(0, "Not context-free, can't be desugared");
|
||||
static HCFChoice* desugar_not(HAllocator *mm__, void *env) {
|
||||
assert_message(0, "'h_not' is not context-free, can't be desugared");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -22,7 +22,8 @@ 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);
|
||||
}
|
||||
|
||||
static const HParserVtable optional_vt = {
|
||||
|
|
|
|||
|
|
@ -12,11 +12,16 @@ static HParseResult* parse_unimplemented(void* env, HParseState *state) {
|
|||
return &result;
|
||||
}
|
||||
|
||||
static HCFChoice* desugar_unimplemented(HAllocator *mm__, void *env) {
|
||||
assert_message(0, "'h_unimplemented' is not context-free, can't be desugared");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static const HParserVtable unimplemented_vt = {
|
||||
.parse = parse_unimplemented,
|
||||
.isValidRegular = h_false,
|
||||
.isValidCF = h_false,
|
||||
.desugar = NULL,
|
||||
.desugar = desugar_unimplemented,
|
||||
};
|
||||
|
||||
static HParser unimplemented = {
|
||||
|
|
|
|||
|
|
@ -31,20 +31,15 @@ static HParseResult* parse_xor(void *env, HParseState *state) {
|
|||
}
|
||||
}
|
||||
|
||||
static bool xor_isValidCF(void *env) {
|
||||
HTwoParsers *tp = (HTwoParsers*)env;
|
||||
return (tp->p1->vtable->isValidCF(tp->p1->env) &&
|
||||
tp->p2->vtable->isValidCF(tp->p2->env));
|
||||
}
|
||||
|
||||
static HCFChoice* desugar_xor(HAllocator *mm__, void *env) {
|
||||
|
||||
assert_message(0, "'h_xor' is not context-free, can't be desugared");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static const HParserVtable xor_vt = {
|
||||
.parse = parse_xor,
|
||||
.isValidRegular = h_false,
|
||||
.isValidCF = xor_isValidCF,
|
||||
.isValidCF = h_false,
|
||||
.desugar = desugar_xor,
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue