Skip to content

Commit 47aa0d7

Browse files
committed
feat(tree-sitter module): add previous sibling apis
1 parent 07a3eac commit 47aa0d7

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

crates/postgresql-cst-parser/src/tree_sitter.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,16 @@ impl<'a> Node<'a> {
186186
})
187187
}
188188

189+
pub fn prev_sibling(&self) -> Option<Node<'a>> {
190+
self.node_or_token
191+
.prev_sibling_or_token()
192+
.map(|sibling| Node {
193+
input: self.input,
194+
range_map: Rc::clone(&self.range_map),
195+
node_or_token: sibling,
196+
})
197+
}
198+
189199
pub fn parent(&self) -> Option<Node<'a>> {
190200
self.node_or_token.parent().map(|parent| Node {
191201
input: self.input,
@@ -246,6 +256,15 @@ impl<'a> TreeCursor<'a> {
246256
}
247257
}
248258

259+
pub fn goto_prev_sibling(&mut self) -> bool {
260+
if let Some(sibling) = self.node_or_token.prev_sibling_or_token() {
261+
self.node_or_token = sibling;
262+
true
263+
} else {
264+
false
265+
}
266+
}
267+
249268
pub fn is_comment(&self) -> bool {
250269
matches!(
251270
self.node_or_token.kind(),

0 commit comments

Comments
 (0)