Implement question mark desugaring
This commit is contained in:
@@ -53,12 +53,35 @@ static void desugar_plus(parse_term_t *term)
|
||||
term->subexpr.contents = alternatives;
|
||||
}
|
||||
|
||||
static void desugar_qmark(parse_term_t *term)
|
||||
{
|
||||
parse_sequence_t *alternatives = malloc(2 * sizeof(parse_sequence_t));
|
||||
|
||||
alternatives[0].count = alternatives[0].capacity = 1;
|
||||
alternatives[0].contents = malloc(sizeof(parse_term_t));
|
||||
alternatives[0].contents[0].quantifier = PARSE_QUANTIFIER_NONE;
|
||||
alternatives[0].contents[0].type = PARSE_TERM_EMPTY;
|
||||
|
||||
alternatives[1].count = alternatives[0].capacity = 1;
|
||||
alternatives[1].contents = malloc(sizeof(parse_term_t));
|
||||
memcpy(&alternatives[1].contents[0], term, sizeof(parse_term_t));
|
||||
alternatives[1].contents[0].quantifier = PARSE_QUANTIFIER_NONE;
|
||||
|
||||
term->quantifier = PARSE_QUANTIFIER_NONE;
|
||||
term->type = PARSE_TERM_SUBEXPR;
|
||||
term->subexpr.count = term->subexpr.capacity = 2;
|
||||
term->subexpr.contents = alternatives;
|
||||
}
|
||||
|
||||
static void desugar_term(parse_term_t *term)
|
||||
{
|
||||
switch (term->quantifier) {
|
||||
case PARSE_QUANTIFIER_PLUS:
|
||||
desugar_plus(term);
|
||||
break;
|
||||
case PARSE_QUANTIFIER_QMARK:
|
||||
desugar_qmark(term);
|
||||
break;
|
||||
case PARSE_QUANTIFIER_NONE:
|
||||
case PARSE_QUANTIFIER_STAR:
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user