pub struct Query { /* private fields */ }
Expand description
A set of patterns that match nodes in a syntax tree.
Implementations§
Source§impl Query
impl Query
Sourcepub fn new(language: &Language, source: &str) -> Result<Self, QueryError>
pub fn new(language: &Language, source: &str) -> Result<Self, QueryError>
Create a new query from a string containing one or more S-expression patterns.
The query is associated with a particular language, and can only be run on syntax nodes parsed with that language. References to Queries can be shared between multiple threads.
Sourcepub fn start_byte_for_pattern(&self, pattern_index: usize) -> usize
pub fn start_byte_for_pattern(&self, pattern_index: usize) -> usize
Get the byte offset where the given pattern starts in the query’s source.
Sourcepub fn end_byte_for_pattern(&self, pattern_index: usize) -> usize
pub fn end_byte_for_pattern(&self, pattern_index: usize) -> usize
Get the byte offset where the given pattern ends in the query’s source.
Sourcepub fn pattern_count(&self) -> usize
pub fn pattern_count(&self) -> usize
Get the number of patterns in the query.
Sourcepub const fn capture_names(&self) -> &[&str]
pub const fn capture_names(&self) -> &[&str]
Get the names of the captures used in the query.
Sourcepub const fn capture_quantifiers(&self, index: usize) -> &[CaptureQuantifier]
pub const fn capture_quantifiers(&self, index: usize) -> &[CaptureQuantifier]
Get the quantifiers of the captures used in the query.
Sourcepub fn capture_index_for_name(&self, name: &str) -> Option<u32>
pub fn capture_index_for_name(&self, name: &str) -> Option<u32>
Get the index for a given capture name.
Sourcepub const fn property_predicates(
&self,
index: usize,
) -> &[(QueryProperty, bool)]
pub const fn property_predicates( &self, index: usize, ) -> &[(QueryProperty, bool)]
Get the properties that are checked for the given pattern index.
This includes predicates with the operators is?
and is-not?
.
Sourcepub const fn property_settings(&self, index: usize) -> &[QueryProperty]
pub const fn property_settings(&self, index: usize) -> &[QueryProperty]
Get the properties that are set for the given pattern index.
This includes predicates with the operator set!
.
Sourcepub const fn general_predicates(&self, index: usize) -> &[QueryPredicate]
pub const fn general_predicates(&self, index: usize) -> &[QueryPredicate]
Get the other user-defined predicates associated with the given index.
This includes predicate with operators other than:
match?
eq?
andnot-eq?
is?
andis-not?
set!
Sourcepub fn disable_capture(&mut self, name: &str)
pub fn disable_capture(&mut self, name: &str)
Disable a certain capture within a query.
This prevents the capture from being returned in matches, and also avoids any resource usage associated with recording the capture.
Sourcepub fn disable_pattern(&mut self, index: usize)
pub fn disable_pattern(&mut self, index: usize)
Disable a certain pattern within a query.
This prevents the pattern from matching, and also avoids any resource usage associated with the pattern.
Sourcepub fn is_pattern_rooted(&self, index: usize) -> bool
pub fn is_pattern_rooted(&self, index: usize) -> bool
Check if a given pattern within a query has a single root node.
Sourcepub fn is_pattern_non_local(&self, index: usize) -> bool
pub fn is_pattern_non_local(&self, index: usize) -> bool
Check if a given pattern within a query has a single root node.
Sourcepub fn is_pattern_guaranteed_at_step(&self, byte_offset: usize) -> bool
pub fn is_pattern_guaranteed_at_step(&self, byte_offset: usize) -> bool
Check if a given step in a query is ‘definite’.
A query step is ‘definite’ if its parent pattern will be guaranteed to match successfully once it reaches the step.
Trait Implementations§
impl Send for Query
impl Sync for Query
Auto Trait Implementations§
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more