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

Function rs_parse_text

internal/cbm/doclink_rs.c:2090–2131  ·  view source on GitHub ↗

The references of one doc text, pushed as tokens of the node `source_qn`. * `file_doc`: it is the file's own doc, whose lines need not be contiguous. */

Source from the content-addressed store, hash-verified

2088/* The references of one doc text, pushed as tokens of the node `source_qn`.
2089 * `file_doc`: it is the file's own doc, whose lines need not be contiguous. */
2090static void rs_parse_text(CBMExtractCtx *ctx, const char *source_qn, uint32_t def_line,
2091 const char *doc, uint32_t doc_line, bool file_doc) {
2092 if (!doc || !source_qn || !strchr(doc, '[')) {
2093 return; /* no bracket, no link */
2094 }
2095 CBMArena *tmp = rs_scratch(ctx);
2096 int n = 0;
2097 rs_line_t *lines = rs_doc_lines(tmp, doc, doc_line, &n);
2098 if (!lines || n == 0) {
2099 return;
2100 }
2101 if (file_doc) {
2102 rs_lines_resync(ctx, lines, n, doc, doc_line);
2103 }
2104 rs_defs_t defs = {.a = tmp};
2105 rs_md_t st;
2106 memset(&st, 0, sizeof(st));
2107 st.a = tmp;
2108 for (int i = 0; i < n;) {
2109 i += rs_md_line(&st, lines, n, i, &defs);
2110 }
2111 char *buf = NULL;
2112 rs_inline_t *in = (defs.failed || st.failed) ? NULL : rs_inline_new(tmp, lines, n, &buf);
2113 if (!in) {
2114 return;
2115 }
2116 if (defs.n > SKIP_ONE) {
2117 qsort(defs.v, (size_t)defs.n, sizeof(rs_def_t), rs_def_cmp);
2118 }
2119 rs_sink_t sink = {.ctx = ctx, .source_qn = source_qn, .def_line = def_line, .defs = &defs};
2120 int first = CBM_NOT_FOUND;
2121 for (int i = 0; i <= n; i++) {
2122 bool text = i < n && lines[i].kind == RS_L_TEXT;
2123 if (first >= 0 && (!text || lines[i].para_start)) {
2124 rs_scan_paragraph(in, &sink, lines, first, i - SKIP_ONE, buf);
2125 first = CBM_NOT_FOUND;
2126 }
2127 if (text && first < 0) {
2128 first = i;
2129 }
2130 }
2131}
2132
2133void cbm_doclink_rs_parse_doc(CBMExtractCtx *ctx, const CBMDefinition *def, const char *doc,
2134 uint32_t doc_line) {

Callers 1

cbm_doclink_rs_parse_docFunction · 0.85

Calls 6

rs_scratchFunction · 0.85
rs_doc_linesFunction · 0.85
rs_lines_resyncFunction · 0.85
rs_md_lineFunction · 0.85
rs_inline_newFunction · 0.85
rs_scan_paragraphFunction · 0.85

Tested by

no test coverage detected