[][src]Struct rowan::SyntaxNode

pub struct SyntaxNode { /* 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

All nodes constituting a tree share the ownership by a tree. Internally, and Arc is used, but outside world observes nodes as &SyntaxNode or TreeArc<SyntaxNode>, where a TreeArc is an Arc-like smart pointer.

Methods

impl SyntaxNode[src]

pub fn new(
    green: GreenNode,
    data: Option<Box<dyn Any + Send + Sync>>
) -> TreeArc<SyntaxNode>
[src]

Creates a new SyntaxNode, which becomes the root of the tree.

pub fn root_data(&self) -> Option<&(dyn Any + Send + Sync)>[src]

Get root data.

pub fn green(&self) -> &GreenNode[src]

Get the green node for this node

pub fn kind(&self) -> SyntaxKind[src]

Get kind of this node.

pub fn range(&self) -> TextRange[src]

Get text range, covered by this node.

pub fn parent(&self) -> Option<&SyntaxNode>[src]

Get the parent node.

pub fn first_child(&self) -> Option<&SyntaxNode>[src]

Get first child, excluding tokens.

pub fn first_child_or_token(&self) -> Option<SyntaxElement>[src]

Get the first, including tokens.

pub fn last_child(&self) -> Option<&SyntaxNode>[src]

Get last child, excluding tokens.

pub fn last_child_or_token(&self) -> Option<SyntaxElement>[src]

Get last child, including tokens.

pub fn next_sibling(&self) -> Option<&SyntaxNode>[src]

Get next sibling, excluding tokens.

pub fn next_sibling_or_token(&self) -> Option<SyntaxElement>[src]

Get next sibling, including tokens.

pub fn prev_sibling(&self) -> Option<&SyntaxNode>[src]

Get previous sibling, excluding tokens.

pub fn prev_sibling_or_token(&self) -> Option<SyntaxElement>[src]

Get previous sibling, including tokens.

pub fn first_token(&self) -> Option<SyntaxToken>[src]

Return the leftmost token in the subtree of this node

pub fn last_token(&self) -> Option<SyntaxToken>[src]

Return the rightmost token in the subtree of this node

pub fn replace_with(&self, replacement: GreenNode) -> GreenNode[src]

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

impl SyntaxNode[src]

Important traits for SyntaxNodeChildren<'a>
pub fn children(&self) -> SyntaxNodeChildren[src]

Get iterator over children, excluding tokens.

Important traits for SyntaxElementChildren<'a>
pub fn children_with_tokens(&self) -> SyntaxElementChildren[src]

Get iterator over children, including tokens.

pub fn ancestors(&self) -> impl Iterator<Item = &SyntaxNode>[src]

All ancestors of the current node, including itself

pub fn preorder(&self) -> impl Iterator<Item = WalkEvent<&SyntaxNode>>[src]

Traverse the subtree rooted at the current node (including the current node) in preorder, excluding tokens.

pub fn preorder_with_tokens<'a>(
    &'a self
) -> impl Iterator<Item = WalkEvent<SyntaxElement<'a>>>
[src]

Traverse the subtree rooted at the current node (including the current node) in preorder, including tokens.

pub fn common_ancestor<'a>(&'a self, other: &'a SyntaxNode) -> &'a SyntaxNode[src]

Returns common ancestor of the two nodes. Precondition: nodes must be from the same tree.

Important traits for TokenAtOffset<T>
pub fn token_at_offset<'a>(
    &'a self,
    offset: TextUnit
) -> TokenAtOffset<SyntaxToken<'a>>
[src]

Find a token in the subtree corresponding to this node, which covers the offset. Precondition: offset must be withing node's range.

pub fn covering_node(&self, range: TextRange) -> SyntaxElement[src]

Return the deepest node or token in the current subtree that fully contains the range. If the range is empty and is contained in two leaf nodes, either one can be returned. Precondition: range must be contained withing the current node

pub fn memory_size_of_subtree(&self) -> usize[src]

Number of memory bytes of occupied by subtree rooted at self.

Trait Implementations

impl TransparentNewType for SyntaxNode[src]

type Repr = SyntaxNode

Underlying representation of a newtype.

impl ToOwned for SyntaxNode[src]

type Owned = TreeArc<SyntaxNode>

The resulting type after obtaining ownership.

fn clone_into(&self, target: &mut Self::Owned)[src]

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

impl Sync for SyntaxNode[src]

impl Eq for SyntaxNode[src]

impl Send for SyntaxNode[src]

impl PartialEq<SyntaxNode> for SyntaxNode[src]

#[must_use]
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]

This method tests for !=.

impl<'a> From<&'a SyntaxNode> for SyntaxElement<'a>[src]

impl Debug for SyntaxNode[src]

impl Display for SyntaxNode[src]

impl Hash for SyntaxNode[src]

fn hash_slice<H>(data: &[Self], state: &mut H) where
    H: Hasher
1.3.0[src]

Feeds a slice of this type into the given [Hasher]. Read more

impl UnwindSafe for SyntaxNode[src]

impl RefUnwindSafe for SyntaxNode[src]

Blanket Implementations

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]