A loop value: an expression (a scalar holding {{ }}, or a list of exactly * one -- with_items flattens one level), else a literal list of items. */
| 770 | /* A loop value: an expression (a scalar holding {{ }}, or a list of exactly |
| 771 | * one -- with_items flattens one level), else a literal list of items. */ |
| 772 | static void an_loop_parse(const an_t *a, TSNode v, an_loop_t *out) { |
| 773 | char buf[CBM_SZ_1K]; |
| 774 | *out = (an_loop_t){0}; |
| 775 | if (an_scalar(a, v, buf, sizeof(buf))) { |
| 776 | out->expr = strstr(buf, "{{") ? an_dup(buf) : NULL; |
| 777 | return; |
| 778 | } |
| 779 | TSNode s = an_bare(v); |
| 780 | bool block = an_type(s, "block_sequence"); |
| 781 | if (!block && !an_type(s, "flow_sequence")) { |
| 782 | return; |
| 783 | } |
| 784 | int cap = 0; |
| 785 | for (uint32_t i = 0; i < ts_node_named_child_count(s); i++) { |
| 786 | TSNode item = ts_node_named_child(s, i); |
| 787 | if (block ? !an_type(item, "block_sequence_item") : !an_type(item, "flow_node")) { |
| 788 | continue; |
| 789 | } |
| 790 | if (block) { |
| 791 | item = ts_node_named_child(item, 0); |
| 792 | } |
| 793 | an_item_t *grown = an_grow(out->items, &cap, out->n, sizeof(an_item_t)); |
| 794 | if (!grown) { |
| 795 | return; |
| 796 | } |
| 797 | out->items = grown; |
| 798 | an_item_parse(a, item, &out->items[out->n++]); |
| 799 | } |
| 800 | if (out->n == SKIP_ONE && out->items[0].scalar && strstr(out->items[0].scalar, "{{")) { |
| 801 | out->expr = out->items[0].scalar; |
| 802 | out->items[0].scalar = NULL; |
| 803 | cbm_free(CBM_MEM_CLASS_OTHER, out->items); |
| 804 | out->items = NULL; |
| 805 | out->n = 0; |
| 806 | } |
| 807 | } |
| 808 | |
| 809 | static void an_loop_free(an_loop_t *l) { |
| 810 | for (int i = 0; i < l->n; i++) { |