pub struct Parser<T: LanguageInfo + Alterator + Checker + Getter> { /* private fields */ }Expand description
Parsed source plus the tree-sitter Tree for a given language T.
Construct with Parser::new and feed the result into the metric,
alterator, or AST-dump entry points. The type parameter T is one
of the language code tags (RustCode, PythonCode, etc.) declared
by the internal mk_code! macro.
Implementations§
Source§impl<T: 'static + LanguageInfo + Alterator + Checker + Getter> Parser<T>
impl<T: 'static + LanguageInfo + Alterator + Checker + Getter> Parser<T>
Sourcepub fn from_tree(tree: Tree, code: Vec<u8>) -> Self
pub fn from_tree(tree: Tree, code: Vec<u8>) -> Self
Builds a Parser from a pre-parsed tree_sitter::Tree
and the matching source bytes.
Use this when the caller already drives tree-sitter for
other purposes (e.g. an editor doing incremental reparsing)
and wants the metric walker to reuse the parse instead of
running its own. The standard byte-based entry point
remains ParserTrait::new.
The supplied tree must have been produced from code with
the tree-sitter language matching T — typically obtained
via crate::LANG::tree_sitter_language. A mismatch is
not unsafe, but metric values will be nonsensical because
the tree’s kind_id values will not correspond to the per-
language enum the metric compute functions match on.
Sourcepub fn ts_tree(&self) -> &Tree
pub fn ts_tree(&self) -> &Tree
Borrow the underlying tree_sitter::Tree for callers that
want to drive their own traversal alongside the metric walker.
Parser is pub in this crate but carries no stability
promise (see the crate root); the stable spelling of this
accessor is big_code_analysis::Ast::as_tree_sitter.
Trait Implementations§
Source§impl<T: 'static + LanguageInfo + Alterator + Checker + Getter> ParserTrait for Parser<T>
impl<T: 'static + LanguageInfo + Alterator + Checker + Getter> ParserTrait for Parser<T>
Source§fn new(code: Vec<u8>, path: &Path, pr: Option<Arc<PreprocResults>>) -> Self
fn new(code: Vec<u8>, path: &Path, pr: Option<Arc<PreprocResults>>) -> Self
code read from path. pr carries the C-family
preprocessor results whose #defines are expanded before parsing;
every other language ignores it. Read more