Struct tree_sitter::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 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 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§

impl PartialEq for Query

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
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, U> TryFrom<U> for T
where U: Into<T>,

§

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>,

§

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.