Juozas Baliuka - 2010-07-29

I changed It to SimpleExpression, but it is valid to use subselects in CASE too.

Expression CaseWhenExpression():
{
CaseExpression caseExp = new CaseExpression();
Expression switchExp = null;
WhenClause clause;
List whenClauses = new ArrayList();
Expression elseExp = null;
}
{
<K_CASE>
(
( clause=WhenThenSearchCondition() { whenClauses.add(clause); } )+
[<K_ELSE> elseExp= !!! SimpleExpression()]
|
switchExp=PrimaryExpression()
( clause=WhenThenValue() { whenClauses.add(clause); } )*
[<K_ELSE> elseExp= !!! SimpleExpression()]
)
<K_END>
{
caseExp.setSwitchExpression(switchExp);
caseExp.setWhenClauses(whenClauses);
caseExp.setElseExpression(elseExp);
return caseExp;
}
}

WhenClause WhenThenSearchCondition():
{
WhenClause whenThen = new WhenClause();
Expression whenExp = null;
Expression thenExp = null;
}
{
<K_WHEN> whenExp=Expression() <K_THEN> thenExp= !!! SimpleExpression()
{
whenThen.setWhenExpression(whenExp);
whenThen.setThenExpression(thenExp);
return whenThen;
}
}