pub struct Node<'a>(/* private fields */);Expand description
An AST node.
The inner tree_sitter::Node is reached through
Node::as_tree_sitter for advanced use cases that need direct
access to the underlying tree-sitter API; the field itself is
private so a tree-sitter version bump cannot silently reshape
this struct’s public layout.
Implementations§
Source§impl<'a> Node<'a>
impl<'a> Node<'a>
Sourcepub fn as_tree_sitter(&self) -> OtherNode<'a>
pub fn as_tree_sitter(&self) -> OtherNode<'a>
Returns the underlying tree_sitter::Node for callers that
want to drive their own traversal alongside the metric walker.
tree_sitter::Node is Copy, so the node is returned by
value. The returned node borrows the same source-tree lifetime
as self.
The tree-sitter re-export this exposes is value-not-stable:
the underlying pin may bump in any minor release, so node shape
and node-kind ids are not part of this crate’s stability
contract (see the tree_sitter re-export
note in the crate root).
Sourcepub fn has_error(&self) -> bool
pub fn has_error(&self) -> bool
Checks if a node represents a syntax error or contains any syntax errors anywhere within it.
Sourcepub fn preorder(&self) -> Preorder<'a>
pub fn preorder(&self) -> Preorder<'a>
Returns a pre-order iterator over this node and all of its descendants (this node first, then each child subtree left to right).
The traversal is allocation-light: it reuses one work stack and
visits each node exactly once, so a full walk is O(n) in the
subtree size. Every yielded Node carries the underlying tree
lifetime 'a, so callers may collect or retain the handles.
This is the Rust counterpart of the Python Node.walk() binding
(issue #728): the binding wraps each yielded node, so Rust and
Python share one traversal order.
Sourcepub fn descendants_by_kind(&self, kinds: &[&str]) -> Vec<Node<'a>>
pub fn descendants_by_kind(&self, kinds: &[&str]) -> Vec<Node<'a>>
Collects every node in this subtree (this node included) whose
kind is listed in kinds, in
pre-order.
Membership is an exact match against the raw grammar kind — the
same unaltered vocabulary crate::Ast::root_node exposes, not
the Alterator-curated kinds crate::Ast::dump emits. This is
the Rust counterpart of the Python Node.descendants_by_kind()
binding (issue #728).