tree-sitter-grammars / tree-sitter-query

TS query grammar for tree-sitter
Apache License 2.0
52 stars 14 forks source link

Error in legal expression with anchor #26

Closed theHamsta closed 8 months ago

theHamsta commented 1 year ago
(function_declaration
  (import_path
    ((identifier) @function .)))

@clason @amaanq could this be the reason why Topiary formatting has problems with some anchor expressions

named_node [0, 0] - [2, 32]
  name: identifier [0, 1] - [0, 21]
  named_node [1, 2] - [2, 31]
    name: identifier [1, 3] - [1, 14]
    grouping [2, 4] - [2, 30]
      named_node [2, 5] - [2, 27]
        name: identifier [2, 6] - [2, 16]
        capture [2, 18] - [2, 27]
          name: identifier [2, 19] - [2, 27]
      ERROR [2, 28] - [2, 29]
clason commented 1 year ago

Topiary is handling anchors correctly; it's query-fmt that mangles them (due to lack of explicit handling).

clason commented 1 year ago

Is that even valid (trailing anchor)?

theHamsta commented 1 year ago

Is that even valid (trailing anchor)?

It should be. It means the last named node of a parent (at least it gets interpreted as such). See https://github.com/nvim-treesitter/nvim-treesitter/pull/5151

theHamsta commented 1 year ago

grafik