Node

Struct Node 

Source
#[repr(C)]
pub struct Node<'tree> { /* private fields */ }

Implementations§

Source§

impl<'tree> Node<'tree>

Source

pub fn id(&self) -> usize

Source

pub fn kind(&self) -> &'tree str

Get this node’s type as a string

Source

pub fn kind_id(&self) -> u16

Get this node’s type as a numerical id.

Source

pub fn grammar(&self) -> Grammar

Get the Grammar that was used to parse this node’s syntax tree.

Source

pub fn is_named(&self) -> bool

Check if this node is named.

Named nodes correspond to named rules in the grammar, whereas anonymous nodes correspond to string literals in the grammar.

Source

pub fn is_contained_within(&self, range: Range<u32>) -> bool

Returns true if and only if this node is contained “inside” the given input range, i.e. either start_new > start_old and end_new <= end_old OR start_new >= start_old and end_new < end_old

Source

pub fn is_missing(&self) -> bool

Check if this node is missing.

Missing nodes are inserted by the parser in order to recover from certain kinds of syntax errors.

Source

pub fn is_extra(&self) -> bool

Check if this node is extra.

Extra nodes represent things like comments, which are not required by the grammar, but can appear anywhere.

Source

pub fn start_byte(&self) -> u32

Get the byte offsets where this node starts.

Source

pub fn end_byte(&self) -> u32

Get the byte offsets where this node end.

Source

pub fn byte_range(&self) -> Range<u32>

Get the byte range of source code that this node represents.

Source

pub fn child(&self, i: u32) -> Option<Node<'tree>>

Get the node’s child at the given index, where zero represents the first child.

This method is fairly fast, but its cost is technically log(i), so if you might be iterating over a long list of children, you should use Node::children instead.

Source

pub fn child_count(&self) -> u32

Get this node’s number of children.

Source

pub fn named_child(&self, i: u32) -> Option<Node<'tree>>

Get this node’s named child at the given index.

See also Node::is_named. This method is fairly fast, but its cost is technically log(i), so if you might be iterating over a long list of children, you should use Node::named_children instead.

Source

pub fn named_child_count(&self) -> u32

Get this node’s number of named children.

See also Node::is_named.

Source

pub fn parent(&self) -> Option<Self>

Get this node’s immediate parent.

Source

pub fn next_sibling(&self) -> Option<Self>

Get this node’s next sibling.

Source

pub fn prev_sibling(&self) -> Option<Self>

Get this node’s previous sibling.

Source

pub fn next_named_sibling(&self) -> Option<Self>

Get this node’s next named sibling.

Source

pub fn prev_named_sibling(&self) -> Option<Self>

Get this node’s previous named sibling.

Source

pub fn descendant_for_byte_range(&self, start: u32, end: u32) -> Option<Self>

Get the smallest node within this node that spans the given range.

Source

pub fn named_descendant_for_byte_range( &self, start: u32, end: u32, ) -> Option<Self>

Get the smallest named node within this node that spans the given range.

Source

pub fn children(&self) -> impl ExactSizeIterator<Item = Node<'tree>>

Iterate over this node’s children.

A TreeCursor is used to retrieve the children efficiently. Obtain a TreeCursor by calling Tree::walk or Node::walk. To avoid unnecessary allocations, you should reuse the same cursor for subsequent calls to this method.

If you’re walking the tree recursively, you may want to use the TreeCursor APIs directly instead.

Source

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

Trait Implementations§

Source§

impl<'tree> Clone for Node<'tree>

Source§

fn clone(&self) -> Node<'tree>

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Node<'_>

Source§

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

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

impl PartialEq for Node<'_>

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Eq for Node<'_>

Source§

impl Send for Node<'_>

Source§

impl Sync for Node<'_>

Auto Trait Implementations§

§

impl<'tree> Freeze for Node<'tree>

§

impl<'tree> RefUnwindSafe for Node<'tree>

§

impl<'tree> Unpin for Node<'tree>

§

impl<'tree> UnwindSafe for Node<'tree>

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