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

Function lisp_push_module

internal/cbm/extract_imports.c:2345–2374  ·  view source on GitHub ↗

--- Lisp-family imports (Scheme, Racket) --- S-expression grammars model (import (lib ...)) / (require mod) / (load "f") as a `list` whose first named child is a `symbol` naming the form. Walk top-level lists; for import/require/load/use, take the remaining children as module references (a symbol, a string, or a nested list whose meaningful module symbol we take as-is).

Source from the content-addressed store, hash-verified

2343// module references (a symbol, a string, or a nested list whose meaningful
2344// module symbol we take as-is).
2345static void lisp_push_module(CBMExtractCtx *ctx, TSNode mod_node) {
2346 CBMArena *a = ctx->arena;
2347 const char *mk = ts_node_type(mod_node);
2348 char *mod = NULL;
2349 if (strcmp(mk, "symbol") == 0 || strcmp(mk, "string") == 0 || strcmp(mk, "sym_lit") == 0 ||
2350 strcmp(mk, "str_lit") == 0 || strcmp(mk, "kwd_lit") == 0) {
2351 mod = strip_quotes(a, cbm_node_text(a, mod_node, ctx->source));
2352 /* Clojure/Fennel keyword module refs carry a leading ':' (e.g. `:util`,
2353 * `(require :util)`); strip it so the name matches the sibling file. */
2354 if (mod && mod[0] == ':') {
2355 mod = cbm_arena_strdup(a, mod + 1);
2356 }
2357 } else if (strcmp(mk, "list") == 0 || strcmp(mk, "list_lit") == 0 ||
2358 strcmp(mk, "vec_lit") == 0) {
2359 /* (only-in racket/math pi) → take first symbol after a leading keyword,
2360 * else join inner symbols with '/'. Simplest robust choice: the whole
2361 * list text minus the parens. */
2362 mod = cbm_node_text(a, mod_node, ctx->source);
2363 if (mod) {
2364 size_t len = strlen(mod);
2365 if (len >= 2 && mod[0] == '(' && mod[len - 1] == ')') {
2366 mod = cbm_arena_strndup(a, mod + 1, len - 2);
2367 }
2368 }
2369 }
2370 if (mod && mod[0]) {
2371 CBMImport imp = {.local_name = path_last(a, mod), .module_path = mod};
2372 cbm_imports_push(&ctx->result->imports, a, imp);
2373 }
2374}
2375
2376/* Strip a leading ':' from a lisp keyword/symbol token (Clojure/Fennel/CL
2377 * package keywords carry it: `:util` → `util`). Returns an arena copy. */

Callers 2

lisp_push_clause_modulesFunction · 0.85
lisp_process_listFunction · 0.85

Calls 6

cbm_node_textFunction · 0.85
path_lastFunction · 0.85
cbm_imports_pushFunction · 0.85
strip_quotesFunction · 0.70
cbm_arena_strdupFunction · 0.70
cbm_arena_strndupFunction · 0.70

Tested by

no test coverage detected