Skip to main content

SgNode

Trait SgNode 

Source
pub trait SgNode<'r>:
    Clone
    + Debug
    + Send
    + Sync {
Show 23 methods // Required methods fn parent(&self) -> Option<Self>; fn children(&self) -> impl ExactSizeIterator<Item = Self>; fn kind(&self) -> Cow<'_, str>; fn kind_id(&self) -> u16; fn node_id(&self) -> usize; fn range(&self) -> Range<usize>; fn start_pos(&self) -> Position; fn end_pos(&self) -> Position; fn field(&self, name: &str) -> Option<Self>; fn field_children( &self, field_id: Option<u16>, ) -> impl Iterator<Item = Self>; fn child_by_field_id(&self, field_id: u16) -> Option<Self>; // Provided methods fn ancestors(&self, _root: Self) -> impl Iterator<Item = Self> { ... } fn dfs(&self) -> impl Iterator<Item = Self> { ... } fn child(&self, nth: usize) -> Option<Self> { ... } fn next(&self) -> Option<Self> { ... } fn prev(&self) -> Option<Self> { ... } fn next_all(&self) -> impl Iterator<Item = Self> { ... } fn prev_all(&self) -> impl Iterator<Item = Self> { ... } fn is_named(&self) -> bool { ... } fn is_named_leaf(&self) -> bool { ... } fn is_leaf(&self) -> bool { ... } fn is_missing(&self) -> bool { ... } fn is_error(&self) -> bool { ... }
}
Expand description

Generic interface for AST nodes across different parser backends.

SgNode (SourceGraph Node) provides a consistent API for working with AST nodes regardless of the underlying parser implementation. Supports navigation, introspection, and traversal operations.

§Lifetime

The lifetime 'r ties the node to its root document, ensuring memory safety.

§Note

Some method names match tree-sitter’s API. Use fully qualified syntax if there are naming conflicts with tree-sitter imports.

See: https://stackoverflow.com/a/44445976/2198656

Required Methods§

Source

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

Source

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

Source

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

Source

fn kind_id(&self) -> u16

Source

fn node_id(&self) -> usize

Source

fn range(&self) -> Range<usize>

Source

fn start_pos(&self) -> Position

Source

fn end_pos(&self) -> Position

Source

fn field(&self, name: &str) -> Option<Self>

Source

fn field_children(&self, field_id: Option<u16>) -> impl Iterator<Item = Self>

Source

fn child_by_field_id(&self, field_id: u16) -> Option<Self>

Provided Methods§

Source

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

Source

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

Source

fn child(&self, nth: usize) -> Option<Self>

Source

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

Source

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

Source

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

Source

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

Source

fn is_named(&self) -> bool

Source

fn is_named_leaf(&self) -> bool

N.B. it is different from is_named && is_leaf if a node has no named children.

Source

fn is_leaf(&self) -> bool

Source

fn is_missing(&self) -> bool

Source

fn is_error(&self) -> bool

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.

Implementations on Foreign Types§

Source§

impl<'r> SgNode<'r> for Node<'r>

Source§

fn is_named_leaf(&self) -> bool

N.B. it is different from is_named && is_leaf if a Node has no named children.

Source§

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

Source§

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

Source§

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

Source§

fn child(&self, nth: usize) -> Option<Self>

Source§

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

Source§

fn child_by_field_id(&self, field_id: u16) -> Option<Self>

Source§

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

Source§

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

Source§

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

Source§

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

Source§

fn is_named(&self) -> bool

Source§

fn is_leaf(&self) -> bool

Source§

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

Source§

fn kind_id(&self) -> u16

Source§

fn node_id(&self) -> usize

Source§

fn range(&self) -> Range<usize>

Source§

fn start_pos(&self) -> Position

Source§

fn end_pos(&self) -> Position

Source§

fn is_missing(&self) -> bool

Source§

fn is_error(&self) -> bool

Source§

fn field(&self, name: &str) -> Option<Self>

Source§

fn field_children(&self, field_id: Option<u16>) -> impl Iterator<Item = Self>

Implementors§