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

Function rs_attr_read

internal/cbm/doclink_rs.c:2642–2691  ·  view source on GitHub ↗

Read one `#[...]` above an item into `at`. */

Source from the content-addressed store, hash-verified

2640
2641/* Read one `#[...]` above an item into `at`. */
2642static void rs_attr_read(const rs_scan_t *s, TSNode attr_item, rs_attrs_t *at) {
2643 uint32_t a = ts_node_start_byte(attr_item);
2644 uint32_t b = ts_node_end_byte(attr_item);
2645 if (b <= a || b > s->src_len) {
2646 return;
2647 }
2648 const char *text = s->src + a;
2649 size_t n = b - a;
2650 bool long_attr = n > RS_SCAN_ATTR_CAP;
2651 n = long_attr ? RS_SCAN_ATTR_CAP : n;
2652 /* the attribute's own name: the path after `#[` up to `(`, `=` or `]` */
2653 size_t i = 0;
2654 while (i < n && (text[i] == '#' || text[i] == '[' || isspace((unsigned char)text[i]))) {
2655 i++;
2656 }
2657 size_t name = i;
2658 while (i < n && (isalnum((unsigned char)text[i]) || text[i] == '_' || text[i] == ':')) {
2659 i++;
2660 }
2661 size_t nl = i - name;
2662 const char *p = text + name;
2663 static const char test_suffix[] = "::test";
2664 const size_t tsl = sizeof(test_suffix) - SKIP_ONE;
2665 if (rs_word_is(p, nl, "test") || rs_word_is(p, nl, "bench") ||
2666 (nl > tsl && memcmp(p + nl - tsl, test_suffix, tsl) == 0)) {
2667 at->test = true;
2668 } else if (rs_word_is(p, nl, "cfg")) {
2669 at->test = at->test || (rs_has_word(text, n, "test") && !rs_has_word(text, n, "not"));
2670 } else if (rs_word_is(p, nl, "path")) {
2671 if (long_attr || !rs_attr_string(text, n, at->path, sizeof(at->path))) {
2672 at->cond_path = true; /* a path this scan cannot read */
2673 }
2674 } else if (rs_word_is(p, nl, "cfg_attr")) {
2675 at->cond_path = at->cond_path || long_attr || rs_has_word(text, n, "path");
2676 at->derives_more = at->derives_more || long_attr;
2677 rs_attr_derives(text, n, at);
2678 } else if (rs_word_is(p, nl, "derive")) {
2679 at->derives_more = at->derives_more || long_attr;
2680 rs_attr_derives(text, n, at);
2681 } else if (rs_word_is(p, nl, "macro_export")) {
2682 at->macro_export = true;
2683 } else if (rs_word_is(p, nl, "proc_macro")) {
2684 at->macro_kind = 'P';
2685 } else if (rs_word_is(p, nl, "proc_macro_attribute")) {
2686 at->macro_kind = 'B';
2687 } else if (rs_word_is(p, nl, "proc_macro_derive")) {
2688 at->macro_kind = 'V';
2689 rs_attr_first_arg(text, n, at->derive, sizeof(at->derive));
2690 }
2691}
2692
2693/* ── Scope scan: names local to a documented item ────────────────── */
2694

Callers 1

rs_scan_blockFunction · 0.85

Calls 5

rs_word_isFunction · 0.85
rs_has_wordFunction · 0.85
rs_attr_stringFunction · 0.85
rs_attr_derivesFunction · 0.85
rs_attr_first_argFunction · 0.85

Tested by

no test coverage detected