-
Notifications
You must be signed in to change notification settings - Fork 107
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
Query to match all declarations (def) and identifiers (uses) in the code #88
Comments
Could you provide a complete snippet of code and a query that work in Tree-sitter playground? |
Here they are: Code in TypeScript:
Query to get some def-uses:
I have noticed that for each language, the query is different, I am wondering for typescript here, is it possible to have a simpler query to match all defs and uses? (Maybe it is not a good idea, I feel that writing such queries are tedious but clear to read!) |
I saw somehere in the issues the author's thounghts that in future there may be a work on standartization to make queries portable, for now all languages defined in own terms what requires different queries. |
It's better to define queries as a series of small queries organized in a batch than try to organize all in a big one query. Tree-sitter's query engine executes all queries in a butch concurently and also this opens possibility to combine small queries in different ways. |
I am using node-tree-sitter to query all def-uses in the code, in the following way:
However, it returns keywords that I do not want. For example,
For code:
It returns:
After reading the query syntax (http://tree-sitter.github.io/tree-sitter/using-parsers#query-syntax) and the test code (https://github.com/tree-sitter/node-tree-sitter/blob/master/test/query_test.js), I am wondering:
(_declaration: name (identifier))
?(_) name: (identifier)
?The text was updated successfully, but these errors were encountered: