Struct ast_grep_core::matcher::NodeMatch

source ·
pub struct NodeMatch<'tree, 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<'tree, D: Doc> NodeMatch<'tree, D>

source

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

Methods from Deref<Target = Node<'tree, 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 get_ts_node(&self) -> Node<'r>

the underlying tree-sitter Node

source

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

byte offsets of start and end.

source

pub fn start_pos(&self) -> (usize, usize)

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

source

pub fn end_pos(&self) -> (usize, usize)

Nodes’ end position in terms of rows and columns.

source

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

source

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

Node’s tree structure dumped in Lisp like S-expression

source

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

source

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

source

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

source

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

source

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

source

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

source

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

source

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

source

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

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. Note: each invocation of the returned iterator is O(n) 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) -> Pre<'r, D>

source

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

source

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

source

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

source

pub fn replace_all<M: Matcher<D::Lang>, R: Replacer<D>>( &self, matcher: M, replacer: R ) -> Vec<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<'tree, D: Clone + Doc> Clone for NodeMatch<'tree, D>

source§

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

Returns a copy of the value. Read more
1.0.0 · source§

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

§

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<'tree, D> Freeze for NodeMatch<'tree, D>

§

impl<'tree, D> RefUnwindSafe for NodeMatch<'tree, D>

§

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

§

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

§

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

§

impl<'tree, D> UnwindSafe for NodeMatch<'tree, D>

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> 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<T> ToOwned for T
where T: Clone,

§

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>,

§

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>,

§

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.