pub struct QueryEngine { /* private fields */ }Expand description
Engine for executing tree-sitter queries against parsed Rust source.
Implementations§
Source§impl QueryEngine
impl QueryEngine
Sourcepub fn new(query_str: &str) -> Result<Self, TreeSitterError>
pub fn new(query_str: &str) -> Result<Self, TreeSitterError>
Create a new query engine from a tree-sitter query string.
§Query Syntax
Tree-sitter queries use S-expression syntax:
(function_item
name: (identifier) @func_name
body: (block) @body)Captures are prefixed with @ and can be referenced by name.
Sourcepub fn find_all<'a>(&self, parsed: &'a ParsedSource<'a>) -> Vec<QueryMatch>
pub fn find_all<'a>(&self, parsed: &'a ParsedSource<'a>) -> Vec<QueryMatch>
Execute the query against parsed source and return all matches.
Sourcepub fn find_unique<'a>(
&self,
parsed: &'a ParsedSource<'a>,
) -> Result<QueryMatch, TreeSitterError>
pub fn find_unique<'a>( &self, parsed: &'a ParsedSource<'a>, ) -> Result<QueryMatch, TreeSitterError>
Execute the query and expect exactly one match.
Sourcepub fn capture_names(&self) -> &[String]
pub fn capture_names(&self) -> &[String]
Get capture names defined in the query.
Auto Trait Implementations§
impl Freeze for QueryEngine
impl RefUnwindSafe for QueryEngine
impl Send for QueryEngine
impl Sync for QueryEngine
impl Unpin for QueryEngine
impl UnsafeUnpin for QueryEngine
impl UnwindSafe for QueryEngine
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more