Struct rowan::SyntaxNode [−][src]
An immutable lazy constructed syntax tree with offsets and parent pointers.
The design is close to https://github.com/apple/swift/tree/bc3189a2d265bf7728ea0cfeb55f032bfe5beaf1/lib/Syntax
SyntaxNode
exists in two flavors:
- owned (R = OwnedRoot
) - borrowed (R = RefRoot<'a, T>)
Borrowed SyntaxNode
is Copy
, but is parametrized over a lifetime,
with a corresponding ergonomics hit.
Owned SyntaxNode
is Clone
(using Arc::clone
under the hood) and
is not parametrized over a lifetime. Note that becaue of the parent
links SyntaxNode
keeps all of its ancestors alive, and not only descendents,
so keep an eye on memory leaks.
Methods like parent
or children
preserv the flavor (borrowed or owned)
of nodes, but you can switch between them at any time using .borrowed()
and .owned()
methods. As a rule of thumb, when processing nodes, use
borowed version to avoid excessive Arc trafic, and, when storing nodes
in data structures, use owned variant, to avoid dealing with lifetimes.
SyntaxNode
have object identity equality and hash semantics.
Methods
impl<T: Types> SyntaxNode<T, OwnedRoot<T>>
[src]
impl<T: Types> SyntaxNode<T, OwnedRoot<T>>
impl<'a, T: Types> SyntaxNode<T, RefRoot<'a, T>>
[src]
impl<'a, T: Types> SyntaxNode<T, RefRoot<'a, T>>
impl<T: Types, R: TreeRoot<T>> SyntaxNode<T, R>
[src]
impl<T: Types, R: TreeRoot<T>> SyntaxNode<T, R>
pub fn borrowed<'a>(&'a self) -> SyntaxNode<T, RefRoot<'a, T>>
[src]
pub fn borrowed<'a>(&'a self) -> SyntaxNode<T, RefRoot<'a, T>>
Switch this node to borrowed flavor.
pub fn owned(&self) -> SyntaxNode<T, OwnedRoot<T>>
[src]
pub fn owned(&self) -> SyntaxNode<T, OwnedRoot<T>>
Switch this node to owned flavor.
pub fn root_data(&self) -> &T::RootData
[src]
pub fn root_data(&self) -> &T::RootData
Get root data.
pub fn kind(&self) -> T::Kind
[src]
pub fn kind(&self) -> T::Kind
Get kind of this node.
pub fn range(&self) -> TextRange
[src]
pub fn range(&self) -> TextRange
Get text range, covered by this node.
pub fn parent(&self) -> Option<SyntaxNode<T, R>>
[src]
pub fn parent(&self) -> Option<SyntaxNode<T, R>>
Get the parent node.
ⓘImportant traits for SyntaxNodeChildren<T, R>pub fn children(&self) -> SyntaxNodeChildren<T, R>
[src]
pub fn children(&self) -> SyntaxNodeChildren<T, R>
Get iterator over children.
pub fn first_child(&self) -> Option<SyntaxNode<T, R>>
[src]
pub fn first_child(&self) -> Option<SyntaxNode<T, R>>
Get first child.
pub fn last_child(&self) -> Option<SyntaxNode<T, R>>
[src]
pub fn last_child(&self) -> Option<SyntaxNode<T, R>>
Get last child.
pub fn next_sibling(&self) -> Option<SyntaxNode<T, R>>
[src]
pub fn next_sibling(&self) -> Option<SyntaxNode<T, R>>
Get next sibling.
pub fn prev_sibling(&self) -> Option<SyntaxNode<T, R>>
[src]
pub fn prev_sibling(&self) -> Option<SyntaxNode<T, R>>
Get previous sibling.
pub fn is_leaf(&self) -> bool
[src]
pub fn is_leaf(&self) -> bool
Returns true
if this node is a leaf node.
pub fn replace_with(&self, green: GreenNode<T>) -> GreenNode<T>
[src]
pub fn replace_with(&self, green: GreenNode<T>) -> GreenNode<T>
Returns a green tree, equal to the green tree this node belongs two, except with this node substitute. The complexity of operation is proportional to the depth of the tree TODO: naming is unfortunate, the return value is not current node, it is the new root node.
Trait Implementations
impl<T, R1, R2> PartialEq<SyntaxNode<T, R1>> for SyntaxNode<T, R2> where
T: Types,
R1: TreeRoot<T>,
R2: TreeRoot<T>,
[src]
impl<T, R1, R2> PartialEq<SyntaxNode<T, R1>> for SyntaxNode<T, R2> where
T: Types,
R1: TreeRoot<T>,
R2: TreeRoot<T>,
fn eq(&self, other: &SyntaxNode<T, R1>) -> bool
[src]
fn eq(&self, other: &SyntaxNode<T, R1>) -> bool
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
fn ne(&self, other: &Rhs) -> bool
This method tests for !=
.
impl<T: Types, R: TreeRoot<T>> Eq for SyntaxNode<T, R>
[src]
impl<T: Types, R: TreeRoot<T>> Eq for SyntaxNode<T, R>
impl<T: Types, R: TreeRoot<T>> Hash for SyntaxNode<T, R>
[src]
impl<T: Types, R: TreeRoot<T>> Hash for SyntaxNode<T, R>
fn hash<H: Hasher>(&self, state: &mut H)
[src]
fn hash<H: Hasher>(&self, state: &mut H)
Feeds this value into the given [Hasher
]. Read more
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
Feeds a slice of this type into the given [Hasher
]. Read more
impl<T: Types, R: TreeRoot<T> + Clone> Clone for SyntaxNode<T, R>
[src]
impl<T: Types, R: TreeRoot<T> + Clone> Clone for SyntaxNode<T, R>
fn clone(&self) -> SyntaxNode<T, R>
[src]
fn clone(&self) -> SyntaxNode<T, R>
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0[src]
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
impl<T: Types, R: TreeRoot<T> + Copy> Copy for SyntaxNode<T, R>
[src]
impl<T: Types, R: TreeRoot<T> + Copy> Copy for SyntaxNode<T, R>
impl<T: Types, R: TreeRoot<T>> Debug for SyntaxNode<T, R>
[src]
impl<T: Types, R: TreeRoot<T>> Debug for SyntaxNode<T, R>
Auto Trait Implementations
impl<T, R> Send for SyntaxNode<T, R>
impl<T, R> Send for SyntaxNode<T, R>
impl<T, R> Sync for SyntaxNode<T, R>
impl<T, R> Sync for SyntaxNode<T, R>