-
Notifications
You must be signed in to change notification settings - Fork 95
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
Cyclic path in the parse tree #119
Comments
I think this is a bug in the For now, my suggested workaround is to not use the I've also considered simply removing the parent and sibling APIs, so that the tree cursor would be the only way to walk the tree in an upward fashion. |
Thanks. Pardon my ignorance, but I wonder how could you traverse the parse tree backwards with a cursor? That would be useful for, eg, searching for a BTW, just to make sure I'm not missing anything, if I want to traverse the parse tree and find a TSNode node;
...traverse in a loop {
node = ts_tree_cursor_current_node(cursor)
(check for node's type)
} |
Yes, exactly. The tree cursor lets you retrieve nodes as you walk the tree. |
Thanks, but how about traversing backwards in the tree with a cursor? That would be useful for, eg, searching for a |
Ok, I looked at the source of |
In at least one context — emacs with Test results here. Perhaps the current emacs 29 implementation of node-parent using cursors is sub-optimal in some way? |
I encountered a case where a node's sibling's parent is the node itself. I don't know if this is a tree-sitter bug or a tree-sitter-c bug, but here it is:
For a program like this:
the parse tree is
And if we go from the semicolon, first find its next sibling, which is the
#endif
, then the parent of#endif
, and we are back at the semicolon.To reproduce, try the following python script. (
libtree-sitter-c.dylib
needs to be in the same directory as the script.) I'm using tree-sitter-c built from latest master, and python's tree-sitter binding on PyPI, so 0.20.1. I first observed this in Emacs, and it uses tree-sitter v0.20.7.which evaluates to True.
The text was updated successfully, but these errors were encountered: