Struct tree_sitter::Node[][src]

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

A single node within a syntax Tree.

Implementations

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

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

Get a numeric id for this node that is unique.

Within a given syntax tree, no two nodes have the same id. However, if a new tree is created based on an older tree, and a node from the old tree is reused in the process, then that node will have the same id in both trees.

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 language(&self) -> Language[src]

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

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.

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

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

Get this node’s number of children.

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. This method is fairly fast, but its cost is technically log(i), so you if you might be iterating over a long list of children, you should use Node::named_children instead.

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

Get this node’s number of named children.

See also Node::is_named.

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

Get the first child with the given field name.

If multiple children may have the same field name, access them using children_by_field_name

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 children<'a>(
    &self,
    cursor: &'a mut TreeCursor<'tree>
) -> impl ExactSizeIterator<Item = Node<'tree>> + 'a
[src]

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.

pub fn named_children<'a>(
    &self,
    cursor: &'a mut TreeCursor<'tree>
) -> impl ExactSizeIterator<Item = Node<'tree>> + 'a
[src]

Iterate over this node’s named children.

See also Node::children.

pub fn children_by_field_name<'a>(
    &self,
    field_name: &str,
    cursor: &'a mut TreeCursor<'tree>
) -> impl Iterator<Item = Node<'tree>> + 'a
[src]

Iterate over this node’s children with a given field name.

See also Node::children.

pub fn children_by_field_id<'a>(
    &self,
    field_id: u16,
    cursor: &'a mut TreeCursor<'tree>
) -> impl Iterator<Item = Node<'tree>> + 'a
[src]

Iterate over this node’s children with a given field id.

See also Node::children_by_field_name.

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> Debug for Node<'a>[src]

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

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

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

Auto Trait Implementations

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

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

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

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

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

Blanket Implementations

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

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

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

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

impl<T, U> Into<U> for T where
    U: From<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.