Skip to main content

Syntax

Struct Syntax 

Source
pub struct Syntax { /* private fields */ }

Implementations§

Source§

impl Syntax

Source

pub fn parse(language: Language, code: &Rope) -> Self

Source

pub fn reparse(&mut self, code: &Rope)

Source

pub fn language(&self) -> Language

Source

pub fn tree(&self) -> &Tree

Source

pub fn node_path(&self, byte_range: Range<usize>) -> Vec<Node<'_>>

Nodes from the root down to the smallest node that covers byte_range.

Source

pub fn inner_node(&self, byte_range: Range<usize>) -> Option<Node<'_>>

First named node, in document order, whose byte range lies strictly inside byte_range.

Source

pub fn outer_node(&self, byte_range: Range<usize>) -> Option<Node<'_>>

Smallest node whose byte range strictly contains byte_range.

The root node starts after any leading whitespace, so a range that begins in that whitespace has no outer node.

Methods from Deref<Target = Tree>§

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

Get the root node of the syntax tree.

pub fn root_node_with_offset( &self, offset_bytes: usize, offset_extent: Point, ) -> Node<'_>

Get the root node of the syntax tree, but with its position shifted forward by the given offset.

pub fn language(&self) -> LanguageRef<'_>

Get the language that was used to parse the syntax tree.

When Tree-sitter is compiled to WebAssembly, this returns the original language if the tree is being accessed from the same WebAssembly instance that created it. Otherwise, this returns a copy of the language that can be used to inspect the tree but cannot be assigned to a parser.

pub fn walk(&self) -> TreeCursor<'_>

Create a new [TreeCursor] starting from the root of the tree.

pub fn changed_ranges(&self, other: &Tree) -> impl ExactSizeIterator

Compare this old edited syntax tree to a new syntax tree representing the same document, returning a sequence of ranges whose syntactic structure has changed.

For this to work correctly, this syntax tree must have been edited such that its ranges match up to the new tree. Generally, you’ll want to call this method right after calling one of the [Parser::parse] functions. Call it on the old tree that was passed to parse, and pass the new tree that was returned from parse.

pub fn included_ranges(&self) -> Vec<Range>

Get the included ranges that were used to parse the syntax tree.

pub fn print_dot_graph(&self, file: &impl AsRawFd)

Print a graph of the tree to the given file descriptor. The graph is formatted in the DOT language. You may want to pipe this graph directly to a dot(1) process in order to generate SVG output.

Trait Implementations§

Source§

impl Clone for Syntax

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Deref for Syntax

Source§

type Target = Tree

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<I> FromItem<I> for I

Source§

fn from_item(item: I) -> I

§

impl<T> Instrument for T

§

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

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

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<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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, <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.
§

impl<T> WithSubscriber for T

§

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
§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

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