Parse a single Go import_spec node.
| 123 | |
| 124 | // Parse a single Go import_spec node. |
| 125 | static void parse_go_import_spec(CBMExtractCtx *ctx, TSNode spec) { |
| 126 | CBMArena *a = ctx->arena; |
| 127 | TSNode path_node = ts_node_child_by_field_name(spec, TS_FIELD("path")); |
| 128 | if (ts_node_is_null(path_node)) { |
| 129 | return; |
| 130 | } |
| 131 | char *path = strip_quotes(a, cbm_node_text(a, path_node, ctx->source)); |
| 132 | if (!path || !path[0]) { |
| 133 | return; |
| 134 | } |
| 135 | |
| 136 | TSNode name_node = ts_node_child_by_field_name(spec, TS_FIELD("name")); |
| 137 | const char *local_name = |
| 138 | !ts_node_is_null(name_node) ? cbm_node_text(a, name_node, ctx->source) : path_last(a, path); |
| 139 | |
| 140 | CBMImport imp = {.local_name = local_name, .module_path = path}; |
| 141 | cbm_imports_push(&ctx->result->imports, a, imp); |
| 142 | } |
| 143 | |
| 144 | static void parse_go_imports(CBMExtractCtx *ctx) { |
| 145 | TSTreeCursor cursor = ts_tree_cursor_new(ctx->root); |
no test coverage detected