Add API for checking if a pattern in a query is non-local

This commit is contained in:
Max Brunsfeld 2023-02-15 18:24:07 -08:00
parent 40703f110c
commit 837899e456
5 changed files with 112 additions and 12 deletions

View file

@ -677,6 +677,9 @@ extern "C" {
length: *mut u32,
) -> *const TSQueryPredicateStep;
}
extern "C" {
pub fn ts_query_is_pattern_non_local(self_: *const TSQuery, pattern_index: u32) -> bool;
}
extern "C" {
pub fn ts_query_is_pattern_rooted(self_: *const TSQuery, pattern_index: u32) -> bool;
}

View file

@ -1736,11 +1736,17 @@ impl Query {
}
/// Check if a given pattern within a query has a single root node.
#[doc(alias = "ts_query_is_pattern_guaranteed_at_step")]
#[doc(alias = "ts_query_is_pattern_rooted")]
pub fn is_pattern_rooted(&self, index: usize) -> bool {
unsafe { ffi::ts_query_is_pattern_rooted(self.ptr.as_ptr(), index as u32) }
}
/// Check if a given pattern within a query has a single root node.
#[doc(alias = "ts_query_is_pattern_non_local")]
pub fn is_pattern_non_local(&self, index: usize) -> bool {
unsafe { ffi::ts_query_is_pattern_non_local(self.ptr.as_ptr(), index as u32) }
}
/// Check if a given step in a query is 'definite'.
///
/// A query step is 'definite' if its parent pattern will be guaranteed to match