-
Notifications
You must be signed in to change notification settings - Fork 113
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
[question] How to check whether two SyntaxNodes are the same? #154
Comments
Regarding:
Just some ideas:
On a side note, I think the underlying C library has a way to directly compare two nodes for equality, but I didn't find any mention of |
Thanks, @sogaiu ! I switched to |
you can specify start and end points to query.captures(tree.rootNode, startPosition, endPosition); I'm interested in what you came up with |
@liaodalin19903 AFAIU, ordinary participants (me included) are not given the ability to label an issue (except when we create the issue, I think some labels may apply automatically). P.S. ahlinc no longer participates in this repository, may be better not to ping / tag him. |
I'm attempting to extract attributes of a certain type from a webpage, then reconstruct a JS object showing where they appeared in the original tree.
For example, I want to go from this input:
to
The language in question is https://github.com/phoenixframework/tree-sitter-heex and I'm using this query:
This correctly outputs the
['a', 'b', 'c', 'd']
, but there doesn't appear to be any obvious way to gather their relative positions to each other.What I've been trying to do is look at each matching capture's node and repeatedly use
.parent
and attempt to find a parent of one match that is the node from another match. But I can't figure out how to verify I've found the right node. And I suspect there's a better way... but documentation on tree-sitter is very sparse, especially on this node implementation. Comparing the text doesn't work, since the node text will have extraneous information (and it isn't guaranteed to be unique)It might even be possible to do this with the original query itself, but I didn't see anything in the documentation that suggested this would be possible.
The text was updated successfully, but these errors were encountered: