Skip to main content

LanguageParser

Trait LanguageParser 

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

Source

fn language(&self) -> Language

Returns the Tree-sitter language for this parser.

Source

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

File extensions this parser handles.

Source

fn extract_nodes( &self, tree: &Tree, source: &str, file_path: &str, ) -> Vec<CodeNode>

Extracts CodeNodes from a parsed Tree-sitter tree.

This is where the magic happens. Each language traverses its AST differently to find functions, classes, etc.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§