Skip to main content

Query

Struct Query 

Source
pub struct Query { /* private fields */ }
Expand description

A set of patterns that match nodes in a syntax tree.

Implementations§

Source§

impl Query

Source

pub unsafe fn from_raw( ptr: *mut TSQuery, source: &str, ) -> Result<Self, QueryError>

Reconstructs a Query from a raw pointer.

§Safety

ptr must be non-null.

Source

pub fn into_raw(self) -> *mut TSQuery

Consumes the Query, returning a raw pointer to the underlying C structure.

Source§

impl Query

Source

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.

Source

pub fn new_raw( language: &Language, source: &str, ) -> Result<*mut TSQuery, QueryError>

Constructs a raw TSQuery pointer without performing extra checks specific to the rust bindings, such as predicate validation. A Query object can be constructed from the returned pointer using from_raw_parts. The caller is responsible for ensuring that the returned pointer is eventually freed by calling ts_query_delete.

Source

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.

Source

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.

Source

pub fn pattern_count(&self) -> usize

Get the number of patterns in the query.

Source

pub const fn capture_names(&self) -> &[&str]

Get the names of the captures used in the query.

Source

pub const fn capture_quantifiers(&self, index: usize) -> &[CaptureQuantifier]

Get the quantifiers of the captures used in the query.

Source

pub fn capture_index_for_name(&self, name: &str) -> Option<u32>

Get the index for a given capture name.

Source

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?.

Source

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!.

Source

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? and not-eq?
  • is? and is-not?
  • set!
Source

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.

Source

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.

Source

pub fn is_pattern_rooted(&self, index: usize) -> bool

Check if a given pattern within a query has a single root node.

Source

pub fn is_pattern_non_local(&self, index: usize) -> bool

Check if a given pattern within a query has a single root node.

Source

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§

Source§

impl Debug for Query

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Drop for Query

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more
Source§

impl PartialEq for Query

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl Send for Query

Source§

impl Sync for Query

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.