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

Function parse_one_embedded_block

internal/cbm/extract_imports.c:2100–2154  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2098}
2099
2100static void parse_one_embedded_block(CBMExtractCtx *ctx, const CBMEmbeddedBlock *block,
2101 CBMLanguage embedded_language) {
2102 const TSLanguage *language = cbm_ts_language(embedded_language);
2103 if (!language || ctx->source_len < 0) {
2104 return;
2105 }
2106 TSRange range = {
2107 .start_point = ts_node_start_point(block->content),
2108 .end_point = ts_node_end_point(block->content),
2109 .start_byte = ts_node_start_byte(block->content),
2110 .end_byte = ts_node_end_byte(block->content),
2111 };
2112 if (range.end_byte <= range.start_byte || range.end_byte > (uint32_t)ctx->source_len) {
2113 return;
2114 }
2115
2116 /* One fresh parser/tree per block prevents parser state or error recovery
2117 * from one script from changing the next script's result. Parsing the full
2118 * original buffer through the absolute included range preserves byte and
2119 * point coordinates across CRLF and UTF-8 prefixes. */
2120 TSParser *parser = ts_parser_new();
2121 if (!parser) {
2122 return;
2123 }
2124 if (!ts_parser_set_language(parser, language) ||
2125 !ts_parser_set_included_ranges(parser, &range, 1)) {
2126 ts_parser_delete(parser);
2127 return;
2128 }
2129 TSTree *tree = ts_parser_parse_string(parser, NULL, ctx->source, (uint32_t)ctx->source_len);
2130 if (!tree) {
2131 ts_parser_delete(parser);
2132 return;
2133 }
2134
2135 CBMExtractCtx sub_ctx = {
2136 .arena = ctx->arena,
2137 .result = ctx->result,
2138 .source = ctx->source,
2139 .source_len = ctx->source_len,
2140 .language = embedded_language,
2141 .project = ctx->project,
2142 .rel_path = ctx->rel_path,
2143 .module_qn = ctx->module_qn,
2144 .root = ts_tree_root_node(tree),
2145 .macro_table = ctx->macro_table,
2146 .return_type_table = ctx->return_type_table,
2147 };
2148 cbm_extract_definitions_without_module(&sub_ctx);
2149 walk_es_imports(&sub_ctx, sub_ctx.root);
2150 cbm_extract_unified(&sub_ctx);
2151
2152 ts_tree_delete(tree);
2153 ts_parser_delete(parser);
2154}
2155
2156static void parse_embedded_imports(CBMExtractCtx *ctx) {
2157 const CBMLangSpec *spec = cbm_lang_spec(ctx->language);

Callers 1

parse_embedded_importsFunction · 0.85

Calls 4

cbm_ts_languageFunction · 0.85
walk_es_importsFunction · 0.85
cbm_extract_unifiedFunction · 0.85

Tested by

no test coverage detected