Still doesn't build, but desugaring is farther along

This commit is contained in:
Meredith L. Patterson 2013-02-02 19:31:18 -05:00
parent 36e1f66de0
commit 156be7a559
16 changed files with 266 additions and 26 deletions

View file

@ -5,8 +5,6 @@ typedef struct {
uint8_t len;
} HToken;
static HParseResult* parse_token(void *env, HParseState *state) {
HToken *t = (HToken*)env;
for (int i=0; i<t->len; ++i) {
@ -20,10 +18,30 @@ static HParseResult* parse_token(void *env, HParseState *state) {
return make_result(state, tok);
}
static HCFChoice* desugar_token(HAllocator *mm__, void *env) {
HToken *tok = (HToken*)env;
HCFSequence *seq = h_new(HCFSequence, 1);
seq->items = h_new(HCFChoice*, 1+tok->len);
for (size_t i=0; i<tok->len; ++i) {
seq->items[i] = h_new(HCFChoice, 1);
seq->items[i]->type = HCF_CHAR;
seq->items[i]->chr = tok->str[i];
}
seq->items[tok->len] = 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;
ret->action = NULL;
return ret;
}
const HParserVtable token_vt = {
.parse = parse_token,
.isValidRegular = h_true,
.isValidCF = h_true,
.desugar = desugar_token,
};
const HParser* h_token(const uint8_t *str, const size_t len) {