From 4138506273ad663dce38fdf8871b07542c3312e3 Mon Sep 17 00:00:00 2001 From: "Sven M. Hallberg" <pesco@khjk.org> Date: Tue, 14 May 2013 14:14:31 +0200 Subject: [PATCH] unwrap (reshape) singleton terminal symbols correctly --- src/cfgrammar.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/cfgrammar.c b/src/cfgrammar.c index a9005e9b..684a39c8 100644 --- a/src/cfgrammar.c +++ b/src/cfgrammar.c @@ -37,6 +37,15 @@ static void collect_nts(HCFGrammar *grammar, HCFChoice *symbol); 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 * of nonterminals. * 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[1] = NULL; nt->seq[1] = NULL; + nt->reshape = h_act_first; h_hashset_put(g->nts, nt); g->start = nt; } else { -- GitLab