pub struct SyntaxTree { /* private fields */ }Expand description
A lossless syntax tree over an owned copy of its source (see the module docs).
Build one with SyntaxTree::parse, SyntaxTree::parse_with, or
from an event stream with SyntaxTree::from_events. Building never
fails and never panics; problems in the input are
SyntaxKind::Error nodes and SyntaxTree::diagnostics.
use oneyaml_syntax::tree::{SyntaxKind, SyntaxTree};
let tree = SyntaxTree::parse("a: [1, 2] # c\n");
assert_eq!(tree.emit(), "a: [1, 2] # c\n");
let doc = tree.root().first_child().unwrap();
assert_eq!(doc.kind(), SyntaxKind::Document);
let map = doc.first_child().unwrap();
assert_eq!(map.kind(), SyntaxKind::BlockMapping);
assert_eq!(map.text(), "a: [1, 2]");Equality and hashing compare the source and the structure, not the
stamp that ties NodeIds to one tree instance.
Implementations§
Source§impl SyntaxTree
impl SyntaxTree
Sourcepub fn comment_attachment<'t>(
&'t self,
comment: Node<'t>,
) -> Option<Attachment<'t>>
pub fn comment_attachment<'t>( &'t self, comment: Node<'t>, ) -> Option<Attachment<'t>>
The attachment of comment, a SyntaxKind::Comment
token of this tree; None for any other element.
Cost: O(depth + log + its line) from the comment-run
index, plus, for a comment whose owner is a document header or the
first node (rules 2/3), the blank lines and comments after it in its
run. Columns beyond u32 and recovered input with both header and
footer owners in one run replay the run (O(the run)).
Sourcepub fn comment_document<'t>(
&'t self,
comment: Node<'t>,
) -> Option<Option<Node<'t>>>
pub fn comment_document<'t>( &'t self, comment: Node<'t>, ) -> Option<Option<Node<'t>>>
The document SyntaxTree::comment_attachment gives comment
(Attachment::document): the outer None when comment is not a
SyntaxKind::Comment token of this
tree. O(depth + log) with the comment-run index,
never the run around it or the stream-level elements between it
and its neighbouring documents (the rules’ document never depends
on the blank lines after a comment, which its header owner may).
Sourcepub fn prev_content_token<'t>(&'t self, n: Node<'t>) -> Option<Node<'t>>
pub fn prev_content_token<'t>(&'t self, n: Node<'t>) -> Option<Node<'t>>
The last content token before n in source order (a token with
bytes that is not trivia: what the rulebook calls content; comments,
white space, line breaks and zero-width tokens are skipped); None
at the start of the text or for another tree’s element.
O(log) with the comment-run index, never the comment lines
before n.
Sourcepub fn next_content_token<'t>(&'t self, n: Node<'t>) -> Option<Node<'t>>
pub fn next_content_token<'t>(&'t self, n: Node<'t>) -> Option<Node<'t>>
The first content token after n in source order (inside n for a
node with content), as SyntaxTree::prev_content_token.
The last own-line comment of the run after block collection
collection (the comment lines between its last content token and
the next one) whose owner is the footer of collection or of a
collection whose span lies within its span (rules 6 and 13: those
comments open the run, each owner’s together); None when there is
none, or collection is not a block collection of this tree.
O(depth + log) with the comment-run index, plus the
blank lines before the next comment, never the footer’s length:
what oneyaml’s Document::push_footer appends after.
Sourcepub fn comment_run_attachments<'t>(
&'t self,
comment: Node<'t>,
) -> Vec<(Node<'t>, Attachment<'t>)>
pub fn comment_run_attachments<'t>( &'t self, comment: Node<'t>, ) -> Vec<(Node<'t>, Attachment<'t>)>
The attachments of every comment of the run holding comment (a
SyntaxKind::Comment token of this
tree): the comments between the content token before it and the
content token after it, in source order, decided as
SyntaxTree::comment_attachments decides them (the same code).
Empty for any other element.
The comments of one owner are
read, and a comment edit is checked, one run at a time, in
O(depth + the run + its lines); next to stray ... markers between
documents, the documents around the run are found in O(log) with
the comment-run index, never by walking the stream-level
elements between them.
Sourcepub fn comment_attachments_between<'t>(
&'t self,
before: Option<Node<'t>>,
after: Option<Node<'t>>,
) -> Vec<(Node<'t>, Attachment<'t>)>
pub fn comment_attachments_between<'t>( &'t self, before: Option<Node<'t>>, after: Option<Node<'t>>, ) -> Vec<(Node<'t>, Attachment<'t>)>
Every comment of the stream-level elements strictly between
documents before and after (None: the start, the end of the
stream), with their attachments, in source order, decided as
SyntaxTree::comment_attachments decides them (the same pass).
Empty when before or after is not a document of this tree, or
after does not follow before.
The documents around the stretch are found once
for all of its runs, so a stretch of N stray ... markers and
comments costs O(N), where deciding its N runs one at a time
(SyntaxTree::comment_run_attachments) walks the stretch for
each, O(N²).
Sourcepub fn comment_attachments(&self) -> Vec<(Node<'_>, Attachment<'_>)>
pub fn comment_attachments(&self) -> Vec<(Node<'_>, Attachment<'_>)>
Every comment of the tree with its attachment, in source order. One O(n) pass (see the module docs); nothing is kept afterwards.
Sourcepub fn document_comment_attachments<'t>(
&'t self,
document: Node<'t>,
) -> Vec<(Node<'t>, Attachment<'t>)>
pub fn document_comment_attachments<'t>( &'t self, document: Node<'t>, ) -> Vec<(Node<'t>, Attachment<'t>)>
The comments that belong to document (a
SyntaxKind::Document of this tree),
with their attachments, in source order: its own and those between
it and its neighbouring documents that the rules give it. O(the
document and the stream-level elements around it), never the rest
of the stream; empty for any other element.
Source§impl SyntaxTree
impl SyntaxTree
Sourcepub const fn error_count(&self) -> usize
pub const fn error_count(&self) -> usize
The number of error-severity diagnostics in the tree, kept up to date by every edit (O(1)). Accepted edits never change it (they neither create nor remove an error region); a caller that derives state from the errors can check that here.
Sourcepub fn begin_group(&mut self) -> GroupMark
pub fn begin_group(&mut self) -> GroupMark
Opens an edit group (a multi-step edit is all or
nothing): the edits accepted until the matching
SyntaxTree::end_group can be undone together by
SyntaxTree::rollback_group, exactly (the tree, its text, its
diagnostics, and every handle are as they were at
begin_group). Groups nest; each edit is still checked on its own.
O(1).
While a group is open, accepted edits keep their undo records and the runs they split (merged and released when the outermost group ends), so a group should be closed by one of the two calls: an unclosed group costs memory and run count, never correctness.
Sourcepub fn end_group(&mut self, mark: GroupMark) -> Result<(), TreeEditError>
pub fn end_group(&mut self, mark: GroupMark) -> Result<(), TreeEditError>
Closes the group mark opened, keeping its edits (for the
outermost group: merging and releasing as each edit alone would
have; O(edits of the group · log R)).
§Errors
TreeEditError::Internal when mark is not the innermost open
group’s (the tree is unchanged).
Sourcepub fn rollback_group(&mut self, mark: GroupMark) -> Result<(), TreeEditError>
pub fn rollback_group(&mut self, mark: GroupMark) -> Result<(), TreeEditError>
Closes the group mark opened, undoing every edit accepted in it,
latest first: the tree is exactly as at SyntaxTree::begin_group.
O(edits of the group · (log R + their size)).
§Errors
TreeEditError::Internal when mark is not the innermost open
group’s (the tree is unchanged), or an undo record does not apply
(an invariant of this crate).
Sourcepub fn extract(
&self,
first: NodeId,
last: NodeId,
) -> Result<Fragment, TreeEditError>
pub fn extract( &self, first: NodeId, last: NodeId, ) -> Result<Fragment, TreeEditError>
Copies the siblings first..=last and their subtrees into a
detached Fragment, leaving the tree as it is. O(copied).
With SyntaxTree::parse_with, this builds a fragment out of any
text through the one parser: parse a snippet written for the
target context, then extract the elements wanted.
§Errors
TreeEditError::Stale, TreeEditError::NoParent (the stream
root), TreeEditError::NotSiblings.
Sourcepub fn remove(&mut self, id: NodeId) -> Result<Fragment, TreeEditError>
pub fn remove(&mut self, id: NodeId) -> Result<Fragment, TreeEditError>
Removes element id with its subtree and returns it as a detached
fragment (with its diagnostics). Handles into it become stale.
§Errors
Sourcepub fn remove_range(
&mut self,
first: NodeId,
last: NodeId,
) -> Result<Fragment, TreeEditError>
pub fn remove_range( &mut self, first: NodeId, last: NodeId, ) -> Result<Fragment, TreeEditError>
Removes the siblings first..=last with their subtrees.
O(depth + log R + removed + window).
§Errors
TreeEditError::Stale; TreeEditError::NoParent for the stream
root; TreeEditError::NotSiblings; TreeEditError::ReadOnly
inside a scalar, alias, or error node, and for directives, tag
properties, and block scalar headers; ReadOnly { kind: Error }
for a range holding an SyntaxKind::Error node below document
level (an error region is never removed or replaced by an
edit; a whole document goes with its errors), and for an edit that
could change how recovered input reads;
TreeEditError::NotWellFormed when the text left would not read
back as the tree left (e.g. removing the : of a: 1).
Sourcepub fn replace_range(
&mut self,
first: NodeId,
last: NodeId,
with: Fragment,
) -> Result<Replaced, TreeEditError>
pub fn replace_range( &mut self, first: NodeId, last: NodeId, with: Fragment, ) -> Result<Replaced, TreeEditError>
Replaces the siblings first..=last by with’s elements. The
fragment is dropped when the edit is refused (clone it first to keep
it). O(depth + log R + removed + inserted roots + window).
§Errors
Those of SyntaxTree::remove_range and
SyntaxTree::insert_before.
Sourcepub fn insert_before(
&mut self,
sibling: NodeId,
fragment: Fragment,
) -> Result<Inserted, TreeEditError>
pub fn insert_before( &mut self, sibling: NodeId, fragment: Fragment, ) -> Result<Inserted, TreeEditError>
Inserts fragment’s elements right before sibling.
O(depth + log R + inserted roots + window). The fragment is dropped
when the edit is refused.
§Errors
TreeEditError::Stale; TreeEditError::NoParent;
TreeEditError::EmptyFragment; TreeEditError::ReadOnly
(inside a scalar, alias, or error node; directive, tag, or header
elements); TreeEditError::Misplaced;
TreeEditError::TagContext; TreeEditError::NotWellFormed
(e.g. x appended right after a: 1); TreeEditError::Capacity.
Sourcepub fn insert_after(
&mut self,
sibling: NodeId,
fragment: Fragment,
) -> Result<Inserted, TreeEditError>
pub fn insert_after( &mut self, sibling: NodeId, fragment: Fragment, ) -> Result<Inserted, TreeEditError>
Sourcepub fn append_child(
&mut self,
parent: NodeId,
fragment: Fragment,
) -> Result<Inserted, TreeEditError>
pub fn append_child( &mut self, parent: NodeId, fragment: Fragment, ) -> Result<Inserted, TreeEditError>
Inserts fragment’s elements as the last children of parent.
§Errors
As SyntaxTree::insert_before, plus TreeEditError::NotANode
when parent is a token.
Sourcepub fn replace_token(
&mut self,
id: NodeId,
text: &str,
) -> Result<NodeId, TreeEditError>
pub fn replace_token( &mut self, id: NodeId, text: &str, ) -> Result<NodeId, TreeEditError>
Replaces the text of token id, returning the new token’s handle
(the old one becomes stale). The text must read, through the one
parser under the tree’s own SyntaxTree::settings, as
exactly one token of the same kind: in flow context for a scalar,
alias, or anchor inside a flow collection. Replaceable: plain,
quoted, alias, anchor, comment, white space, and line break tokens.
The caller supplies text valid in its context (e.g. a multi-line
scalar’s indentation); the edit must be well-formed (a comment
replaced by a comment always is).
§Errors
TreeEditError::Stale; TreeEditError::NotAToken;
TreeEditError::ReadOnly for other token kinds;
TreeEditError::InvalidToken when the text does not read as one
such token; TreeEditError::NotWellFormed when it does, but not
where it would go (e.g. a multi-line key, or indentation that moves
an entry).
Source§impl SyntaxTree
impl SyntaxTree
Sourcepub fn replace_to_line_end(
&mut self,
first: NodeId,
last: NodeId,
with: Fragment,
) -> Result<Replaced, TreeEditError>
pub fn replace_to_line_end( &mut self, first: NodeId, last: NodeId, with: Fragment, ) -> Result<Replaced, TreeEditError>
Replaces the siblings first..=last, through the end of their
line, by with, whose text must end with a line break: the text
becomes the text before first, then with’s text, then the text
after the line break that ended the range’s line (block scalars replaced or inserted at the end of a
collection or document).
The range’s line ends inside its last token (a block scalar’s text
ends with its line break), at a SyntaxKind::LineBreak token
right after it (at whatever level the parser put it), or at the end
of the text. with ends its line inside its last token (a block
scalar), or with a final SyntaxKind::LineBreak element, which
goes where the parser puts it: after the collections the new
content ends, before what followed the old line. So a: |\n x\n
with the scalar replaced by 1\n gives a: 1\n, and a: 1\n
with 1 replaced by |\n x\n gives a: |\n x\n.
One or two splices, applied and checked for well-formedness as one
edit (refused, the tree is unchanged). O(depth + log R +
removed + inserted roots + windows). inserted names the
fragment’s elements without a final line break element.
§Errors
Those of SyntaxTree::replace_range;
TreeEditError::NotWellFormed also when the range’s line goes on
after it (e.g. a comment follows) or with’s text does not end
with a line break; TreeEditError::EmptyFragment for a fragment
that is only a line break.
Sourcepub fn remove_to_line_end(
&mut self,
first: NodeId,
last: NodeId,
trivia: Option<Fragment>,
) -> Result<Fragment, TreeEditError>
pub fn remove_to_line_end( &mut self, first: NodeId, last: NodeId, trivia: Option<Fragment>, ) -> Result<Fragment, TreeEditError>
Removes the siblings first..=last, through the end of their
line, and puts trivia (white space, comments, and line breaks
only, ending with a line break; None: nothing) where the parser
puts trivia after
the content before first (freeze gate:
removing the last entry of a block collection whose value is a
block scalar, as in a GitHub Actions run: | step or a ConfigMap’s
data).
The range’s line ends inside its last token (a block scalar’s text)
or at a SyntaxKind::LineBreak token right after it, which goes
too. trivia is typically the line end of the content before the
range (its same-line comment and line break): when the range is the
end of a collection, that trivia cannot stay inside it (the parser
never ends a node with trivia, C4) and goes after the collections
the content before first ends, before what followed the range’s
line (or at the end of the stream). So in a: 1\nb: |\n x\n the
siblings from the line break after 1 through the block scalar,
removed with trivia = \n, give a: 1\n with the break after the
mapping; and in o:\n a: |+\n x\n\n b: 1\nz: 2\n the siblings
from the indentation of b through 1, removed with None, give
o:\n a: |+\n x\n\nz: 2\n (the break after 1, outside the
inner mapping, goes too: left alone, the kept scalar would read it).
One or two splices, applied and checked for well-formedness as one edit (refused, the tree is unchanged). Returns the removed siblings (without the old line break token).
§Errors
Those of SyntaxTree::remove_range;
TreeEditError::NotWellFormed also when the range’s line goes on
after it or ends the text without a line break, or trivia holds
anything but white space, comments, and line breaks, or does not
end with a line break.
Sourcepub fn close_block_scalar(
&mut self,
sibling: NodeId,
brk: &str,
) -> Result<(), TreeEditError>
pub fn close_block_scalar( &mut self, sibling: NodeId, brk: &str, ) -> Result<(), TreeEditError>
Gives the block scalar that ends the text its final line break: the
scalar sibling ends (a: |-\n x at the end of the input) has a
last line that does not end, so nothing can follow it. Its text gets
brk (a line break: \n, \r\n or \r), after the white space
that ends the input behind it, if any (that white space is the text
of one more line of the scalar then: - |+\n becomes
- |+\n \n). Lines can then go after it with
SyntaxTree::insert_line_after.
One or two splices applied and checked as one edit.
§Errors
TreeEditError::NotWellFormed when sibling does not end the text
in a block scalar without a final line break, or brk is not a line
break; TreeEditError::Stale.
Sourcepub fn insert_line_after(
&mut self,
sibling: NodeId,
with: Fragment,
) -> Result<Inserted, TreeEditError>
pub fn insert_line_after( &mut self, sibling: NodeId, with: Fragment, ) -> Result<Inserted, TreeEditError>
Inserts with, whose text must end with a line break, as the lines
right after the line that sibling ends (see
SyntaxTree::replace_to_line_end): the text becomes the text
through that line’s break, then with’s text, then the rest. The
new elements go under sibling’s parent, after it; the line
breaks go where the parser puts them. So in a: |\n x\n an entry
b: 1\n inserted after the scalar gives a: |\n x\nb: 1\n, and in
a: 1\n an entry b: |\n y\n inserted after 1 gives
a: 1\nb: |\n y\n.
One or two splices, applied and checked as one edit.
inserted names what went in under the parent (a copy of
sibling’s line break first, when that break lies outside the
parent; without with’s final line break element).
Trivia: with of white space, comments, and line
breaks only (comment lines) goes wholly where the parser puts trivia
after sibling’s line: right after sibling’s line break, under
that break’s parent, or, when sibling’s line ends inside its own
text, before the element after it, under that element’s parent (or
at the end of the stream). So comment lines after a root collection
that ends with a block scalar go at stream level. inserted names
all of with’s elements.
§Errors
Those of SyntaxTree::insert_after;
TreeEditError::NotWellFormed also when sibling’s line goes on
after it or ends the text without a line break, or with’s text
does not end with one; TreeEditError::EmptyFragment.
Source§impl SyntaxTree
impl SyntaxTree
Sourcepub fn parse(source: impl Into<String>) -> Self
pub fn parse(source: impl Into<String>) -> Self
Parses source under the default Settings and builds its tree.
Pass a String to hand over its buffer; a &str is copied.
Sourcepub fn parse_with(source: impl Into<String>, settings: &Settings) -> Self
pub fn parse_with(source: impl Into<String>, settings: &Settings) -> Self
Parses source under settings and builds its tree from the pull
parser’s events as they come, without collecting them.
Sourcepub fn from_events<'a, E, I>(events: I) -> Self
pub fn from_events<'a, E, I>(events: I) -> Self
Builds the tree of an event stream, e.g. list.sourced() of an
EventList or
events_with, copying its source.
A stream from the parser always satisfies the event contract, and
its tree always round-trips. A stream that was filtered or reordered
still builds without panicking; the tree then records a Y9001
(INVALID_EVENT_STREAM)
diagnostic, covers any bytes the stream skipped with
SyntaxKind::Skipped tokens, and its spans follow the tokens it
was given.
Sourcepub fn settings(&self) -> &Settings
pub fn settings(&self) -> &Settings
The settings the tree was parsed with (Settings::new for a tree
built with SyntaxTree::from_events). Edits re-read text under
them.
Sourcepub fn source(&self) -> &str
pub fn source(&self) -> &str
The source text the tree was built from (unchanged by edits: see
SyntaxTree::emit for the current text).
Sourcepub fn root(&self) -> Node<'_>
pub fn root(&self) -> Node<'_>
The SyntaxKind::Stream node spanning the whole input.
Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
true when the tree has no elements, which never happens for a
built tree (the root always exists).
Sourcepub fn node_at_slot(&self, slot: u32) -> Option<Node<'_>>
pub fn node_at_slot(&self, slot: u32) -> Option<Node<'_>>
The live element named by slot (Node::slot), or None once
it was removed or replaced (or for a slot this tree never issued).
The same element as SyntaxTree::get resolves the handle of an
element of this tree to. O(1); O(log R) in an edited tree.
Sourcepub fn diagnostics(
&self,
) -> impl ExactSizeIterator<Item = Cow<'_, Diagnostic>> + '_
pub fn diagnostics( &self, ) -> impl ExactSizeIterator<Item = Cow<'_, Diagnostic>> + '_
Every diagnostic, errors and warnings, in element order (see
SyntaxTree::diagnostics_by_element). Borrowed from a parsed
tree; an edited tree’s are built with their spans moved to the
edited text (O(d + D log R) for the D runs holding diagnostics, no
cache). Complete: past max_diagnostics they are skeletons
(SyntaxTree::is_skeleton).
Sourcepub const fn suppressed_diagnostics(&self) -> usize
pub const fn suppressed_diagnostics(&self) -> usize
How many of the parse’s diagnostics are kept as skeletons:
a tree keeps the first Limits::max_diagnostics + 1
diagnostics of its parse in stream order with their texts, and the
first error wherever it is; every other one as a fixed-size
skeleton (32 bytes, no heap). So the tree’s record of what the
parse found (every error, its position, its error node) is complete
whatever the limit; only texts are not stored. Edits never change
the count.
Sourcepub fn is_skeleton(d: &Diagnostic) -> bool
pub fn is_skeleton(d: &Diagnostic) -> bool
Whether d is a skeleton (see
SyntaxTree::suppressed_diagnostics). Readers see a skeleton as
a diagnostic with its code, severity, and primary span, and empty
texts (no diagnostic with texts has an empty message), and nothing
else: how the tree compares skeletons with re-read diagnostics is
internal and never exposed.
Sourcepub fn diagnostics_by_element(
&self,
) -> impl ExactSizeIterator<Item = (Option<Node<'_>>, Cow<'_, Diagnostic>)> + '_
pub fn diagnostics_by_element( &self, ) -> impl ExactSizeIterator<Item = (Option<Node<'_>>, Cow<'_, Diagnostic>)> + '_
Every diagnostic with the element it is attached to, in element
order: an error’s SyntaxKind::Error node, a warning’s element
that followed it in the event stream, or None for a warning after
the last element. Consumers that read the tree as an event stream
use this to see warnings where the stream reported them.
Borrowed from a parsed tree. An edited tree’s are built on each call from the arenas’ own lists, spans moved to the edited text: O(d + D (log d + log R)) for d diagnostics, R runs, and the D runs holding any (the others are skipped by the treap’s sums), and nothing is cached.
Sourcepub fn diagnostics_within<'s>(
&'s self,
node: Node<'s>,
) -> impl ExactSizeIterator<Item = (Option<Node<'s>>, Cow<'s, Diagnostic>)> + 's
pub fn diagnostics_within<'s>( &'s self, node: Node<'s>, ) -> impl ExactSizeIterator<Item = (Option<Node<'s>>, Cow<'s, Diagnostic>)> + 's
The diagnostics attached to elements of node‘s subtree (see
SyntaxTree::diagnostics_by_element), in element order. Found by
binary search: O(log d + k) for k results, so reading one
document of a stream does not scan the others’ diagnostics; in an
edited tree O(D’ (log d + log R) + k) for the D’ runs of the subtree
holding diagnostics (never the subtree’s other runs), with
nothing rebuilt for the rest of the tree.
Sourcepub fn diagnostics_within_filled<'s>(
&'s self,
node: Node<'s>,
fill: &'s [Diagnostic],
) -> impl ExactSizeIterator<Item = (Option<Node<'s>>, Cow<'s, Diagnostic>)> + 's
pub fn diagnostics_within_filled<'s>( &'s self, node: Node<'s>, fill: &'s [Diagnostic], ) -> impl ExactSizeIterator<Item = (Option<Node<'s>>, Cow<'s, Diagnostic>)> + 's
SyntaxTree::diagnostics_within, with each skeleton
(SyntaxTree::is_skeleton) that a diagnostic of fill records
read as that diagnostic, texts included: fill
holds diagnostics with texts found by reading the same text again
(with spans in this tree’s text), sorted by start. A skeleton
records a diagnostic when they have the same code, severity,
primary span, label reach, and keyed fingerprint of everything the
skeleton does not keep (as the tree compares them when it re-reads
an edit’s text), so a skeleton is never given another
diagnostic’s texts; one that none records stays a skeleton. Cost:
as SyntaxTree::diagnostics_within, plus O(log f) per skeleton.
Sourcepub fn has_errors(&self) -> bool
pub fn has_errors(&self) -> bool
true when the tree has at least one error. O(1): the count is
kept by every edit.
Sourcepub fn fork(&self) -> Self
pub fn fork(&self) -> Self
A copy that shares this tree’s handle identity:
every NodeId issued before the fork, by this tree
or the copy, resolves in both to the same element for as long as
that copy keeps it, and Node::id of such an element is the same
value in both. Elements inserted after the fork get handles of
their own tree, stale in the other; an element removed from one
copy is stale there only. Forks of forks work the same way.
Clone gives an independent tree instead (no handle of the
original resolves in it).
Cost: O(n + L) for the parsed text and arrays (n) and the live
edits (L: the inserted arenas some run still covers, the runs, the
link overrides of live slots; never the edit history,
since text removed by accepted edits is dropped with its arena),
plus one (stamp, slot) pair of metadata per ancestor range that
still holds a live slot (no per-copy translation map, pairs of
ranges without live slots are dropped); resolving a handle is
O(log A) for A such pairs.
Sourcepub fn emit(&self) -> String
pub fn emit(&self) -> String
The text of the tree: its tokens’ bytes in order. For a tree that was not edited this is exactly the input; for an edited tree, exactly the input with each edit’s bytes spliced in. O(n): an edited tree’s text is copied run by run, O(1) per run beyond its bytes, with no map lookup (a run holds at least one element).
Trait Implementations§
Source§impl Clone for SyntaxTree
impl Clone for SyntaxTree
Source§fn clone(&self) -> Self
fn clone(&self) -> Self
An independent copy with its own stamp: handles of the original do
not resolve in the copy (they may diverge once edited). See
SyntaxTree::fork for a copy that keeps them.
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for SyntaxTree
impl Debug for SyntaxTree
impl Eq for SyntaxTree
Source§impl Hash for SyntaxTree
impl Hash for SyntaxTree
Source§impl PartialEq for SyntaxTree
impl PartialEq for SyntaxTree
Source§fn eq(&self, other: &Self) -> bool
fn eq(&self, other: &Self) -> bool
Structural equality (compare_trees): the same elements in the
same shape, token texts, block headers, resolved tags, and
diagnostics. Not the stamp, the generations, or how edits laid the
tree out, so an edited tree equals the tree parsed from its
SyntaxTree::emit exactly when they agree structurally.