unwrap (reshape) singleton terminal symbols correctly

This commit is contained in:
Sven M. Hallberg 2013-05-14 14:14:31 +02:00
parent 010d957fe8
commit 4138506273

View file

@ -37,6 +37,15 @@ static void collect_nts(HCFGrammar *grammar, HCFChoice *symbol);
static void collect_geneps(HCFGrammar *grammar); static void collect_geneps(HCFGrammar *grammar);
static const HParsedToken *h_act_first(const HParseResult *p)
{
assert(p->ast);
assert(p->ast->token_type == TT_SEQUENCE);
assert(p->ast->seq->used > 0);
return p->ast->seq->elements[0];
}
/* Convert 'parser' into CFG representation by desugaring and compiling the set /* Convert 'parser' into CFG representation by desugaring and compiling the set
* of nonterminals. * of nonterminals.
* A NULL return means we are unable to represent the parser as a CFG. * A NULL return means we are unable to represent the parser as a CFG.
@ -63,6 +72,7 @@ HCFGrammar *h_cfgrammar(HAllocator* mm__, const HParser *parser)
nt->seq[0]->items[0] = desugared; nt->seq[0]->items[0] = desugared;
nt->seq[0]->items[1] = NULL; nt->seq[0]->items[1] = NULL;
nt->seq[1] = NULL; nt->seq[1] = NULL;
nt->reshape = h_act_first;
h_hashset_put(g->nts, nt); h_hashset_put(g->nts, nt);
g->start = nt; g->start = nt;
} else { } else {