[][src]Struct tree_sitter::Node

#[repr(transparent)]
pub struct Node<'a>(_, _);

A single node within a syntax Tree.

Methods

impl<'tree> Node<'tree>[src]

pub fn kind_id(&self) -> u16[src]

Get this node's type as a numerical id.

pub fn kind(&self) -> &'static str[src]

Get this node's type as a string.

pub fn is_named(&self) -> bool[src]

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.

pub fn is_extra(&self) -> bool[src]

Check if this node is extra.

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

pub fn has_changes(&self) -> bool[src]

Check if this node has been edited.

pub fn has_error(&self) -> bool[src]

Check if this node represents a syntax error or contains any syntax errors anywhere within it.

pub fn is_error(&self) -> bool[src]

Check if this node represents a syntax error.

Syntax errors represent parts of the code that could not be incorporated into a valid syntax tree.

pub fn is_missing(&self) -> bool[src]

Check if this node is missing.

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

pub fn start_byte(&self) -> usize[src]

Get the byte offsets where this node starts.

pub fn end_byte(&self) -> usize[src]

Get the byte offsets where this node end.

pub fn byte_range(&self) -> Range<usize>[src]

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

pub fn range(&self) -> Range[src]

Get the range of source code that this node represents, both in terms of raw bytes and of row/column coordinates.

pub fn start_position(&self) -> Point[src]

Get this node's start position in terms of rows and columns.

pub fn end_position(&self) -> Point[src]

Get this node's end position in terms of rows and columns.

pub fn child(&self, i: usize) -> Option<Self>[src]

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

pub fn child_by_field_name(&self, field_name: impl AsRef<[u8]>) -> Option<Self>[src]

Get the first child with the given field name.

To access the node's children and their field names more efficiently, create a TreeCursor using Node::walk. Then, while walking the tree, access each node's field id using TreeCursor::field_name or TreeCursor::field_id.

pub fn child_by_field_id(&self, field_id: u16) -> Option<Self>[src]

Get this node's child with the given numerical field id.

See also [child_by_field_name]. You can convert a field name to an id using Language::field_id_for_name.

pub fn child_count(&self) -> usize[src]

Get this node's number of children.

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

pub fn named_child<'a>(&'a self, i: usize) -> Option<Self>[src]

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

See also [Node.is_named].

pub fn named_child_count(&self) -> usize[src]

Get this node's number of named children.

See also [Node.is_named].

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

Get this node's immediate parent.

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

Get this node's next sibling.

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

Get this node's previous sibling.

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

Get this node's next named sibling.

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

Get this node's previous named sibling.

pub fn descendant_for_byte_range(
    &self,
    start: usize,
    end: usize
) -> Option<Self>
[src]

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

pub fn named_descendant_for_byte_range(
    &self,
    start: usize,
    end: usize
) -> Option<Self>
[src]

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

pub fn descendant_for_point_range(
    &self,
    start: Point,
    end: Point
) -> Option<Self>
[src]

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

pub fn named_descendant_for_point_range(
    &self,
    start: Point,
    end: Point
) -> Option<Self>
[src]

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

pub fn to_sexp(&self) -> String[src]

pub fn utf8_text<'a>(&self, source: &'a [u8]) -> Result<&'a str, Utf8Error>[src]

pub fn utf16_text<'a>(&self, source: &'a [u16]) -> &'a [u16][src]

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

Create a new TreeCursor starting from this node.

pub fn edit(&mut self, edit: &InputEdit)[src]

Edit this node to keep it in-sync with source code that has been edited.

This function is only rarely needed. When you edit a syntax tree with the Tree::edit method, all of the nodes that you retrieve from the tree afterward will already reflect the edit. You only need to use Node::edit when you have a specific Node instance that you want to keep and continue to use after an edit.

Trait Implementations

impl<'a> Clone for Node<'a>[src]

impl<'a> Copy for Node<'a>[src]

impl<'a> PartialEq<Node<'a>> for Node<'a>[src]

impl<'a> Debug for Node<'a>[src]

Auto Trait Implementations

impl<'a> !Send for Node<'a>

impl<'a> !Sync for Node<'a>

impl<'a> Unpin for Node<'a>

impl<'a> UnwindSafe for Node<'a>

impl<'a> RefUnwindSafe for Node<'a>

Blanket Implementations

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> From<T> for T[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]