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

Function extract_python_docstring

internal/cbm/extract_defs.c:1197–1218  ·  view source on GitHub ↗

Python-specific: docstring as first expression_statement -> string in function body.

Source from the content-addressed store, hash-verified

1195
1196// Python-specific: docstring as first expression_statement -> string in function body.
1197static const char *extract_python_docstring(CBMArena *a, TSNode node, const char *source) {
1198 TSNode body = ts_node_child_by_field_name(node, TS_FIELD("body"));
1199 if (ts_node_is_null(body) || ts_node_named_child_count(body) == 0) {
1200 return NULL;
1201 }
1202 TSNode first = ts_node_named_child(body, 0);
1203 if (ts_node_is_null(first) || strcmp(ts_node_type(first), "expression_statement") != 0) {
1204 return NULL;
1205 }
1206 if (ts_node_named_child_count(first) == 0) {
1207 return NULL;
1208 }
1209 TSNode str = ts_node_named_child(first, 0);
1210 if (ts_node_is_null(str)) {
1211 return NULL;
1212 }
1213 const char *sk = ts_node_type(str);
1214 if (strcmp(sk, "string") == 0 || strcmp(sk, "concatenated_string") == 0) {
1215 return extract_comment_text(a, str, source);
1216 }
1217 return NULL;
1218}
1219
1220// Extract docstring from the node's leading comment.
1221static const char *extract_docstring(CBMArena *a, TSNode node, const char *source,

Callers 1

extract_docstringFunction · 0.85

Calls 1

extract_comment_textFunction · 0.85

Tested by

no test coverage detected