| 1772 | } |
| 1773 | |
| 1774 | static void scan_mapping_for_bindings(CBMExtractCtx *ctx, TSNode mapping) { |
| 1775 | const char *sources[MAX_INFRA_BINDINGS] = {NULL}; |
| 1776 | const char *source_keys[MAX_INFRA_BINDINGS] = {NULL}; |
| 1777 | int n_sources = 0; |
| 1778 | const char *targets[MAX_INFRA_BINDINGS] = {NULL}; |
| 1779 | int n_targets = 0; |
| 1780 | |
| 1781 | uint32_t nc = ts_node_named_child_count(mapping); |
| 1782 | for (uint32_t i = 0; i < nc; i++) { |
| 1783 | TSNode pair = ts_node_named_child(mapping, i); |
| 1784 | if (strcmp(ts_node_type(pair), "block_mapping_pair") != 0) { |
| 1785 | continue; |
| 1786 | } |
| 1787 | TSNode key = ts_node_child_by_field_name(pair, TS_FIELD("key")); |
| 1788 | TSNode val = ts_node_child_by_field_name(pair, TS_FIELD("value")); |
| 1789 | if (ts_node_is_null(key) || ts_node_is_null(val)) { |
| 1790 | continue; |
| 1791 | } |
| 1792 | char *k = cbm_node_text(ctx->arena, key, ctx->source); |
| 1793 | if (!k) { |
| 1794 | continue; |
| 1795 | } |
| 1796 | |
| 1797 | const char *vtype = ts_node_type(val); |
| 1798 | if (strcmp(vtype, "block_node") != 0 && strcmp(vtype, "block_mapping") != 0) { |
| 1799 | char *v = strip_yaml_quotes(ctx->arena, cbm_node_text(ctx->arena, val, ctx->source)); |
| 1800 | if (is_source_key(k) && n_sources < MAX_INFRA_BINDINGS) { |
| 1801 | sources[n_sources] = v; |
| 1802 | source_keys[n_sources] = k; |
| 1803 | n_sources++; |
| 1804 | } |
| 1805 | if (is_target_key(k) && n_targets < MAX_INFRA_BINDINGS && v && strstr(v, "://")) { |
| 1806 | targets[n_targets++] = v; |
| 1807 | } |
| 1808 | } else { |
| 1809 | scan_nested_mapping_targets(ctx, val, targets, &n_targets); |
| 1810 | } |
| 1811 | } |
| 1812 | |
| 1813 | emit_infra_bindings(ctx, sources, source_keys, n_sources, targets, n_targets); |
| 1814 | } |
| 1815 | |
| 1816 | #define INFRA_SCAN_STACK_CAP CBM_SZ_512 |
| 1817 | static void scan_yaml_for_infra_bindings(CBMExtractCtx *ctx, TSNode root) { |
no test coverage detected