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

The last child anchor `.` in queries doesn't make any difference for a specific parser.

Open blindFS opened this issue 5 months ago • 1 comments

Problem

For the nushell parser.

Image

The query is supposed to match only the last element in the code, but matches both.

  • It fails for almost all node types of nushell
  • It works for some other parsers like bash

Steps to reproduce

  1. clone the parser repo
  2. tree-sitter generate
  3. tree-sitter query test.scm test.nu

test.scm:

(pipeline
  (pipe_element) @foo .)

test.nu

foo
| bar

output

  pattern: 0
    capture: 0 - foo, start: (0, 0), end: (0, 3), text: `foo`
  pattern: 0
    capture: 0 - foo, start: (1, 2), end: (1, 5), text: `bar`

Expected behavior

Only match the last pipe_element, bar in test.nu above.

Tree-sitter version (tree-sitter --version)

0.25.4

Operating system/version

macOS 15.5

blindFS avatar Jul 03 '25 22:07 blindFS

I'm running into the same issue with https://github.com/christoph-dfinity/tree-sitter-motoko

Image

Notably I also work around the same whitespace issue the nu parser is in their grammar.

christoph-dfinity avatar Aug 08 '25 10:08 christoph-dfinity