feat: reverse iteration through node parents (#3214)
This commit is contained in:
parent
0f125e2d09
commit
90e0e28b95
5 changed files with 84 additions and 24 deletions
|
|
@ -355,9 +355,13 @@ extern "C" {
|
|||
pub fn ts_node_next_parse_state(self_: TSNode) -> TSStateId;
|
||||
}
|
||||
extern "C" {
|
||||
#[doc = " Get the node's immediate parent."]
|
||||
#[doc = " Get the node's immediate parent.\n Prefer [`ts_node_child_containing_descendant`] for\n iterating over the node's ancestors."]
|
||||
pub fn ts_node_parent(self_: TSNode) -> TSNode;
|
||||
}
|
||||
extern "C" {
|
||||
#[doc = " Get the node's child that contains `descendant`."]
|
||||
pub fn ts_node_child_containing_descendant(self_: TSNode, descendant: TSNode) -> TSNode;
|
||||
}
|
||||
extern "C" {
|
||||
#[doc = " Get the node's child at the given index, where zero represents the first\n child."]
|
||||
pub fn ts_node_child(self_: TSNode, child_index: u32) -> TSNode;
|
||||
|
|
|
|||
|
|
@ -1331,12 +1331,21 @@ impl<'tree> Node<'tree> {
|
|||
}
|
||||
|
||||
/// Get this node's immediate parent.
|
||||
/// Prefer [`child_containing_descendant`](Node::child_containing_descendant)
|
||||
/// for iterating over this node's ancestors.
|
||||
#[doc(alias = "ts_node_parent")]
|
||||
#[must_use]
|
||||
pub fn parent(&self) -> Option<Self> {
|
||||
Self::new(unsafe { ffi::ts_node_parent(self.0) })
|
||||
}
|
||||
|
||||
/// Get this node's child that contains `descendant`.
|
||||
#[doc(alias = "ts_node_child_containing_descendant")]
|
||||
#[must_use]
|
||||
pub fn child_containing_descendant(&self, descendant: Self) -> Option<Self> {
|
||||
Self::new(unsafe { ffi::ts_node_child_containing_descendant(self.0, descendant.0) })
|
||||
}
|
||||
|
||||
/// Get this node's next sibling.
|
||||
#[doc(alias = "ts_node_next_sibling")]
|
||||
#[must_use]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue