tree-sitter-python icon indicating copy to clipboard operation
tree-sitter-python copied to clipboard

Difference in fields between parameters

Open Qwarctick opened this issue 1 year ago • 2 comments

If I have this code:

def func(first, second: str, third = 7, four: int = 1):
    print()

I got the following abstract tree:

module [0, 0] - [2, 0]
  function_definition [0, 0] - [1, 11]
    name: identifier [0, 4] - [0, 8]
    parameters: parameters [0, 8] - [0, 54]
      identifier [0, 9] - [0, 14]
      typed_parameter [0, 16] - [0, 27]
        identifier [0, 16] - [0, 22]
        type: type [0, 24] - [0, 27]
          identifier [0, 24] - [0, 27]
      default_parameter [0, 29] - [0, 38]
        name: identifier [0, 29] - [0, 34]
        value: integer [0, 37] - [0, 38]
      typed_default_parameter [0, 40] - [0, 53]
        name: identifier [0, 40] - [0, 44]
        type: type [0, 46] - [0, 49]
          identifier [0, 46] - [0, 49]
        value: integer [0, 52] - [0, 53]
    body: block [1, 4] - [1, 11]
      expression_statement [1, 4] - [1, 11]
        call [1, 4] - [1, 11]
          function: identifier [1, 4] - [1, 9]
          arguments: argument_list [1, 9] - [1, 11]

My question is: Why is the first parameter and typed_parameter does not have a name field like default_parameter and typed_default_parameter. Or in the other way, why default_parameter and typed_default_parameter need a name field ?

Is there any reason to this design ?

Maybe it's possible to homogenize all this.

Qwarctick avatar Feb 21 '23 16:02 Qwarctick