Python-specific: docstring as first expression_statement -> string in function body.
| 1244 | |
| 1245 | // Python-specific: docstring as first expression_statement -> string in function body. |
| 1246 | static const char *extract_python_docstring(CBMArena *a, TSNode node, const char *source) { |
| 1247 | TSNode body = ts_node_child_by_field_name(node, TS_FIELD("body")); |
| 1248 | if (ts_node_is_null(body) || ts_node_named_child_count(body) == 0) { |
| 1249 | return NULL; |
| 1250 | } |
| 1251 | TSNode first = ts_node_named_child(body, 0); |
| 1252 | if (ts_node_is_null(first) || strcmp(ts_node_type(first), "expression_statement") != 0) { |
| 1253 | return NULL; |
| 1254 | } |
| 1255 | if (ts_node_named_child_count(first) == 0) { |
| 1256 | return NULL; |
| 1257 | } |
| 1258 | TSNode str = ts_node_named_child(first, 0); |
| 1259 | if (ts_node_is_null(str)) { |
| 1260 | return NULL; |
| 1261 | } |
| 1262 | const char *sk = ts_node_type(str); |
| 1263 | if (strcmp(sk, "string") == 0 || strcmp(sk, "concatenated_string") == 0) { |
| 1264 | return extract_comment_text(a, str, source); |
| 1265 | } |
| 1266 | return NULL; |
| 1267 | } |
| 1268 | |
| 1269 | // Extract docstring from the node's leading comment. |
| 1270 | static const char *extract_docstring(CBMArena *a, TSNode node, const char *source, |
no test coverage detected