pub struct Node<'t> { /* private fields */ }Expand description
A node or token of a SyntaxTree: a cheap, copyable view.
Navigation is O(1) per step, except Node::last_child and
Node::prev_sibling, which are O(depth) (the arena links forward).
In an edited tree too, as long as the step stays inside one of the
edits’ runs, so sequential reads cost amortised O(1) per
element (see SyntaxTree::is_edited).
Implementations§
Source§impl<'t> Node<'t>
impl<'t> Node<'t>
Sourcepub const fn slot(self) -> u32
pub const fn slot(self) -> u32
The element’s slot: a 4-byte name of the element for the tree’s
whole life (edits never reuse a slot), resolved with
SyntaxTree::node_at_slot. Meant for compact indexes
over one tree; unlike a NodeId it does not name
its tree, so it is meaningful only with the tree that issued it (and
a fork of it, for slots issued before the
fork). O(1).
Sourcepub fn preorder_index(self) -> usize
pub fn preorder_index(self) -> usize
The element’s position in preorder (= source order), 0 for the root.
Positions compare elements of one tree: an element comes before
everything in its subtree and after its preceding siblings. O(1);
O(log R) in an edited tree (R: runs, see SyntaxTree::is_edited).
Sourcepub const fn tree(self) -> &'t SyntaxTree
pub const fn tree(self) -> &'t SyntaxTree
The tree this element belongs to.
Sourcepub fn kind(self) -> SyntaxKind
pub fn kind(self) -> SyntaxKind
What the element is.
Sourcepub fn span(self) -> Span
pub fn span(self) -> Span
The source bytes the element covers (UTF-8 byte range); in an
edited tree, the range in SyntaxTree::emit’s text. O(1) (a run
of nodes opening at one byte aside); edited: O(log R) when the
subtree is untouched, else O(depth).
Sourcepub fn text(self) -> Cow<'t, str>
pub fn text(self) -> Cow<'t, str>
The source text the element covers; in an edited tree, its text in
SyntaxTree::emit. Borrowed from the tree (always for a parsed
tree and for tokens); a node whose text an edit split over several
arenas is built from them on each call (O(node size)): the tree
keeps no copies of its text.
Sourcepub fn first_child(self) -> Option<Self>
pub fn first_child(self) -> Option<Self>
The first child; None for a token or an empty node.
Sourcepub fn last_child(self) -> Option<Self>
pub fn last_child(self) -> Option<Self>
The last child. O(depth).
Sourcepub fn next_sibling(self) -> Option<Self>
pub fn next_sibling(self) -> Option<Self>
The next sibling.
Sourcepub fn prev_sibling(self) -> Option<Self>
pub fn prev_sibling(self) -> Option<Self>
The previous sibling. O(depth).
Sourcepub fn descendants(self) -> Descendants<'t> ⓘ
pub fn descendants(self) -> Descendants<'t> ⓘ
This element and everything under it, in preorder (= source order).
Sourcepub fn walk(self) -> Walk<'t> ⓘ
pub fn walk(self) -> Walk<'t> ⓘ
A preorder walk of this subtree that also reports leaving each element (tokens are entered and left at once).
Sourcepub fn diagnostic(self) -> Option<Cow<'t, Diagnostic>>
pub fn diagnostic(self) -> Option<Cow<'t, Diagnostic>>
The diagnostic of an SyntaxKind::Error node (in an edited tree,
with its spans moved to the edited text). Past max_diagnostics it
is a skeleton, without texts (see
SyntaxTree::suppressed_diagnostics).
Sourcepub fn anchor(self) -> Option<Anchor<'t>>
pub fn anchor(self) -> Option<Anchor<'t>>
A YAML node’s anchor (§6.9.2), read as the event stream reads it.
Sourcepub fn tag(self) -> Option<Tag<'t>>
pub fn tag(self) -> Option<Tag<'t>>
A YAML node’s tag, resolved as the event stream resolves it
(%TAG prefix and %XX escapes, §6.9.1).
Cost: O(prefix + suffix) per call; the resolved text copies the
%TAG prefix, which may be long. To read many tags, cache by
TagSource::key (Node::tag_source) and resolve each distinct
tag once.
Sourcepub fn tag_source(self) -> Option<TagSource<'t>>
pub fn tag_source(self) -> Option<TagSource<'t>>
A YAML node’s tag as written, not yet resolved: O(the property’s
text), whatever the %TAG prefix’s length. Its
span is in the edited text, as Node::tag’s.
Sourcepub fn block_header(self) -> Option<BlockHeader>
pub fn block_header(self) -> Option<BlockHeader>
A block scalar’s header as the event carried it (C5).
Sourcepub fn value(self) -> Option<Cow<'t, str>>
pub fn value(self) -> Option<Cow<'t, str>>
A scalar node’s value after escapes, folding, and chomping, decoded by the event stream’s own decoder. Borrowed from the source when it is a slice of it.
Sourcepub fn alias_name(self) -> Option<&'t str>
pub fn alias_name(self) -> Option<&'t str>
An alias node’s anchor name, without *.