From ea6f3a9568223b554c7c4434051859c335dcff2a Mon Sep 17 00:00:00 2001 From: Taus Date: Wed, 13 May 2026 13:20:58 +0000 Subject: [PATCH] unified: Encapsulate function parameters The field representation would have made it difficult to figure out which parameters correspond to which default values and attributes, so instead we now encapsulate these in a new `function_parameter` node. --- .../extractor/tree-sitter-swift/grammar.js | 4 ++-- .../tree-sitter-swift/node-types.yml | 24 +++++++------------ 2 files changed, 11 insertions(+), 17 deletions(-) diff --git a/unified/extractor/tree-sitter-swift/grammar.js b/unified/extractor/tree-sitter-swift/grammar.js index 2112413b0c6..50c1a08c66c 100644 --- a/unified/extractor/tree-sitter-swift/grammar.js +++ b/unified/extractor/tree-sitter-swift/grammar.js @@ -1611,9 +1611,9 @@ module.exports = grammar({ ), _function_value_parameters: ($) => repeat1( - seq("(", optional(sep1Opt($._function_value_parameter, ",")), ")") + seq("(", optional(sep1Opt(field("parameter", $.function_parameter), ",")), ")") ), - _function_value_parameter: ($) => + function_parameter: ($) => seq( field("attribute", optional($.attribute)), field("parameter", $.parameter), diff --git a/unified/extractor/tree-sitter-swift/node-types.yml b/unified/extractor/tree-sitter-swift/node-types.yml index 125a26a7679..1f2e27ea337 100644 --- a/unified/extractor/tree-sitter-swift/node-types.yml +++ b/unified/extractor/tree-sitter-swift/node-types.yml @@ -305,17 +305,19 @@ named: fully_open_range: function_declaration: async?: "async" - attribute*: attribute body: block - default_value*: expression modifiers*: [attribute, inheritance_modifier, modifiers, ownership_modifier, property_behavior_modifier] name: [referenceable_operator, simple_identifier] - parameter*: parameter + parameter*: function_parameter return_type?: [implicitly_unwrapped_type, type] throws?: [throws, throws_clause] type_constraints?: type_constraints type_parameters?: type_parameters function_modifier: + function_parameter: + attribute?: attribute + default_value?: expression + parameter: parameter function_type: async?: "async" params: unannotated_type @@ -361,13 +363,11 @@ named: inherits_from: [function_type, suppressed_constraint, user_type] init_declaration: async?: "async" - attribute*: attribute bang?: bang body?: block - default_value*: expression modifiers?: modifiers name: "init" - parameter*: parameter + parameter*: function_parameter throws?: [throws, throws_clause] type_constraints?: type_constraints type_parameters?: type_parameters @@ -410,12 +410,10 @@ named: interpolation*: interpolated_expression text*: [line_str_text, str_escaped_char] macro_declaration: - attribute*: attribute - default_value*: expression definition?: macro_definition modifiers?: modifiers name: simple_identifier - parameter*: parameter + parameter*: function_parameter return_type?: unannotated_type type_constraints?: type_constraints type_parameters?: type_parameters @@ -527,12 +525,10 @@ named: type_parameters?: type_parameters protocol_function_declaration: async?: "async" - attribute*: attribute body?: block - default_value*: expression modifiers?: modifiers name: [referenceable_operator, simple_identifier] - parameter*: parameter + parameter*: function_parameter return_type?: [implicitly_unwrapped_type, type] throws?: [throws, throws_clause] type_constraints?: type_constraints @@ -584,11 +580,9 @@ named: statement_label: str_escaped_char: subscript_declaration: - attribute*: attribute body: computed_property - default_value*: expression modifiers?: modifiers - parameter*: parameter + parameter*: function_parameter return_type?: [implicitly_unwrapped_type, type] type_constraints?: type_constraints type_parameters?: type_parameters