Struct rowan::SyntaxNode[][src]

pub struct SyntaxNode<T: Types, R: TreeRoot<T>> { /* fields omitted */ }

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]

Creates a new SyntaxNode.

impl<'a, T: Types> SyntaxNode<T, RefRoot<'a, T>>
[src]

Text of this node if it is a leaf.

impl<T: Types, R: TreeRoot<T>> SyntaxNode<T, R>
[src]

Switch this node to borrowed flavor.

Switch this node to owned flavor.

Get root data.

Get kind of this node.

Get text range, covered by this node.

Get the parent node.

Important traits for SyntaxNodeChildren<T, R>

Get iterator over children.

Get first child.

Get last child.

Get next sibling.

Get previous sibling.

Returns true if this node is a leaf node.

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]

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

impl<T: Types, R: TreeRoot<T>> Eq for SyntaxNode<T, R>
[src]

impl<T: Types, R: TreeRoot<T>> Hash for SyntaxNode<T, R>
[src]

Feeds this value into the given [Hasher]. Read more

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]

Returns a copy of the value. Read more

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>> Debug for SyntaxNode<T, R>
[src]

Formats the value using the given formatter. Read more

Auto Trait Implementations

impl<T, R> Send for SyntaxNode<T, R>

impl<T, R> Sync for SyntaxNode<T, R>