Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Recursive nodes are difficult to match in queries #24

Open
tmillr opened this issue May 11, 2023 · 1 comment
Open

Recursive nodes are difficult to match in queries #24

tmillr opened this issue May 11, 2023 · 1 comment

Comments

@tmillr
Copy link

tmillr commented May 11, 2023

Is it at all possible for recursive nodes such as dot_index_expression and method_index_expression to be changed to be sequential?

Currently, there doesn't appear to be a way to captures nodes recursively (only sequentially with * and +) in treesitter queries, leading to having to resort to queries with "manual" recursion up to a "limited" depth like the following: https://github.com/projekt0n/github-nvim-theme/pull/250/files

For example, since dot_index_expression nodes currently nest recursively when multiple instances of them appear side-by-side in the code, it is not possible to capture any of its child nodes beyond the 1st level without resorting to such manual recursion as shown in the link above, whereas if they were sequential, I could simply use tresitter's + or * repetitions/quantifiers to distinctively capture these nodes, and their non-recursive children, up to arbitrary lengths.

-- E.g. in a query, how could I capture all "." nodes appearing within a
--`dot_index_expression` that are themselves within `function_declaration` names?
function tbl.x.y.z() end
function tbl.x.y:z() end
-- etc.

Is there a good reason why they are recursive? Is it only so that multiple of them can fit under a single ts field?

Unfortunately, I imagine this would be a breaking change, if it even can be changed.

Also see

@MunifTanjim
Copy link
Collaborator

Is there a good reason why they are recursive?

That's the structure that conveys their meaning well. Many other languages does the same thing, e.g. ecma (javascript, typescript), go, python, rust, most others.


This seems like a limitation of the query language. So I think tree-sitter/tree-sitter#880 is actually the right place to raise it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants