Extract param_names from a parameter list node. Returns NULL-terminated arena-allocated array. Extract the parameter name from a single parameter AST node.
| 4613 | // Returns NULL-terminated arena-allocated array. |
| 4614 | // Extract the parameter name from a single parameter AST node. |
| 4615 | static char *resolve_param_name(CBMArena *a, TSNode param, const char *source) { |
| 4616 | const char *pk = ts_node_type(param); |
| 4617 | |
| 4618 | if (strcmp(pk, "argument") == 0 || strcmp(pk, "tag_parameter") == 0) { |
| 4619 | TSNode name = find_first_descendant_by_kind(param, "objectscript_identifier", 6); |
| 4620 | if (ts_node_is_null(name)) { |
| 4621 | name = find_first_descendant_by_kind(param, "objectscript_identifier_special", 6); |
| 4622 | } |
| 4623 | return ts_node_is_null(name) ? NULL : cbm_node_text(a, name, source); |
| 4624 | } |
| 4625 | |
| 4626 | if (strcmp(pk, "parameter_declaration") == 0) { |
| 4627 | TSNode nm = ts_node_child_by_field_name(param, TS_FIELD("name")); |
| 4628 | if (!ts_node_is_null(nm)) { |
| 4629 | return cbm_node_text(a, nm, source); |
| 4630 | } |
| 4631 | return NULL; |
| 4632 | } |
| 4633 | if (strcmp(pk, "identifier") == 0) { |
| 4634 | return cbm_node_text(a, param, source); |
| 4635 | } |
| 4636 | if (strcmp(pk, "formal_parameter") == 0 || strcmp(pk, "parameter") == 0 || |
| 4637 | strcmp(pk, "required_parameter") == 0 || strcmp(pk, "optional_parameter") == 0 || |
| 4638 | strcmp(pk, "simple_parameter") == 0 || strcmp(pk, "typed_parameter") == 0 || |
| 4639 | strcmp(pk, "default_parameter") == 0 || strcmp(pk, "typed_default_parameter") == 0) { |
| 4640 | TSNode nm = ts_node_child_by_field_name(param, TS_FIELD("name")); |
| 4641 | if (ts_node_is_null(nm)) { |
| 4642 | nm = ts_node_child_by_field_name(param, TS_FIELD("pattern")); |
| 4643 | } |
| 4644 | if (!ts_node_is_null(nm)) { |
| 4645 | if (strcmp(ts_node_type(nm), "identifier") == 0 || |
| 4646 | strcmp(ts_node_type(nm), "simple_identifier") == 0) { |
| 4647 | return cbm_node_text(a, nm, source); |
| 4648 | } |
| 4649 | } |
| 4650 | } |
| 4651 | return NULL; |
| 4652 | } |
| 4653 | |
| 4654 | static const char **extract_param_names(CBMArena *a, TSNode params, const char *source, |
| 4655 | CBMLanguage lang) { |
no test coverage detected