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.
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
Sourcefn is_named_leaf(&self) -> bool
fn is_named_leaf(&self) -> bool
N.B. it is different from is_named && is_leaf
if a node has no named children.
fn is_leaf(&self) -> bool
fn is_missing(&self) -> bool
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>
impl<'r> SgNode<'r> for Node<'r>
Source§fn is_named_leaf(&self) -> bool
fn is_named_leaf(&self) -> bool
N.B. it is different from is_named && is_leaf
if a Node has no named children.