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>
impl<'tree, D: Doc> NodeMatch<'tree, D>
pub fn new(node: Node<'tree, D>, env: MetaVarEnv<'tree, D>) -> Self
pub fn get_node(&self) -> &Node<'tree, D>
sourcepub fn get_env(&self) -> &MetaVarEnv<'tree, D>
pub fn get_env(&self) -> &MetaVarEnv<'tree, D>
Returns the populated MetaVarEnv for this match.
pub fn get_env_mut(&mut self) -> &mut MetaVarEnv<'tree, D>
Methods from Deref<Target = Node<'tree, D>>§
pub fn node_id(&self) -> usize
pub fn is_leaf(&self) -> bool
sourcepub fn is_named_leaf(&self) -> bool
pub fn is_named_leaf(&self) -> bool
if has no named children. N.B. it is different from is_named && is_leaf
pub fn is_error(&self) -> bool
pub fn kind(&self) -> Cow<'_, str>
pub fn kind_id(&self) -> u16
pub fn is_named(&self) -> bool
sourcepub fn get_ts_node(&self) -> Node<'r>
pub fn get_ts_node(&self) -> Node<'r>
the underlying tree-sitter Node
sourcepub fn start_pos(&self) -> (usize, usize)
pub fn start_pos(&self) -> (usize, usize)
Nodes’ start position in terms of zero-based rows and columns.
pub fn text(&self) -> Cow<'r, str>
pub fn lang(&self) -> &'r D::Lang
pub fn root(&self) -> &'r Root<StrDoc<L>>
pub fn matches<M: Matcher<D::Lang>>(&self, m: M) -> bool
pub fn inside<M: Matcher<D::Lang>>(&self, m: M) -> bool
pub fn has<M: Matcher<D::Lang>>(&self, m: M) -> bool
pub fn precedes<M: Matcher<D::Lang>>(&self, m: M) -> bool
pub fn follows<M: Matcher<D::Lang>>(&self, m: M) -> bool
pub fn parent(&self) -> Option<Self>
pub fn children<'s>(&'s self) -> impl ExactSizeIterator<Item = Node<'r, D>> + 's
pub fn child(&self, nth: usize) -> Option<Self>
pub fn field(&self, name: &str) -> Option<Self>
pub fn child_by_field_id(&self, field_id: u16) -> Option<Self>
pub fn field_children(&self, name: &str) -> impl Iterator<Item = Node<'r, D>>
sourcepub fn ancestors(&self) -> impl Iterator<Item = Node<'r, D>> + '_
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.
pub fn next(&self) -> Option<Self>
sourcepub fn next_all(&self) -> impl Iterator<Item = Node<'r, D>> + '_
pub fn next_all(&self) -> impl Iterator<Item = Node<'r, D>> + '_
Returns all sibling nodes next to self
.
pub fn prev(&self) -> Option<Node<'r, D>>
pub fn prev_all(&self) -> impl Iterator<Item = Node<'r, D>> + '_
pub fn dfs<'s>(&'s self) -> Pre<'r, D> ⓘ
pub fn find<M: Matcher<D::Lang>>(&self, pat: M) -> Option<NodeMatch<'r, D>>
pub fn find_all<M: Matcher<D::Lang>>( &self, pat: M ) -> impl Iterator<Item = NodeMatch<'r, D>>
pub fn replace<M: Matcher<D::Lang>, R: Replacer<D>>( &self, matcher: M, replacer: R ) -> Option<Edit<<D as Doc>::Source>>
pub fn replace_all<M: Matcher<D::Lang>, R: Replacer<D>>( &self, matcher: M, replacer: R ) -> Vec<Edit<<D as Doc>::Source>>
pub fn after(&self) -> Edit<<D as Doc>::Source>
pub fn before(&self) -> Edit<<D as Doc>::Source>
pub fn append(&self) -> Edit<<D as Doc>::Source>
pub fn prepend(&self) -> Edit<<D as Doc>::Source>
Trait Implementations§
source§impl<'tree, D: Doc> Borrow<Node<'tree, D>> for NodeMatch<'tree, D>
impl<'tree, D: Doc> Borrow<Node<'tree, D>> for NodeMatch<'tree, D>
NodeMatch is an immutable view to Node
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>
impl<'tree, D> Sync for NodeMatch<'tree, D>
impl<'tree, D> Unpin for NodeMatch<'tree, D>
impl<'tree, D> UnwindSafe for NodeMatch<'tree, D>
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more