MCPcopy Create free account
hub / github.com/DeusData/codebase-memory-mcp / parse_shell_source_imports

Function parse_shell_source_imports

internal/cbm/extract_imports.c:2690–2716  ·  view source on GitHub ↗

--- Bash / Zsh imports --- source file / . file — `command` nodes whose command_name is "source" or ".". The argument field carries the sourced path. Every other command is a call, not an import: read as an import, `set -e` imported "set", which the import resolver then bound to whatever project symbol is named set (a TSX method), and every `set` call in the script followed it.

Source from the content-addressed store, hash-verified

2688// resolver then bound to whatever project symbol is named set (a TSX method),
2689// and every `set` call in the script followed it.
2690static void parse_shell_source_imports(CBMExtractCtx *ctx) {
2691 CBMArena *a = ctx->arena;
2692 TSNodeStack stack;
2693 ts_nstack_init(&stack, ctx, CBM_SZ_512);
2694 ts_nstack_push(&stack, ctx->root);
2695 while (stack.count > 0) {
2696 TSNode node = ts_nstack_pop(&stack);
2697 if (strcmp(ts_node_type(node), "command") == 0) {
2698 TSNode name = ts_node_child_by_field_name(node, TS_FIELD("name"));
2699 char *nm = ts_node_is_null(name) ? NULL : cbm_node_text(a, name, ctx->source);
2700 if (nm && (strcmp(nm, "source") == 0 || strcmp(nm, ".") == 0)) {
2701 TSNode arg = ts_node_child_by_field_name(node, TS_FIELD("argument"));
2702 if (ts_node_is_null(arg)) {
2703 arg = ts_node_child_by_field_name(node, TS_FIELD("arguments"));
2704 }
2705 if (!ts_node_is_null(arg)) {
2706 char *mod = strip_quotes(a, cbm_node_text(a, arg, ctx->source));
2707 if (mod && mod[0]) {
2708 CBMImport imp = {.local_name = path_last(a, mod), .module_path = mod};
2709 cbm_imports_push(&ctx->result->imports, a, imp);
2710 }
2711 }
2712 }
2713 }
2714 ts_nstack_push_children(&stack, node);
2715 }
2716}
2717
2718// --- Make imports: include / -include / sinclude FILE... ---
2719// Every name of an include directive -- outside recipes, conditionals

Callers 1

cbm_extract_importsFunction · 0.85

Calls 8

ts_nstack_initFunction · 0.85
ts_nstack_pushFunction · 0.85
ts_nstack_popFunction · 0.85
cbm_node_textFunction · 0.85
path_lastFunction · 0.85
cbm_imports_pushFunction · 0.85
ts_nstack_push_childrenFunction · 0.85
strip_quotesFunction · 0.70

Tested by

no test coverage detected