pub trait LanguageAdapter: Send + Sync {
// Required methods
fn name(&self) -> &str;
fn language(&self) -> Language;
fn file_extensions(&self) -> &[&str];
fn statement_node_types(&self) -> &[&str];
fn expression_node_types(&self) -> &[&str];
fn identifier_node_types(&self) -> &[&str];
// Provided methods
fn supports_file(&self, path: &Path) -> bool { ... }
fn is_leaf_variable_candidate(&self, node_kind: &str) -> bool { ... }
fn is_structural_node(&self, node_kind: &str) -> bool { ... }
fn parse(&self, source: &str) -> Result<Tree, String> { ... }
}Expand description
Trait for language-specific adapters.
Each supported language implements this trait to provide tree-sitter grammar and language-specific utilities that the pattern engine uses for parsing, matching, and transformation.
Required Methods§
Sourcefn language(&self) -> Language
fn language(&self) -> Language
Returns the tree_sitter::Language grammar used for parsing.
Sourcefn file_extensions(&self) -> &[&str]
fn file_extensions(&self) -> &[&str]
Returns common file extensions for this language (without the leading dot).
§Examples
Rust: &["rs"]
JavaScript: &["js", "jsx", "mjs"]
Sourcefn statement_node_types(&self) -> &[&str]
fn statement_node_types(&self) -> &[&str]
Returns tree-sitter node types that represent “statements”.
These are used during pattern inference to decide structural boundaries for extraction.
Sourcefn expression_node_types(&self) -> &[&str]
fn expression_node_types(&self) -> &[&str]
Returns tree-sitter node types that represent “expressions”.
Sourcefn identifier_node_types(&self) -> &[&str]
fn identifier_node_types(&self) -> &[&str]
Returns tree-sitter node types that represent identifiers (variable names, type names, etc.).
Provided Methods§
Sourcefn supports_file(&self, path: &Path) -> bool
fn supports_file(&self, path: &Path) -> bool
Checks if a file path is supported by this language adapter.
The default implementation matches the file extension against
Self::file_extensions.
Sourcefn is_leaf_variable_candidate(&self, node_kind: &str) -> bool
fn is_leaf_variable_candidate(&self, node_kind: &str) -> bool
Returns true if the given tree-sitter node kind represents a leaf token (identifier or literal) that could become a pattern variable.
Sourcefn is_structural_node(&self, node_kind: &str) -> bool
fn is_structural_node(&self, node_kind: &str) -> bool
Returns true if the given tree-sitter node kind is a structural container (statement or expression) that should be compared recursively.