Query depends on choice alternatives order
yuriv opened this issue · comments
yuriv commented
Problem
I have run (see attachment) tree-sitter query declarations.scm var0.c
and get no captures. But if you will change order of the choice: will move line (identifier) @identifier
to the start position you will get valid capture.
declaration.scm:
(translation_unit
...
declarator:
[
( (ms_call_modifier) @ms_call_modifier)?
[
; <---
(attributed_declarator) @attributed_declarator
(pointer_declarator) @pointer_declarator
(function_declarator) @function_declarator
(array_declarator) @array_declarator
(parenthesized_declarator) @parenthesized_declarator
(identifier) @identifier ; <--- this line from here to first position
]
( (gnu_asm_expression) @gnu_asm_expression)?
(init_declarator) @init_declarator
]
....
@declaration
)
Steps to reproduce
git clone https://github.com/tree-sitter/tree-sitter-c
cd tree-sitter-c
tree-sitter generate
gzip -d declarations.scm.gz var0.c.gz
tree-sitter query declarations.scm var0.c
Expected behavior
pattern: 0
capture: 15 - declaration, start: (0, 0), end: (0, 6), text: `int k;`
capture: 5 - _type_specifier, start: (0, 0), end: (0, 3), text: `int`
capture: 7 - identifier, start: (0, 4), end: (0, 5), text: `k`
Tree-sitter version (tree-sitter --version)
tree-sitter 0.22.2
Operating system/version
Rocky Linux 8.9
ObserverOfTime commented
Duplicate of #3239