Query

Struct Query 

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

Implementations§

Source§

impl Query

Source

pub fn new( grammar: Grammar, source: &str, custom_predicate: impl FnMut(Pattern, UserPredicate<'_>) -> Result<(), InvalidPredicateError>, ) -> Result<Self, ParseError>

Create a new query from a string containing one or more S-expression patterns.

The query is associated with a particular grammar, and can only be run on syntax nodes parsed with that grammar. References to Queries can be shared between multiple threads.

Source

pub fn capture_name(&self, capture_idx: Capture) -> &str

Source

pub fn captures(&self) -> impl ExactSizeIterator<Item = (Capture, &str)>

Source

pub fn num_captures(&self) -> u32

Source

pub fn get_capture(&self, capture_name: &str) -> Option<Capture>

Source

pub fn start_byte_for_pattern(&self, pattern: Pattern) -> 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 fn patterns(&self) -> impl ExactSizeIterator<Item = Pattern>

Get the number of patterns in the query.

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. Currently, there is no way to undo this.

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

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.