ganezdragon / tree-sitter-perl

a perl parser for javascript
MIT License
33 stars 9 forks source link

function call argument parse structure #23

Closed pokey closed 1 year ago

pokey commented 1 year ago

The parse tree for function call arguments is a bit tough to use, because all the arguments get wrapped up in a single node called argument

https://github.com/ganezdragon/tree-sitter-perl/blob/ff1f0ac0f1c678a23f68d0140e75a0da8e11b7b5/grammar.js#L1454-L1457

It would be nice to have one argument node per argument. Something like the following

    _arguments: $ => prec.left(PRECEDENCE.SUB_ARGS, choice(
      $._key_value_pair,
      commaSeparated($.argument),
    )),
    argument: $ => choice($._dereference, $._expression),
ganezdragon commented 1 year ago

Let me work on this, this weekend

ganezdragon commented 1 year ago

the latest commit should create a graph for a function like main($sfds, $sdfs);, as follows

  (call_expression [11, 0] - [11, 18]
    function_name: (identifier [11, 0] - [11, 4])
    args: (parenthesized_argument [11, 4] - [11, 18]
      (arguments [11, 5] - [11, 17]
        (argument [11, 5] - [11, 10]
          (scalar_variable [11, 5] - [11, 10]))
        (argument [11, 12] - [11, 17]
          (scalar_variable [11, 12] - [11, 17])))))
  (semi_colon [11, 18] - [11, 19])

let me know if this could be closed.

pokey commented 1 year ago

Looks pretty good to me; @Leeft wdyt?

Leeft commented 1 year ago

Looks fab to me @pokey ty @ganezdragon