Struct NodeMatch

Source
pub struct NodeMatch<'t, D: Doc>(/* private fields */);
Expand description

Represents the matched node with populated MetaVarEnv. It derefs to the Node so you can use it as a Node. To access the underlying MetaVarEnv, call get_env method.

Implementations§

Source§

impl<'tree, D: Doc> NodeMatch<'tree, D>

Source

pub fn new(node: Node<'tree, D>, env: MetaVarEnv<'tree, D>) -> Self

Source

pub fn get_node(&self) -> &Node<'tree, D>

Source

pub fn get_env(&self) -> &MetaVarEnv<'tree, D>

Returns the populated MetaVarEnv for this match.

Source

pub fn get_env_mut(&mut self) -> &mut MetaVarEnv<'tree, D>

Source§

impl<D: Doc> NodeMatch<'_, D>

Source

pub fn replace_by<R: Replacer<D>>( &self, replacer: R, ) -> Edit<<D as Doc>::Source>

Methods from Deref<Target = Node<'tree, D>>§

Source

pub fn get_doc(&self) -> &'r D

Source

pub fn node_id(&self) -> usize

Source

pub fn is_leaf(&self) -> bool

Source

pub fn is_named_leaf(&self) -> bool

if has no named children. N.B. it is different from is_named && is_leaf

Source

pub fn is_error(&self) -> bool

Source

pub fn kind(&self) -> Cow<'_, str>

Source

pub fn kind_id(&self) -> u16

Source

pub fn is_named(&self) -> bool

Source

pub fn is_missing(&self) -> bool

Source

pub fn range(&self) -> Range<usize>

byte offsets of start and end.

Source

pub fn start_pos(&self) -> Position

Nodes’ start position in terms of zero-based rows and columns.

Source

pub fn end_pos(&self) -> Position

Nodes’ end position in terms of rows and columns.

Source

pub fn text(&self) -> Cow<'r, str>

Source

pub fn lang(&self) -> &'r D::Lang

Source

pub fn get_inner_node(&self) -> D::Node<'r>

the underlying tree-sitter Node

Source

pub fn root(&self) -> &'r Root<D>

Source

pub fn matches<M: Matcher>(&self, m: M) -> bool

Source

pub fn inside<M: Matcher>(&self, m: M) -> bool

Source

pub fn has<M: Matcher>(&self, m: M) -> bool

Source

pub fn precedes<M: Matcher>(&self, m: M) -> bool

Source

pub fn follows<M: Matcher>(&self, m: M) -> bool

Source

pub fn parent(&self) -> Option<Self>

Source

pub fn children(&self) -> impl ExactSizeIterator<Item = Node<'r, D>> + '_

Source

pub fn child(&self, nth: usize) -> Option<Self>

Source

pub fn field(&self, name: &str) -> Option<Self>

Source

pub fn child_by_field_id(&self, field_id: u16) -> Option<Self>

Source

pub fn field_children( &self, name: &str, ) -> impl Iterator<Item = Node<'r, D>> + '_

Source

pub fn ancestors(&self) -> impl Iterator<Item = Node<'r, D>> + '_

Returns all ancestors nodes of self. Using cursor is overkill here because adjust cursor is too expensive.

Source

pub fn next(&self) -> Option<Self>

Source

pub fn next_all(&self) -> impl Iterator<Item = Node<'r, D>> + '_

Returns all sibling nodes next to self.

Source

pub fn prev(&self) -> Option<Node<'r, D>>

Source

pub fn prev_all(&self) -> impl Iterator<Item = Node<'r, D>> + '_

Source

pub fn dfs<'s>(&'s self) -> impl Iterator<Item = Node<'r, D>> + 's

Source

pub fn find<M: Matcher>(&self, pat: M) -> Option<NodeMatch<'r, D>>

Source

pub fn find_all<'s, M: Matcher + 's>( &'s self, pat: M, ) -> impl Iterator<Item = NodeMatch<'r, D>> + 's

Source

pub fn replace<M: Matcher, R: Replacer<D>>( &self, matcher: M, replacer: R, ) -> Option<Edit<<D as Doc>::Source>>

Source

pub fn after(&self) -> Edit<<D as Doc>::Source>

Source

pub fn before(&self) -> Edit<<D as Doc>::Source>

Source

pub fn append(&self) -> Edit<<D as Doc>::Source>

Source

pub fn prepend(&self) -> Edit<<D as Doc>::Source>

Source

pub fn empty(&self) -> Option<Edit<<D as Doc>::Source>>

Empty children. Remove all child node

Source

pub fn remove(&self) -> Edit<<D as Doc>::Source>

Remove the node itself

Trait Implementations§

Source§

impl<'tree, D: Doc> Borrow<Node<'tree, D>> for NodeMatch<'tree, D>

NodeMatch is an immutable view to Node

Source§

fn borrow(&self) -> &Node<'tree, D>

Immutably borrows from an owned value. Read more
Source§

impl<'t, D: Clone + Doc> Clone for NodeMatch<'t, D>

Source§

fn clone(&self) -> NodeMatch<'t, D>

Returns a duplicate of the value. Read more
1.0.0 · Source§

const fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'tree, D: Doc> Deref for NodeMatch<'tree, D>

NodeMatch is an immutable view to Node

Source§

type Target = Node<'tree, D>

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl<'tree, D: Doc> From<Node<'tree, D>> for NodeMatch<'tree, D>

Source§

fn from(node: Node<'tree, D>) -> Self

Converts to this type from the input type.
Source§

impl<'tree, D: Doc> From<NodeMatch<'tree, D>> for Node<'tree, D>

NodeMatch is an immutable view to Node

Source§

fn from(node_match: NodeMatch<'tree, D>) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

§

impl<'t, D> Freeze for NodeMatch<'t, D>
where <D as Doc>::Node<'t>: Freeze,

§

impl<'t, D> RefUnwindSafe for NodeMatch<'t, D>
where <D as Doc>::Node<'t>: RefUnwindSafe, D: RefUnwindSafe, <<D as Doc>::Source as Content>::Underlying: RefUnwindSafe,

§

impl<'t, D> Send for NodeMatch<'t, D>
where <D as Doc>::Node<'t>: Send, D: Sync, <<D as Doc>::Source as Content>::Underlying: Send,

§

impl<'t, D> Sync for NodeMatch<'t, D>
where <D as Doc>::Node<'t>: Sync, D: Sync, <<D as Doc>::Source as Content>::Underlying: Sync,

§

impl<'t, D> Unpin for NodeMatch<'t, D>
where <D as Doc>::Node<'t>: Unpin, <<D as Doc>::Source as Content>::Underlying: Unpin,

§

impl<'t, D> UnwindSafe for NodeMatch<'t, D>
where <D as Doc>::Node<'t>: UnwindSafe, D: RefUnwindSafe, <<D as Doc>::Source as Content>::Underlying: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

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

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.