Skip to content
Snippets Groups Projects
Commit 41385062 authored by Sven M. Hallberg's avatar Sven M. Hallberg
Browse files

unwrap (reshape) singleton terminal symbols correctly

parent 010d957f
No related branches found
No related tags found
No related merge requests found
...@@ -37,6 +37,15 @@ static void collect_nts(HCFGrammar *grammar, HCFChoice *symbol); ...@@ -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) ...@@ -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 {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment