Struct cstree::syntax::SyntaxNode [−][src]
Inner syntax tree node. Syntax nodes can be shared between threads. Every syntax tree is reference counted as a whole and nodes are pointer-sized, so copying individual nodes is relatively cheap.
Implementations
impl<L: Language, D> SyntaxNode<L, D>
[src]
pub fn debug<R: ?Sized>(&self, resolver: &R, recursive: bool) -> String where
R: Resolver,
[src]
R: Resolver,
pub fn display<R: ?Sized>(&self, resolver: &R) -> String where
R: Resolver,
[src]
R: Resolver,
pub fn resolver(&self) -> Option<&StdArc<dyn Resolver>>
[src]
If there is a resolver associated with this tree, returns it.
pub fn try_resolved(&self) -> Option<&ResolvedNode<L, D>>
[src]
Turns this node into a ResolvedNode
, but only if there is a resolver associated with this tree.
pub fn resolved(&self) -> &ResolvedNode<L, D>
[src]
impl<L: Language, D> SyntaxNode<L, D>
[src]
pub fn root(&self) -> &SyntaxNode<L, D>
[src]
The root of the tree this node belongs to.
If this node is the root, returns self
.
impl<L: Language, D> SyntaxNode<L, D>
[src]
pub fn new_root(green: GreenNode) -> Self
[src]
Build a new syntax tree on top of a green tree.
Example
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] #[repr(u16)] enum SyntaxKind { ROOT, } #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] enum Lang {} impl cstree::Language for Lang { // ... } let root: SyntaxNode<Lang> = SyntaxNode::new_root(green); assert_eq!(root.kind(), SyntaxKind::ROOT);
pub fn new_root_with_resolver(
green: GreenNode,
resolver: impl Resolver + 'static
) -> ResolvedNode<L, D>
[src]
green: GreenNode,
resolver: impl Resolver + 'static
) -> ResolvedNode<L, D>
Build a new syntax tree on top of a green tree and associate a resolver with the tree to resolve interned Strings.
Example
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] #[repr(u16)] enum SyntaxKind { TOKEN, ROOT, } #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] enum Lang {} impl cstree::Language for Lang { // ... } let mut builder = GreenNodeBuilder::new(); builder.start_node(ROOT); builder.token(TOKEN, "content"); builder.finish_node(); let (green, resolver) = builder.finish(); let root: ResolvedNode<Lang> = SyntaxNode::new_root_with_resolver(green, resolver.unwrap()); assert_eq!(root.text(), "content");
pub fn set_data(&self, data: D) -> Arc<D>
[src]
Stores custom data for this node. If there was previous data associated with this node, it will be replaced.
pub fn try_set_data(&self, data: D) -> Result<Arc<D>, D>
[src]
Stores custom data for this node, but only if no data was previously set. If it was, the given data is returned unchanged.
pub fn get_data(&self) -> Option<Arc<D>>
[src]
Returns the data associated with this node, if any.
pub fn clear_data(&self)
[src]
Removes the data associated with 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
pub fn syntax_kind(&self) -> SyntaxKind
[src]
The internal representation of the kind of this node.
pub fn kind(&self) -> L::Kind
[src]
The kind of this node in terms of your language.
pub fn text_range(&self) -> TextRange
[src]
The range this node covers in the source text, in bytes.
pub fn resolve_text<'n, 'i, I: ?Sized>(
&'n self,
resolver: &'i I
) -> SyntaxText<'n, 'i, I, L, D> where
I: Resolver,
[src]
&'n self,
resolver: &'i I
) -> SyntaxText<'n, 'i, I, L, D> where
I: Resolver,
Uses the provided resolver to return an efficient representation of all source text covered by this node, i.e. the combined text of all token leafs of the subtree originating in this node.
pub fn green(&self) -> &GreenNode
[src]
Returns the unterlying green tree node of this node.
pub fn parent(&self) -> Option<&SyntaxNode<L, D>>
[src]
The parent node of this node, except if this node is the root.
pub fn arity(&self) -> usize
[src]
The number of child nodes (!) of this node.
If you want to also consider leafs, see arity_with_tokens
.
pub fn arity_with_tokens(&self) -> usize
[src]
The number of children of this node.
pub fn ancestors(&self) -> impl Iterator<Item = &SyntaxNode<L, D>>
[src]
Returns an iterator along the chain of parents of this node.
pub fn children(&self) -> SyntaxNodeChildren<'_, L, D>ⓘNotable traits for SyntaxNodeChildren<'n, L, D>
impl<'n, L: Language, D> Iterator for SyntaxNodeChildren<'n, L, D> type Item = &'n SyntaxNode<L, D>;
[src]
Notable traits for SyntaxNodeChildren<'n, L, D>
impl<'n, L: Language, D> Iterator for SyntaxNodeChildren<'n, L, D> type Item = &'n SyntaxNode<L, D>;
Returns an iterator over all nodes that are children of this node.
If you want to also consider leafs, see children_with_tokens
.
pub fn children_with_tokens(&self) -> SyntaxElementChildren<'_, L, D>ⓘNotable traits for SyntaxElementChildren<'n, L, D>
impl<'n, L: Language, D> Iterator for SyntaxElementChildren<'n, L, D> type Item = SyntaxElementRef<'n, L, D>;
[src]
Notable traits for SyntaxElementChildren<'n, L, D>
impl<'n, L: Language, D> Iterator for SyntaxElementChildren<'n, L, D> type Item = SyntaxElementRef<'n, L, D>;
Returns an iterator over child elements of this node, including tokens.
pub fn first_child(&self) -> Option<&SyntaxNode<L, D>>
[src]
The first child node of this node, if any.
If you want to also consider leafs, see first_child_or_token
.
pub fn first_child_or_token(&self) -> Option<SyntaxElementRef<'_, L, D>>
[src]
The first child element of this node, if any, including tokens.
pub fn last_child(&self) -> Option<&SyntaxNode<L, D>>
[src]
The last child node of this node, if any.
If you want to also consider leafs, see last_child_or_token
.
pub fn last_child_or_token(&self) -> Option<SyntaxElementRef<'_, L, D>>
[src]
The last child element of this node, if any, including tokens.
pub fn next_child_after(
&self,
n: usize,
offset: TextSize
) -> Option<&SyntaxNode<L, D>>
[src]
&self,
n: usize,
offset: TextSize
) -> Option<&SyntaxNode<L, D>>
The first child node of this node starting at the (n + 1)-st, if any.
Note that even if this method returns Some
, the contained node may not actually be the (n +
1)-st child, but the next child from there that is a node.
If you want to also consider leafs, see next_child_or_token_after
.
pub fn next_child_or_token_after(
&self,
n: usize,
offset: TextSize
) -> Option<SyntaxElementRef<'_, L, D>>
[src]
&self,
n: usize,
offset: TextSize
) -> Option<SyntaxElementRef<'_, L, D>>
The first child element of this node starting at the (n + 1)-st, if any.
If this method returns Some
, the contained node is the (n + 1)-st child of this node.
pub fn prev_child_before(
&self,
n: usize,
offset: TextSize
) -> Option<&SyntaxNode<L, D>>
[src]
&self,
n: usize,
offset: TextSize
) -> Option<&SyntaxNode<L, D>>
The last child node of this node up to the nth, if any.
Note that even if this method returns Some
, the contained node may not actually be the (n -
1)-st child, but the previous child from there that is a node.
If you want to also consider leafs, see prev_child_or_token_before
.
pub fn prev_child_or_token_before(
&self,
n: usize,
offset: TextSize
) -> Option<SyntaxElementRef<'_, L, D>>
[src]
&self,
n: usize,
offset: TextSize
) -> Option<SyntaxElementRef<'_, L, D>>
The last child node of this node up to the nth, if any.
If this method returns Some
, the contained node is the (n - 1)-st child.
pub fn next_sibling(&self) -> Option<&SyntaxNode<L, D>>
[src]
The node to the right of this one, i.e. the next child node (!) of this node’s parent after this node.
If you want to also consider leafs, see next_sibling_or_token
.
pub fn next_sibling_or_token(&self) -> Option<SyntaxElementRef<'_, L, D>>
[src]
The tree element to the right of this one, i.e. the next child of this node’s parent after this node.
pub fn prev_sibling(&self) -> Option<&SyntaxNode<L, D>>
[src]
The node to the left of this one, i.e. the previous child node (!) of this node’s parent before this node.
If you want to also consider leafs, see prev_sibling_or_token
.
pub fn prev_sibling_or_token(&self) -> Option<SyntaxElementRef<'_, L, D>>
[src]
The tree element to the left of this one, i.e. the previous child of this node’s parent before this node.
pub fn first_token(&self) -> Option<&SyntaxToken<L, D>>
[src]
Return the leftmost token in the subtree of this node
pub fn last_token(&self) -> Option<&SyntaxToken<L, D>>
[src]
Return the rightmost token in the subtree of this node
pub fn siblings(
&self,
direction: Direction
) -> impl Iterator<Item = &SyntaxNode<L, D>>
[src]
&self,
direction: Direction
) -> impl Iterator<Item = &SyntaxNode<L, D>>
Returns an iterator over all sibling nodes of this node in the given direction
, i.e. all of
this node’s parent’s child nodes (!) from this node on to the left or the right. The first
item in the iterator will always be this node.
If you want to also consider leafs, see siblings_with_tokens
.
pub fn siblings_with_tokens(
&self,
direction: Direction
) -> impl Iterator<Item = SyntaxElementRef<'_, L, D>>
[src]
&self,
direction: Direction
) -> impl Iterator<Item = SyntaxElementRef<'_, L, D>>
Returns an iterator over all siblings of this node in the given direction
, i.e. all of this
node’s parent’s children from this node on to the left or the right.
The first item in the iterator will always be this node.
pub fn descendants(&self) -> impl Iterator<Item = &SyntaxNode<L, D>>
[src]
Returns an iterator over all nodes (!) in the subtree starting at this node, including this node.
If you want to also consider leafs, see descendants_with_tokens
.
pub fn descendants_with_tokens(
&self
) -> impl Iterator<Item = SyntaxElementRef<'_, L, D>>
[src]
&self
) -> impl Iterator<Item = SyntaxElementRef<'_, L, D>>
Returns an iterator over all elements in the subtree starting at this node, including this node.
pub fn preorder(&self) -> impl Iterator<Item = WalkEvent<&SyntaxNode<L, D>>>
[src]
Traverse the subtree rooted at the current node (including the current node) in preorder, excluding tokens.
pub fn preorder_with_tokens(
&self
) -> impl Iterator<Item = WalkEvent<SyntaxElementRef<'_, L, D>>>
[src]
&self
) -> impl Iterator<Item = WalkEvent<SyntaxElementRef<'_, L, D>>>
Traverse the subtree rooted at the current node (including the current node) in preorder, including tokens.
pub fn token_at_offset(
&self,
offset: TextSize
) -> TokenAtOffset<SyntaxToken<L, D>>ⓘNotable traits for TokenAtOffset<T>
impl<T> Iterator for TokenAtOffset<T> type Item = T;
[src]
&self,
offset: TextSize
) -> TokenAtOffset<SyntaxToken<L, D>>ⓘ
Notable traits for TokenAtOffset<T>
impl<T> Iterator for TokenAtOffset<T> type Item = T;
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_element(&self, range: TextRange) -> SyntaxElementRef<'_, L, D>
[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
impl<L, D> SyntaxNode<L, D> where
L: Language,
[src]
L: Language,
pub fn as_serialize_with_data_with_resolver<'node>(
&'node self,
resolver: &'node impl Resolver
) -> impl Serialize + 'node where
D: Serialize,
[src]
&'node self,
resolver: &'node impl Resolver
) -> impl Serialize + 'node where
D: Serialize,
Return an anonymous object that can be used to serialize this node, including the data and by using an external resolver.
pub fn as_serialize_with_resolver<'node>(
&'node self,
resolver: &'node impl Resolver
) -> impl Serialize + 'node
[src]
&'node self,
resolver: &'node impl Resolver
) -> impl Serialize + 'node
Return an anonymous object that can be used to serialize this node, which uses the given resolver instead of the resolver inside the tree.
Trait Implementations
impl<L: Language, D> Clone for SyntaxNode<L, D>
[src]
fn clone(&self) -> Self
[src]
pub fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl<L: Language, D> Drop for SyntaxNode<L, D>
[src]
impl<L: Language, D> Eq for SyntaxNode<L, D>
[src]
impl<'a, L: Language, D> From<&'a SyntaxNode<L, D>> for SyntaxElementRef<'a, L, D>
[src]
fn from(node: &'a SyntaxNode<L, D>) -> Self
[src]
impl<L: Language, D> From<SyntaxNode<L, D>> for SyntaxElement<L, D>
[src]
fn from(node: SyntaxNode<L, D>) -> SyntaxElement<L, D>
[src]
impl<L: Language, D> Hash for SyntaxNode<L, D>
[src]
fn hash<H: Hasher>(&self, state: &mut H)
[src]
pub fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
impl<L: Language, D> PartialEq<SyntaxNode<L, D>> for SyntaxNode<L, D>
[src]
fn eq(&self, other: &SyntaxNode<L, D>) -> bool
[src]
#[must_use]pub fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
impl<L: Language, D: 'static> Send for SyntaxNode<L, D>
[src]
impl<L: Language, D: 'static> Sync for SyntaxNode<L, D>
[src]
Auto Trait Implementations
impl<L, D = ()> !RefUnwindSafe for SyntaxNode<L, D>
impl<L, D> Unpin for SyntaxNode<L, D>
impl<L, D = ()> !UnwindSafe for SyntaxNode<L, D>
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> CallHasher for T where
T: Hash,
T: Hash,
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,