Struct ParsedFile

Source
pub struct ParsedFile<'a> { /* private fields */ }
Expand description

A parsed source file with its tree-sitter parse tree and original source code.

Implementations§

Source§

impl<'a> ParsedFile<'a>

Source

pub fn parse( source_code: &'a str, parser: &mut Parser, ) -> Result<Self, ExtractionError>

Parse source code into a tree-sitter parse tree.

§Parameters
  • source_code - The source code to parse
  • parser - A mutable reference to a configured tree-sitter parser
§Returns

A new ParsedFile instance or an ExtractionError if parsing fails

Source

pub fn root_node(&'a self) -> Node<'a>

Return the root node of the parse tree.

§Returns

The root node of the parsed source file

Source

pub fn render_node(&self, node: Node<'_>) -> Result<String, ExtractionError>

Return a tree-sitter node’s text content.

§Parameters
  • node - The tree-sitter node to render
§Returns

The text content of the node or an ExtractionError if rendering fails

Source

pub fn render(&self, range: Range<usize>) -> String

Return text content from a byte range in the source code.

§Parameters
  • range - The byte range to extract from the source code
§Returns

The text content within the specified range

Source

pub fn make_query(&self, query: &str) -> Result<Query, ExtractionError>

Create a new tree-sitter query from a query string.

§Parameters
  • query - The query string in tree-sitter query language
§Returns

A compiled query or an ExtractionError if query creation fails

Source

pub fn exec_query<'b>( &'b self, query: &'b Query, node: Node<'b>, cursor: &'b mut QueryCursor, ) -> QueryMatches<'b, 'b, &'b [u8], &'b [u8]>

Execute a tree-sitter query on a specific node.

§Parameters
  • query - The compiled tree-sitter query to execute
  • node - The node to search within
  • cursor - A mutable reference to a query cursor for tracking query state
§Returns

An iterator over the query matches

Auto Trait Implementations§

§

impl<'a> Freeze for ParsedFile<'a>

§

impl<'a> RefUnwindSafe for ParsedFile<'a>

§

impl<'a> Send for ParsedFile<'a>

§

impl<'a> Sync for ParsedFile<'a>

§

impl<'a> Unpin for ParsedFile<'a>

§

impl<'a> UnwindSafe for ParsedFile<'a>

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 = 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.