Skip to main content

LanguageAdapter

Trait LanguageAdapter 

Source
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§

Source

fn name(&self) -> &str

Returns the human-readable language name (e.g., "rust", "javascript").

Source

fn language(&self) -> Language

Returns the tree_sitter::Language grammar used for parsing.

Source

fn file_extensions(&self) -> &[&str]

Returns common file extensions for this language (without the leading dot).

§Examples

Rust: &["rs"] JavaScript: &["js", "jsx", "mjs"]

Source

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.

Source

fn expression_node_types(&self) -> &[&str]

Returns tree-sitter node types that represent “expressions”.

Source

fn identifier_node_types(&self) -> &[&str]

Returns tree-sitter node types that represent identifiers (variable names, type names, etc.).

Provided Methods§

Source

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.

Source

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.

Source

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.

Source

fn parse(&self, source: &str) -> Result<Tree, String>

Parse source code into a tree-sitter Tree.

This is a convenience method that creates a parser, sets the language, and parses the given source.

Implementors§