Skip to main content

Parser

Struct Parser 

Source
pub struct Parser { /* private fields */ }
Expand description

Parser that extracts symbol facts from Rust source code

Pure function: Input (path, contents) → Output Vec<SymbolFact> No filesystem access. No global state. No caching.

Implementations§

Source§

impl Parser

Source

pub fn new() -> Result<Self>

Create a new parser for Rust source code

Source

pub fn extract_symbols( &mut self, file_path: PathBuf, source: &[u8], ) -> Vec<SymbolFact>

👎Deprecated since 1.7.0:

Use extract_symbols_with_parser with parser pool for better performance

Extract symbol facts from Rust source code

§Deprecated

This method creates a new parser instance per call, which is inefficient for batch processing. Use extract_symbols_with_parser with the thread-local parser pool instead:

use crate::ingest::pool::with_parser;
use crate::ingest::Language;

let facts = with_parser(Language::Rust, |parser| {
    RustParser::extract_symbols_with_parser(parser, file_path, source)
})?;
§Arguments
  • file_path - Path to the file (for context only, not accessed)
  • source - Source code content as bytes
§Returns

Vector of symbol facts found in the source

§Guarantees
  • Pure function: same input → same output
  • No side effects
  • No filesystem access
Source

pub fn extract_symbols_with_parser( parser: &mut Parser, file_path: PathBuf, source: &[u8], ) -> Vec<SymbolFact>

Extract symbol facts using an external parser (for parser pooling).

This static method allows sharing a parser instance across multiple calls, reducing allocation overhead when parsing many files.

Source

pub fn extract_symbols_from_tree( tree: &Tree, file_path: PathBuf, source: &[u8], ) -> Vec<SymbolFact>

Extract symbol facts from a pre-parsed tree.

This static method allows extracting symbols without re-parsing, which is useful when the tree is already available from a previous parse.

§Arguments
  • tree - The pre-parsed tree-sitter tree
  • file_path - Path to the file (for context only, not accessed)
  • source - Source code content as bytes
§Returns

Vector of symbol facts found in the source

Source

pub fn extract_impl_relations_static( tree: &Tree, source: &[u8], file_path: &Path, ) -> Vec<ImplRelation>

Extract all impl relationships from a parsed tree.

Walks the tree for impl_item nodes and extracts:

  • Trait impls: impl Trait for TypeImplRelation { type_name, trait_name: Some("Trait") }
  • Inherent impls: impl TypeImplRelation { type_name, trait_name: None }

This is a separate pass from symbol extraction to keep concerns clean. Inherent impls are included for use by downstream consumers (e.g., llmgrep impl block indexing).

Source§

impl Parser

Extension to Parser for reference extraction (convenience wrapper)

Source

pub fn extract_references( &mut self, file_path: PathBuf, source: &[u8], symbols: &[SymbolFact], ) -> Vec<ReferenceFact>

Extract reference facts using the inner parser

Source

pub fn extract_calls( &mut self, file_path: PathBuf, source: &[u8], symbols: &[SymbolFact], ) -> Vec<CallFact>

Extract function call facts (forward call graph)

§Arguments
  • file_path - Path to the file (for context only, not accessed)
  • source - Source code content as bytes
  • symbols - Symbols defined in this file (to match against)
§Returns

Vector of CallFact representing caller → callee relationships

§Guarantees
  • Only function calls are extracted (not type references)
  • Calls are extracted when a function identifier within a function body references another function symbol
  • No semantic analysis (AST-based only)
Source

pub fn extract_calls_with_fqn( &mut self, file_path: PathBuf, source: &[u8], symbols: &[SymbolFact], fqn_to_symbol: &HashMap<String, &SymbolFact>, ) -> Vec<CallFact>

Extract function call facts with optional FQN-aware symbol map.

The FQN map enables accurate resolution of qualified calls such as math::add() across files.

Source

pub fn extract_calls_from_tree( tree: &Tree, file_path: PathBuf, source: &[u8], symbols: &[SymbolFact], ) -> Vec<CallFact>

Extract function call facts from a pre-parsed tree.

Avoids redundant parsing when the tree is already available.

Source

pub fn extract_calls_from_tree_with_fqn( tree: &Tree, file_path: PathBuf, source: &[u8], symbols: &[SymbolFact], fqn_to_symbol: &HashMap<String, &SymbolFact>, ) -> Vec<CallFact>

Extract function call facts from a pre-parsed tree with FQN map.

Trait Implementations§

Source§

impl Default for Parser

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more