Skip to main content

Parser

Struct Parser 

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

Source

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.

Source

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: Debug + LanguageInfo + Alterator + Checker + Getter> Debug for Parser<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T: 'static + LanguageInfo + Alterator + Checker + Getter> ParserTrait for Parser<T>

Source§

type Checker = T

The language’s classification predicates.
Source§

type Getter = T

The language’s naming / space-kind / Halstead-class accessors.
Source§

fn new(code: Vec<u8>, path: &Path, pr: Option<Arc<PreprocResults>>) -> Self

Parses code read from path. pr carries the C-family preprocessor results whose #defines are expanded before parsing; every other language ignores it. Read more
Source§

fn root(&self) -> Node<'_>

The root node of the parsed tree.
Source§

fn code(&self) -> &[u8] ⓘ

The bytes the tree was parsed from (after macro expansion, for the C family).
Source§

fn filters(&self, requested: &[String]) -> Filter<'_>

The returned Filter borrows self — the "function" and "string" predicates read the source bytes (#1162, #1381).

Auto Trait Implementations§

§

impl<T> Freeze for Parser<T>
where PhantomData<T>: Freeze,

§

impl<T> RefUnwindSafe for Parser<T>

§

impl<T> Send for Parser<T>
where PhantomData<T>: Send,

§

impl<T> Sync for Parser<T>
where PhantomData<T>: Sync,

§

impl<T> Unpin for Parser<T>
where PhantomData<T>: Unpin,

§

impl<T> UnsafeUnpin for Parser<T>

§

impl<T> UnwindSafe for Parser<T>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.