AstNode

Trait AstNode 

Source
pub trait AstNode:
    Debug
    + Send
    + Sync
    + DowncastSync {
    // Required methods
    fn contains(node: &Node<'_>) -> bool
       where Self: Sized;
    fn lower(&self) -> &(dyn AstNode + 'static);
    fn get_id(&self) -> usize;
    fn get_parent_id(&self) -> Option<usize>;
    fn get_range(&self) -> &Range;

    // Provided methods
    fn get_lsp_range(&self) -> Range { ... }
    fn get_start_position(&self) -> Position { ... }
    fn get_end_position(&self) -> Position { ... }
    fn get_text<'a>(
        &self,
        source_code: &'a [u8],
    ) -> Result<&'a str, PositionError> { ... }
    fn get_parent<'a>(
        &'a self,
        nodes: &'a [Arc<dyn AstNode>],
    ) -> Option<&'a Arc<dyn AstNode>> { ... }
}
Expand description

Trait representing an AST node.

Required Methods§

Source

fn contains(node: &Node<'_>) -> bool
where Self: Sized,

Returns true if a given tree_sitter::Node matches this node type.

Source

fn lower(&self) -> &(dyn AstNode + 'static)

Returns the inner node as a trait object.

If the node is a struct, returns self.

Source

fn get_id(&self) -> usize

Returns the unique ID of this node.

IDs are assigned when TryFrom is called and are unique within the tree.

Source

fn get_parent_id(&self) -> Option<usize>

Returns the ID of the parent node, if any.

Source

fn get_range(&self) -> &Range

Returns the tree_sitter::Range of this node.

Provided Methods§

Source

fn get_lsp_range(&self) -> Range

Returns the LSP-compatible range of this node.

Source

fn get_start_position(&self) -> Position

Returns the start position in LSP format.

Source

fn get_end_position(&self) -> Position

Returns the end position in LSP format.

Source

fn get_text<'a>(&self, source_code: &'a [u8]) -> Result<&'a str, PositionError>

Returns the UTF-8 text slice corresponding to this node.

Returns:

  • Ok(&str) with the node’s source text
  • Err(PositionError::WrongTextRange) if the range is invalid
  • Err(PositionError::UTF8Error) if the byte slice is not valid UTF-8
Source

fn get_parent<'a>( &'a self, nodes: &'a [Arc<dyn AstNode>], ) -> Option<&'a Arc<dyn AstNode>>

Retrieves the parent node, if present, from the node list.

The node list must be sorted by ID.

Implementations§

Source§

impl dyn AstNode

Source

pub fn is<__T>(&self) -> bool
where __T: AstNode,

Returns true if the trait object wraps an object of type __T.

Source

pub fn downcast<__T>( self: Box<dyn AstNode>, ) -> Result<Box<__T>, Box<dyn AstNode>>
where __T: AstNode,

Returns a boxed object from a boxed trait object if the underlying object is of type __T. Returns the original boxed trait if it isn’t.

Source

pub fn downcast_rc<__T>( self: Rc<dyn AstNode>, ) -> Result<Rc<__T>, Rc<dyn AstNode>>
where __T: AstNode,

Returns an Rc-ed object from an Rc-ed trait object if the underlying object is of type __T. Returns the original Rc-ed trait if it isn’t.

Source

pub fn downcast_ref<__T>(&self) -> Option<&__T>
where __T: AstNode,

Returns a reference to the object within the trait object if it is of type __T, or None if it isn’t.

Source

pub fn downcast_mut<__T>(&mut self) -> Option<&mut __T>
where __T: AstNode,

Returns a mutable reference to the object within the trait object if it is of type __T, or None if it isn’t.

Trait Implementations§

Source§

impl Ord for dyn AstNode

Source§

fn cmp(&self, other: &(dyn AstNode + 'static)) -> Ordering

This method returns an Ordering between self and other. Read more
Source§

impl PartialEq for dyn AstNode

Source§

fn eq(&self, other: &(dyn AstNode + 'static)) -> 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 PartialOrd for dyn AstNode

Source§

fn partial_cmp(&self, other: &(dyn AstNode + 'static)) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

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

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

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

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

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

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

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

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl Eq for dyn AstNode

Implementors§