pub trait LanguageParser: Send + Sync {
// Required methods
fn language(&self) -> Language;
fn extensions(&self) -> &[&str];
fn extract_nodes(
&self,
tree: &Tree,
source: &str,
file_path: &str,
) -> Vec<CodeNode>;
// Provided methods
fn extract_usages(
&self,
_tree: &Tree,
_source: &str,
_file_path: &str,
) -> Option<FileUsages> { ... }
fn usages_language(&self) -> Option<&'static str> { ... }
fn may_have_usages(&self, _source: &str) -> bool { ... }
}Expand description
Trait for language-specific parsing logic.
Each language needs to implement this to handle its unique AST structure and idioms. The trait provides the Tree-sitter language and the extraction logic.
Required Methods§
Sourcefn extensions(&self) -> &[&str]
fn extensions(&self) -> &[&str]
File extensions this parser handles.
Provided Methods§
Sourcefn extract_usages(
&self,
_tree: &Tree,
_source: &str,
_file_path: &str,
) -> Option<FileUsages>
fn extract_usages( &self, _tree: &Tree, _source: &str, _file_path: &str, ) -> Option<FileUsages>
Extracts tracked SDK usages (see crate::usages) from the same tree.
None means this language has no usage extractor yet, which is
different from a file with no usages (an empty FileUsages).
Sourcefn usages_language(&self) -> Option<&'static str>
fn usages_language(&self) -> Option<&'static str>
The language name usage records carry, for a language that
implements Self::extract_usages.
Sourcefn may_have_usages(&self, _source: &str) -> bool
fn may_have_usages(&self, _source: &str) -> bool
Whether source can contain usages at all. A false answer lets
crate::parse_source_usages skip the parse: most files of a large
tree never mention an SDK.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".