Trait ast_grep_core::matcher::Matcher
source · pub trait Matcher<L: Language> {
fn match_node_with_env<'tree>(
&self,
_node: Node<'tree, L>,
_env: &mut MetaVarEnv<'tree, L>
) -> Option<Node<'tree, L>>;
fn potential_kinds(&self) -> Option<BitSet> { ... }
fn get_match_len(&self, _node: Node<'_, L>) -> Option<usize> { ... }
fn match_node<'tree>(
&self,
node: Node<'tree, L>
) -> Option<NodeMatch<'tree, L>> { ... }
fn get_meta_var_matchers(&self) -> MetaVarMatchers<L> { ... }
fn get_meta_var_env<'tree>(&self) -> MetaVarEnv<'tree, L> { ... }
fn find_node<'tree>(
&self,
node: Node<'tree, L>
) -> Option<NodeMatch<'tree, L>> { ... }
}
Expand description
N.B. At least one positive term is required for matching
Required Methods§
sourcefn match_node_with_env<'tree>(
&self,
_node: Node<'tree, L>,
_env: &mut MetaVarEnv<'tree, L>
) -> Option<Node<'tree, L>>
fn match_node_with_env<'tree>(
&self,
_node: Node<'tree, L>,
_env: &mut MetaVarEnv<'tree, L>
) -> Option<Node<'tree, L>>
Returns the node why the input is matched or None if not matched.
The return value is usually input node itself, but it can be different node.
For example Has
matcher can return the child or descendant node.
Provided Methods§
sourcefn potential_kinds(&self) -> Option<BitSet>
fn potential_kinds(&self) -> Option<BitSet>
Returns a bitset for all possible target node kind ids. Returns None if the matcher needs to try against all node kind.
sourcefn get_match_len(&self, _node: Node<'_, L>) -> Option<usize>
fn get_match_len(&self, _node: Node<'_, L>) -> Option<usize>
get_match_len will skip trailing anonymous child node to exclude punctuation.
fn match_node<'tree>(&self, node: Node<'tree, L>) -> Option<NodeMatch<'tree, L>>
fn get_meta_var_matchers(&self) -> MetaVarMatchers<L>
fn get_meta_var_env<'tree>(&self) -> MetaVarEnv<'tree, L>
fn find_node<'tree>(&self, node: Node<'tree, L>) -> Option<NodeMatch<'tree, L>>
Trait Implementations§
source§impl<L: Language> Matcher<L> for Box<dyn Matcher<L>>
impl<L: Language> Matcher<L> for Box<dyn Matcher<L>>
source§fn match_node_with_env<'tree>(
&self,
node: Node<'tree, L>,
env: &mut MetaVarEnv<'tree, L>
) -> Option<Node<'tree, L>>
fn match_node_with_env<'tree>(
&self,
node: Node<'tree, L>,
env: &mut MetaVarEnv<'tree, L>
) -> Option<Node<'tree, L>>
Returns the node why the input is matched or None if not matched.
The return value is usually input node itself, but it can be different node.
For example
Has
matcher can return the child or descendant node.source§fn potential_kinds(&self) -> Option<BitSet>
fn potential_kinds(&self) -> Option<BitSet>
Returns a bitset for all possible target node kind ids.
Returns None if the matcher needs to try against all node kind.