pub struct Query<Q> {
pub raw: Q,
pub capture_names: Vec<String>,
pub patterns: Vec<Pattern>,
pub metadata: Vec<Metadata>,
}Expand description
A compiled query and its metadata in the shared format.
Fields§
§raw: QRuntime-specific compiled query.
capture_names: Vec<String>Capture names indexed by crate::backend::Capture::index.
patterns: Vec<Pattern>Pattern metadata indexed by Match::pattern.
metadata: Vec<Metadata>Metadata required for each capture across all query patterns.
Implementations§
Source§impl<Q> Query<Q>
impl<Q> Query<Q>
Sourcepub fn new(raw: Q, capture_names: Vec<String>, patterns: Vec<Pattern>) -> Self
pub fn new(raw: Q, capture_names: Vec<String>, patterns: Vec<Pattern>) -> Self
Store a compiled query and determine the node metadata each capture needs.
Sourcepub fn matches<B: Backend<Query = Q>>(
&self,
backend: &mut B,
tree: &B::Tree,
source: &str,
) -> Result<Vec<Match>, Error>
pub fn matches<B: Backend<Query = Q>>( &self, backend: &mut B, tree: &B::Tree, source: &str, ) -> Result<Vec<Match>, Error>
Run a query and filter its matches. Empty queries skip runtime execution.
§Errors
Returns runtime, predicate, or invalid-range errors.
Sourcepub fn filtered(
&self,
matches: Vec<Match>,
source: &str,
) -> Result<Vec<Match>, Error>
pub fn filtered( &self, matches: Vec<Match>, source: &str, ) -> Result<Vec<Match>, Error>
Validate captures, filter custom predicates, and apply capture offsets.
Reuses the input vector and preserves the order of accepted matches. Input indices must refer to this query.
§Errors
Returns Error::InvalidRange for invalid source boundaries or offsets.
§Panics
Panics if a match references a pattern outside Self::patterns.