Fix: else if doesn't work without an else branch

fixes #8572
This commit is contained in:
Gunnar Beutner 2015-03-03 10:22:21 +01:00
parent 1d2b008dcb
commit c3e32911a7
1 changed files with 12 additions and 2 deletions

View File

@ -808,12 +808,22 @@ rterm_side_effect: rterm '(' rterm_items ')'
$$ = new FunctionExpression(*$2, new std::map<String, Expression *>(), $5, @$);
delete $2;
}
| T_IF '(' rterm ')' rterm_scope
| T_IF '(' rterm ')' rterm_scope else_if_branches
{
DictExpression *atrue = dynamic_cast<DictExpression *>($5);
atrue->MakeInline();
$$ = new ConditionalExpression($3, atrue, NULL, @$);
std::vector<std::pair<Expression *, Expression *> > ebranches = *$6;
delete $6;
Expression *afalse = NULL;
for (int i = ebranches.size() - 1; i >= 0; i--) {
const std::pair<Expression *, Expression *>& ebranch = ebranches[i];
afalse = new ConditionalExpression(ebranch.first, ebranch.second, afalse, @6);
}
$$ = new ConditionalExpression($3, atrue, afalse, @$);
}
| T_IF '(' rterm ')' rterm_scope else_if_branches T_ELSE rterm_scope
{