feat: add field_name_for_named_child
This commit is contained in:
parent
8667e3ea0c
commit
7e3f572655
5 changed files with 109 additions and 1 deletions
|
|
@ -373,6 +373,13 @@ extern "C" {
|
|||
child_index: u32,
|
||||
) -> *const ::core::ffi::c_char;
|
||||
}
|
||||
extern "C" {
|
||||
#[doc = " Get the field name for node's named child at the given index, where zero\n represents the first named child. Returns NULL, if no field is found."]
|
||||
pub fn ts_node_field_name_for_named_child(
|
||||
self_: TSNode,
|
||||
named_child_index: u32,
|
||||
) -> *const ::core::ffi::c_char;
|
||||
}
|
||||
extern "C" {
|
||||
#[doc = " Get the node's number of children."]
|
||||
pub fn ts_node_child_count(self_: TSNode) -> u32;
|
||||
|
|
@ -642,7 +649,7 @@ extern "C" {
|
|||
pub fn ts_query_cursor_set_timeout_micros(self_: *mut TSQueryCursor, timeout_micros: u64);
|
||||
}
|
||||
extern "C" {
|
||||
#[doc = " Get the duration in microseconds that query execution is allowed to take."]
|
||||
#[doc = " Get the duration in microseconds that query execution is allowed to take.\n\n This is set via [`ts_query_cursor_set_timeout_micros`]."]
|
||||
pub fn ts_query_cursor_timeout_micros(self_: *const TSQueryCursor) -> u64;
|
||||
}
|
||||
extern "C" {
|
||||
|
|
|
|||
|
|
@ -1236,6 +1236,14 @@ impl<'tree> Node<'tree> {
|
|||
}
|
||||
}
|
||||
|
||||
/// Get the field name of this node's named child at the given index.
|
||||
pub fn field_name_for_named_child(&self, named_child_index: u32) -> Option<&'static str> {
|
||||
unsafe {
|
||||
let ptr = ffi::ts_node_field_name_for_named_child(self.0, named_child_index);
|
||||
(!ptr.is_null()).then(|| CStr::from_ptr(ptr).to_str().unwrap())
|
||||
}
|
||||
}
|
||||
|
||||
/// Iterate over this node's children.
|
||||
///
|
||||
/// A [`TreeCursor`] is used to retrieve the children efficiently. Obtain
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue