Python-specific: docstring as first expression_statement -> string in function body.
| 1285 | |
| 1286 | // Python-specific: docstring as first expression_statement -> string in function body. |
| 1287 | static const char *extract_python_docstring(CBMArena *a, TSNode node, const char *source) { |
| 1288 | TSNode body = ts_node_child_by_field_name(node, TS_FIELD("body")); |
| 1289 | if (ts_node_is_null(body) || ts_node_named_child_count(body) == 0) { |
| 1290 | return NULL; |
| 1291 | } |
| 1292 | TSNode first = ts_node_named_child(body, 0); |
| 1293 | if (ts_node_is_null(first) || strcmp(ts_node_type(first), "expression_statement") != 0) { |
| 1294 | return NULL; |
| 1295 | } |
| 1296 | if (ts_node_named_child_count(first) == 0) { |
| 1297 | return NULL; |
| 1298 | } |
| 1299 | TSNode str = ts_node_named_child(first, 0); |
| 1300 | if (ts_node_is_null(str)) { |
| 1301 | return NULL; |
| 1302 | } |
| 1303 | const char *sk = ts_node_type(str); |
| 1304 | if (strcmp(sk, "string") == 0 || strcmp(sk, "concatenated_string") == 0) { |
| 1305 | return cbm_node_text(a, str, source); |
| 1306 | } |
| 1307 | return NULL; |
| 1308 | } |
| 1309 | |
| 1310 | /* ── Doc comments ───────────────────────────────────────────────────────── |
| 1311 | * A definition's doc is the comment RUN directly above it, not only the one |
no test coverage detected