ganezdragon / tree-sitter-perl

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

Oddities around "$c->stash->{otherEval}" #19

Closed lf- closed 1 year ago

lf- commented 2 years ago

There's some funny highlighting going on with the following snippet:

        $c->stash->{otherEval} = $eval2 if defined $eval2;

image

Note that the second brace is highlighted a different colour than the first.

Here is the AST from TSPlayground:

      single_line_statement [106, 8] - [106, 58]
        binary_expression [106, 8] - [106, 39]
          variable: hash_access_variable [106, 8] - [106, 30]
            hash_variable: method_invocation [106, 8] - [106, 17]
              object: scalar_variable [106, 8] - [106, 10]
              arrow_operator [106, 10] - [106, 12]
              function_name: identifier [106, 12] - [106, 17]
            "->{" [106, 17] - [106, 20]
            key: bareword [106, 20] - [106, 29]
            "}" [106, 29] - [106, 30]
          operator: "=" [106, 31] - [106, 32]
          variable: scalar_variable [106, 33] - [106, 39]
        if_simple_statement [106, 40] - [106, 58]
          "if" [106, 40] - [106, 42]
          condition: call_expression [106, 43] - [106, 57]
            function_name: identifier [106, 43] - [106, 50]
            args: argument [106, 51] - [106, 57]
              scalar_variable [106, 51] - [106, 57]
          semi_colon [106, 57] - [106, 58]

Code from: https://github.com/NixOS/hydra/blob/bab671124df0bc43a521d708bf86eece908d33af/src/lib/Hydra/Controller/Build.pm#L103-L108

Version: bbf86084d9b7eb4768f3fb9fe094b3e0600057b1

nvim-treesitter/parser-info - [master] » cat perl.revision
bbf86084d9b7eb4768f3fb9fe094b3e0600057b1
ganezdragon commented 1 year ago

I'm not able to replicate this. Is this still an issue?

(source_file [0, 0] - [0, 50]
  (single_line_statement [0, 0] - [0, 50]
    (binary_expression [0, 0] - [0, 31]
      variable: (hash_access_variable [0, 0] - [0, 22]
        hash_variable: (method_invocation [0, 0] - [0, 9]
          object: (scalar_variable [0, 0] - [0, 2])
          (arrow_operator [0, 2] - [0, 4])
          function_name: (identifier [0, 4] - [0, 9]))
        key: (bareword [0, 12] - [0, 21]))
      variable: (scalar_variable [0, 25] - [0, 31]))
    (if_simple_statement [0, 32] - [0, 50]
      condition: (call_expression [0, 35] - [0, 49]
        function_name: (identifier [0, 35] - [0, 42])
        args: (argument [0, 43] - [0, 49]
          (scalar_variable [0, 43] - [0, 49])))
      (semi_colon [0, 49] - [0, 50]))))
lf- commented 1 year ago

Oh, I see what's going on. The grammar emits an AST with the ->{ node as an anonymous node and the query doesn't consider it punctuation.bracket. It's a bug in the query, not in the parser, I think. Although the query's hands might be tied, in that it might be unable to split off the bracket there to turn it into a @punctuation.bracket.