Parses the "IfExpr" rule. @return query expression or null @throws QueryException query exception
()
| 1656 | * @throws QueryException query exception |
| 1657 | */ |
| 1658 | private Expr iff() throws QueryException { |
| 1659 | if(!wsConsumeWs(IF, IFPAR, "(")) return null; |
| 1660 | |
| 1661 | final LinkedList<InputInfo> infos = new LinkedList<>(); |
| 1662 | infos.add(info()); |
| 1663 | final ExprList list = new ExprList(3).add(ifCond()); |
| 1664 | if(wsConsumeWs(THEN)) { |
| 1665 | list.add(check(single(), NOIF)); |
| 1666 | if(wsConsumeWs(ELSE)) list.add(check(single(), NOIF)); |
| 1667 | } else { |
| 1668 | list.add(enclosedExpr()); |
| 1669 | while(wsConsume(ELSE)) { |
| 1670 | if(!wsConsume(IF)) { |
| 1671 | list.add(enclosedExpr()); |
| 1672 | break; |
| 1673 | } |
| 1674 | infos.add(info()); |
| 1675 | list.add(ifCond()).add(enclosedExpr()); |
| 1676 | } |
| 1677 | } |
| 1678 | Expr expr = (list.size() & 1) == 0 ? Empty.VALUE : list.pop(); |
| 1679 | while(!list.isEmpty()) { |
| 1680 | final Expr thn = list.pop(), cond = list.pop(); |
| 1681 | expr = new If(infos.removeLast(), cond, thn, expr); |
| 1682 | } |
| 1683 | return expr; |
| 1684 | } |
| 1685 | |
| 1686 | /** |
| 1687 | * Parses the if condition. |
no test coverage detected