added ElseNode, handling elsif and else correctly

git-svn-id: svn://anubis/fart/trunk@358 7f9b0f55-74a9-4bce-be96-3c2cd072584d
This commit is contained in:
Josh Holtrop 2010-10-07 17:10:27 +00:00
parent 8aaeb8d0fa
commit 240384569d
3 changed files with 18 additions and 1 deletions

View File

@ -157,8 +157,15 @@ NodeRef IfNode::evaluate()
} }
else if ( ! m_elses.isNull() ) else if ( ! m_elses.isNull() )
{ {
eval->addChild(m_elses->evaluate()); return m_elses->evaluate();
} }
return eval; return eval;
} }
NodeRef ElseNode::evaluate()
{
NodeRef eval = new EvaluatePropagateNode();
evaluateChildren(eval);
return eval;
}

View File

@ -744,6 +744,12 @@ class IfNode : public Node
NodeRef m_test_expr, m_elses; NodeRef m_test_expr, m_elses;
}; };
class ElseNode : public Node
{
public:
virtual NodeRef evaluate();
};
/* this class is only used to hold a set of items coming out of a class's /* this class is only used to hold a set of items coming out of a class's
* evaluate() from above. the evaluateChildren() top-level method will * evaluate() from above. the evaluateChildren() top-level method will
* propagate children of this class up to the level of their parent */ * propagate children of this class up to the level of their parent */

View File

@ -431,8 +431,12 @@ if: IF LPAREN bool_expression RPAREN LCURLY general_items RCURLY if_more {
if_more: /* empty */ if_more: /* empty */
| ELSIF LPAREN bool_expression RPAREN LCURLY general_items RCURLY if_more { | ELSIF LPAREN bool_expression RPAREN LCURLY general_items RCURLY if_more {
$$ = new IfNode($3, $8);
$$->addChildren($6);
} }
| ELSE LCURLY general_items RCURLY { | ELSE LCURLY general_items RCURLY {
$$ = new ElseNode();
$$->addChildren($3);
} }
; ;
%% %%