Fix bug where patterns with top-level alternatives were not considered 'rooted'

This commit is contained in:
Max Brunsfeld 2022-07-07 17:25:49 -07:00
parent 1401767689
commit 548c12fb88
5 changed files with 169 additions and 22 deletions

View file

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

View file

@ -1699,6 +1699,12 @@ impl Query {
unsafe { ffi::ts_query_disable_pattern(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_guaranteed_at_step")]
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 step in a query is 'definite'.
///
/// A query step is 'definite' if its parent pattern will be guaranteed to match