Struct ast_grep_core::NodeMatch
source · pub struct NodeMatch<'tree, L: Language>(_, _);
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, L: Language> NodeMatch<'tree, L>
impl<'tree, L: Language> NodeMatch<'tree, L>
pub fn new(node: Node<'tree, L>, env: MetaVarEnv<'tree, L>) -> Self
pub fn get_node(&self) -> &Node<'tree, L>
sourcepub fn get_env(&self) -> &MetaVarEnv<'tree, L>
pub fn get_env(&self) -> &MetaVarEnv<'tree, L>
Returns the populated MetaVarEnv for this match.
pub fn replace_by<R: Replacer<L>>(&self, replacer: R) -> Edit
Methods from Deref<Target = Node<'tree, L>>§
pub fn is_leaf(&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) -> &L
pub fn matches<M: Matcher<L>>(&self, m: M) -> bool
pub fn inside<M: Matcher<L>>(&self, m: M) -> bool
pub fn has<M: Matcher<L>>(&self, m: M) -> bool
pub fn precedes<M: Matcher<L>>(&self, m: M) -> bool
pub fn follows<M: Matcher<L>>(&self, m: M) -> bool
pub fn children<'s>(&'s self) -> impl ExactSizeIterator<Item = Node<'r, L>> + 's
pub fn dfs<'s>(&'s self) -> Pre<'r, L> ⓘ
pub fn find<M: Matcher<L>>(&self, pat: M) -> Option<NodeMatch<'r, L>>
pub fn find_all<M: Matcher<L>>(
&self,
pat: M
) -> impl Iterator<Item = NodeMatch<'r, L>>
pub fn field(&self, name: &str) -> Option<Self>
pub fn field_children(&self, name: &str) -> impl Iterator<Item = Node<'r, L>>
pub fn parent(&self) -> Option<Self>
pub fn child(&self, nth: usize) -> Option<Self>
pub fn ancestors(&self) -> impl Iterator<Item = Node<'r, L>> + '_
pub fn next(&self) -> Option<Self>
pub fn next_all(&self) -> impl Iterator<Item = Node<'r, L>> + '_
pub fn prev(&self) -> Option<Node<'r, L>>
pub fn prev_all(&self) -> impl Iterator<Item = Node<'r, L>> + '_
pub fn replace<M: Matcher<L>, R: Replacer<L>>(
&self,
matcher: M,
replacer: R
) -> Option<Edit>
pub fn replace_all<M: Matcher<L>, R: Replacer<L>>(
&self,
matcher: M,
replacer: R
) -> Vec<Edit> ⓘ
pub fn after(&self) -> Edit
pub fn before(&self) -> Edit
pub fn append(&self) -> Edit
pub fn prepend(&self) -> Edit
Trait Implementations§
source§impl<'tree, L: Language> Borrow<Node<'tree, L>> for NodeMatch<'tree, L>
impl<'tree, L: Language> Borrow<Node<'tree, L>> for NodeMatch<'tree, L>
NodeMatch is an immutable view to Node