Start work on exposing APIs for node descendant counts and indices
This commit is contained in:
parent
2a9d951cd6
commit
9dd725b4e3
9 changed files with 502 additions and 72 deletions
|
|
@ -1121,6 +1121,12 @@ impl<'tree> Node<'tree> {
|
|||
Self::new(unsafe { ffi::ts_node_prev_named_sibling(self.0) })
|
||||
}
|
||||
|
||||
/// Get the node's number of descendants, including one for the node itself.
|
||||
#[doc(alias = "ts_node_descendant_count")]
|
||||
pub fn descendant_count(&self) -> usize {
|
||||
unsafe { ffi::ts_node_descendant_count(self.0) as usize }
|
||||
}
|
||||
|
||||
/// Get the smallest node within this node that spans the given range.
|
||||
#[doc(alias = "ts_node_descendant_for_byte_range")]
|
||||
pub fn descendant_for_byte_range(&self, start: usize, end: usize) -> Option<Self> {
|
||||
|
|
@ -1287,6 +1293,16 @@ impl<'a> TreeCursor<'a> {
|
|||
return unsafe { ffi::ts_tree_cursor_goto_next_sibling(&mut self.0) };
|
||||
}
|
||||
|
||||
/// Move the cursor to the node that is the nth descendant of
|
||||
/// the original node that the cursor was constructed with, where
|
||||
/// zero represents the original node itself.
|
||||
#[doc(alias = "ts_tree_cursor_goto_descendant")]
|
||||
pub fn goto_descendant(&mut self, descendant_index: usize) {
|
||||
return unsafe {
|
||||
ffi::ts_tree_cursor_goto_descendant(&mut self.0, descendant_index as u32)
|
||||
};
|
||||
}
|
||||
|
||||
/// Move this cursor to the first child of its current node that extends beyond
|
||||
/// the given byte offset.
|
||||
///
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue