diff --git a/src/parsers/and.c b/src/parsers/and.c index 7f870ba..650a11a 100644 --- a/src/parsers/and.c +++ b/src/parsers/and.c @@ -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; } diff --git a/src/parsers/attr_bool.c b/src/parsers/attr_bool.c index 059bfbc..46f511f 100644 --- a/src/parsers/attr_bool.c +++ b/src/parsers/attr_bool.c @@ -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 = { diff --git a/src/parsers/butnot.c b/src/parsers/butnot.c index adb2e97..c0e3b41 100644 --- a/src/parsers/butnot.c +++ b/src/parsers/butnot.c @@ -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, }; diff --git a/src/parsers/difference.c b/src/parsers/difference.c index 1b0e09f..3528759 100644 --- a/src/parsers/difference.c +++ b/src/parsers/difference.c @@ -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, }; diff --git a/src/parsers/epsilon.c b/src/parsers/epsilon.c index 5063e60..d802246 100644 --- a/src/parsers/epsilon.c +++ b/src/parsers/epsilon.c @@ -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; diff --git a/src/parsers/ignore.c b/src/parsers/ignore.c index a642c84..1129e88 100644 --- a/src/parsers/ignore.c +++ b/src/parsers/ignore.c @@ -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 = { diff --git a/src/parsers/many.c b/src/parsers/many.c index 193fadc..15f020b 100644 --- a/src/parsers/many.c +++ b/src/parsers/many.c @@ -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) { diff --git a/src/parsers/not.c b/src/parsers/not.c index d6f25d5..b0d5a8e 100644 --- a/src/parsers/not.c +++ b/src/parsers/not.c @@ -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; } diff --git a/src/parsers/optional.c b/src/parsers/optional.c index f59ca55..e22a4f6 100644 --- a/src/parsers/optional.c +++ b/src/parsers/optional.c @@ -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 = { diff --git a/src/parsers/unimplemented.c b/src/parsers/unimplemented.c index 1bd288b..fcfe821 100644 --- a/src/parsers/unimplemented.c +++ b/src/parsers/unimplemented.c @@ -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 = { diff --git a/src/parsers/xor.c b/src/parsers/xor.c index ed67371..c8dbe3d 100644 --- a/src/parsers/xor.c +++ b/src/parsers/xor.c @@ -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, };