AstNode

Trait AstNode 

Source
pub trait AstNode: Debug + Sized {
    // Required methods
    fn ancestors(&self) -> impl Iterator<Item = Self>;
    fn children(&self) -> impl Iterator<Item = Self>;
    fn parent(&self) -> Option<Self>;
    fn next_named_node(&self) -> Option<Self>;
    fn previous_named_node(&self) -> Option<Self>;
    fn next_sibling(&self) -> Option<Self>;
    fn previous_sibling(&self) -> Option<Self>;
    fn text(&self) -> GritResult<Cow<'_, str>>;
    fn byte_range(&self) -> ByteRange;
    fn code_range(&self) -> CodeRange;
    fn walk(&self) -> impl AstCursor<Node = Self>;
}
Expand description

Represents an AST node and offers convenient AST-specific functionality.

This trait should be free from dependencies on TreeSitter. This also implies it should not expose details about the node that may make it infeasible to implement the trait by implementations that use different node representations internally.

Required Methods§

Source

fn ancestors(&self) -> impl Iterator<Item = Self>

Returns an iterator over the node’s ancestors, starting with the node itself and moving up to the root.

Source

fn children(&self) -> impl Iterator<Item = Self>

Returns an iterator over the node’s children.

Source

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

Returns the node’s parent.

Returns None if this is the root node.

Source

fn next_named_node(&self) -> Option<Self>

Returns the next node in the tree, ignoring trivia such as whitespace.

Source

fn previous_named_node(&self) -> Option<Self>

Returns the previous node in the tree, ignoring trivia such as whitespace.

Source

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

Returns the next adjacent node.

Source

fn previous_sibling(&self) -> Option<Self>

Returns the previous adjacent node.

Source

fn text(&self) -> GritResult<Cow<'_, str>>

Returns the text representation of the node.

Source

fn byte_range(&self) -> ByteRange

Returns the byte range of the node.

Source

fn code_range(&self) -> CodeRange

Returns the code range of the node.

Source

fn walk(&self) -> impl AstCursor<Node = Self>

Returns a cursor for traversing the tree, starting at the current node.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§