Struct ast_grep_core::Node
source · pub struct Node<'r, L: Language> { /* private fields */ }
Expand description
’r represents root lifetime
Implementations§
source§impl<'r, L: Language> Node<'r, L>
impl<'r, L: Language> Node<'r, L>
APIs for Node inspection
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
source§impl<'r, L: Language> Node<'r, L>
impl<'r, L: Language> Node<'r, L>
tree traversal API
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>> + '_
source§impl<'r, L: Language> Node<'r, L>
impl<'r, L: Language> Node<'r, L>
Tree manipulation API
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