Skip to main content

BufferParser

Struct BufferParser 

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

Per-buffer parser + last-parsed tree.

Implementations§

Source§

impl BufferParser

Source

pub fn new( language: &str, registry: &GrammarRegistry, ) -> Result<BufferParser, TsError>

A parser for language (must be registered).

§Errors

Returns TsError if the language is unknown or the parser rejects it.

Source

pub fn language(&self) -> &str

Source

pub fn reparse(&mut self, src: &str) -> Result<(), TsError>

Re-parse src from scratch. Passes None as the old tree on purpose: tree-sitter’s incremental path requires the old tree to have been Tree::edit-ed to reflect exactly what changed. Handing parse() an un-edited old tree against changed source violates that contract and can yield an incorrect tree — so the correct answer for an unknown delta is a full parse. Callers that know the edit use reparse_edit.

§Errors

Infallible today (tree-sitter returns None on failure, stored as-is); the Result reserves fallibility for future timeout/cancel support.

Source

pub fn reparse_edit( &mut self, old_src: &str, new_src: &str, start_byte: usize, old_end_byte: usize, ) -> Result<(), TsError>

Incrementally re-parse after splicing [start_byte, old_end_byte) of old_src to produce new_src. Edits the retained tree by the splice (TsEdit) so tree-sitter reuses every unchanged subtree and reparses only the affected span — O(edit), not O(document). With no prior tree it falls back to a full parse. The result is identical to a full parse of new_src (the differential-equivalence invariant, tested).

§Errors

Same as reparse.

Source

pub fn tree(&self) -> Option<&Tree>

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