Parse a multi-argument scalar call: coalesce(a, b, ...), substring(s, i[, n]), * replace(s, from, to), left(s, n), right(s, n). */
| 1602 | /* Parse a multi-argument scalar call: coalesce(a, b, ...), substring(s, i[, n]), |
| 1603 | * replace(s, from, to), left(s, n), right(s, n). */ |
| 1604 | static int parse_multiarg_func_item(parser_t *p, cbm_return_item_t *item) { |
| 1605 | const char *canon = multiarg_func_canonical(peek(p)->text); |
| 1606 | advance(p); /* function name */ |
| 1607 | expect(p, TOK_LPAREN); |
| 1608 | int cap = CYP_INIT_CAP4; |
| 1609 | item->args = malloc((size_t)cap * sizeof(cbm_func_arg_t)); |
| 1610 | item->arg_count = 0; |
| 1611 | while (!check(p, TOK_RPAREN) && !check(p, TOK_EOF)) { |
| 1612 | if (item->arg_count > 0 && !match(p, TOK_COMMA)) { |
| 1613 | break; |
| 1614 | } |
| 1615 | if (item->arg_count >= cap) { |
| 1616 | cap *= PAIR_LEN; |
| 1617 | item->args = safe_realloc(item->args, (size_t)cap * sizeof(cbm_func_arg_t)); |
| 1618 | } |
| 1619 | if (parse_func_arg(p, &item->args[item->arg_count]) < 0) { |
| 1620 | return CBM_NOT_FOUND; |
| 1621 | } |
| 1622 | item->arg_count++; |
| 1623 | } |
| 1624 | expect(p, TOK_RPAREN); |
| 1625 | item->func = heap_strdup(canon); |
| 1626 | /* Surface the first variable arg as variable/property for column naming. */ |
| 1627 | if (item->arg_count > 0 && item->args[0].variable) { |
| 1628 | item->variable = heap_strdup(item->args[0].variable); |
| 1629 | if (item->args[0].property) { |
| 1630 | item->property = heap_strdup(item->args[0].property); |
| 1631 | } |
| 1632 | } |
| 1633 | return 0; |
| 1634 | } |
| 1635 | |
| 1636 | /* Parse aggregate function call: COUNT(var.prop) */ |
| 1637 | static int parse_aggregate_item(parser_t *p, cbm_return_item_t *item) { |
no test coverage detected