Duplicate Captures #2586
-
Hi! I have already read through the other posts about this, and none of them seem to be like my case. I am using web-tree-sitter, and it gives me different results from what the rust CLI gives me during testing. Source string:
Parse tree:
Query:
The result using the rust cli:
Result using web-tree-sitter:queries.module.captures(tree.rootNode).map(s => s.node.text)
=> ['core', 'core', 'core', 'events', 'events', 'events']
// also, the node ids and capture names are the same within each group of three. However, if I use Could this be a problem with web-tree-sitter or am I doing something wrong? All the other posts on here were missing an anchor or something, but I don't think this is the case here. When using a quantifier (like |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
Intuitively, it would make sense if this expression matches subsets of a list of identifiers, but that is not the case for the CLI, which is why I was confused about the web-tree-sitter case. Maybe using matches instead of captures is the right thing to do anyway? Now that I think about it in that way, that sounds reasonable. |
Beta Was this translation helpful? Give feedback.
-
Don't mix captures and matches modes, that was the main mistake. Your original issue reproducible with CLI so it's not a bug in the web binding: In the matches mode your original query works as you expected: You need to properly construct your queries, on the bellow screenshot there are fixed queries for both captures and matches modes. Keep in mind that queries for the matches mode may not work well for the captures mode. Also be attentive when you use underscore placeholders, usually it's better to use explicit node names and especially for string literal terminals. |
Beta Was this translation helpful? Give feedback.
Don't mix captures and matches modes, that was the main mistake.
Your original issue reproducible with CLI so it's not a bug in the web binding:
In the matches mode your original query works as you expected:
You need to properly construct your queries, on the bellow screenshot there are fixed queries for both captures and matches modes. Keep in mind that queries for the matches mode may not work well for the captures mode. Also be attentive when you use underscore placeholders, usually it's better to use explicit node names and especially for string literal terminals.