Skip to main content

CompiledQuery

Struct CompiledQuery 

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

A query compiled against one language’s grammar.

Implementations§

Source§

impl CompiledQuery

Source

pub fn compile( language: &dyn Language, source: &str, ) -> Result<Self, CompileError>

Compile query source against a language.

§Errors

Returns CompileError for malformed syntax, unknown node kinds or fields, and for a query that binds no captures.

Source

pub const fn language(&self) -> LanguageId

The language this query was compiled against.

Source

pub fn capture_names(&self) -> &[String]

Capture names, in capture-index order.

Source

pub fn pattern_count(&self) -> usize

How many alternative patterns the query contains.

Source

pub fn for_each_match<'tree>( &self, tree: &'tree Tree, source: &[u8], visit: impl FnMut(QueryMatch<'_, 'tree>), )

Run the query over a tree, invoking visit once per match.

A callback rather than an iterator, and rather than returning a Vec: matches borrow the tree, and collecting them would allocate for every match on the hot path this crate exists to keep cheap.

Matches arrive in the order tree-sitter walks the tree, which is deterministic for a given tree and query. Nothing downstream may depend on that order beyond determinism itself — violations are sorted before reporting regardless.

Source

pub fn for_each_match_in<'tree>( &self, node: Node<'tree>, source: &[u8], visit: impl FnMut(QueryMatch<'_, 'tree>), )

The same, scoped to one node’s subtree.

What ctx.querySubtree is built on: a rule that has already matched a function and wants to look inside it should not have to filter the whole file’s matches by position, which is both slower and easy to get subtly wrong at boundaries.

Trait Implementations§

Source§

impl Debug for CompiledQuery

Source§

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

Formats the value using the given formatter. Read more

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> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. 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.