A call to syntax_node.prev_sibling() returns actually the node two nodes before itself instead of the one before it.
I found out that syntax_node.prev_sibling_or_token works as expected and finds also the previous node.
To illustrate this issue, take the following tree of syntax nodes (only nodes, not tokens):
Root
A
B
C
The calls to prev_sibling and prev_sibling_or_token report the following (per current node)
A
prev_sibling=None
prev_sibling_or_token=None
B
prev_sibling=None
prev_sibling_or_token=Some(Node(A))
C
prev_sibling=Some(A)
prev_sibling_or_token=Some(Node(B))
I found this by working with the rowan syntax trees in my rewrite of ( https://github.com/MalteJanz/ludtwig/tree/bachelor-thesis ) where I use rowan ( still in a very early state ). Parsing is done by the GreenNodeBuilder (abstracted away behind a sink / events). I have not yet found the time to produce a minimal reproducible example, so it would be nice if someone can confirm this behaviour in their rowan syntax trees or proof me wrong in my understanding of the function 🙈 .
I guess I already found the underlaying issue and will submit a PR shortly (offset by one error in src/cursor.rs line 393) 🙂.
A call to
syntax_node.prev_sibling()
returns actually the node two nodes before itself instead of the one before it. I found out thatsyntax_node.prev_sibling_or_token
works as expected and finds also the previous node.To illustrate this issue, take the following tree of syntax nodes (only nodes, not tokens):
The calls to
prev_sibling
andprev_sibling_or_token
report the following (per current node)I found this by working with the rowan syntax trees in my rewrite of ( https://github.com/MalteJanz/ludtwig/tree/bachelor-thesis ) where I use rowan ( still in a very early state ). Parsing is done by the
GreenNodeBuilder
(abstracted away behind a sink / events). I have not yet found the time to produce a minimal reproducible example, so it would be nice if someone can confirm this behaviour in their rowan syntax trees or proof me wrong in my understanding of the function 🙈 .I guess I already found the underlaying issue and will submit a PR shortly (offset by one error in
src/cursor.rs
line 393) 🙂.