Skip to main content

AstParser

Trait AstParser 

Source
pub trait AstParser {
    // Required method
    fn parse(
        &mut self,
        source: &str,
        language: &Language,
    ) -> Result<Tree, ParseError>;
}
Expand description

A source code parser that produces syntax trees.

Implementations are stateful and mutable: a single instance should be reused across multiple files so it can recycle internal buffers.

The signature currently uses tree_sitter::Language and tree_sitter::Tree directly to avoid a wrapper layer that would add no value today. Implementors must depend on the same tree_sitter version.

Required Methods§

Source

fn parse( &mut self, source: &str, language: &Language, ) -> Result<Tree, ParseError>

Parse source code with the given language grammar.

§Errors

Returns ParseError::LanguageSetup if the grammar can’t be loaded, or ParseError::ParseFailed if the parser produces no tree.

Implementors§