Trait ast_grep_core::matcher::Matcher

source ·
pub trait Matcher<L: Language> {
    // Required method
    fn match_node_with_env<'tree, D: Doc<Lang = L>>(
        &self,
        _node: Node<'tree, D>,
        _env: &mut Cow<'_, MetaVarEnv<'tree, D>>
    ) -> Option<Node<'tree, D>>;

    // Provided methods
    fn potential_kinds(&self) -> Option<BitSet> { ... }
    fn get_match_len<D: Doc<Lang = L>>(
        &self,
        _node: Node<'_, D>
    ) -> Option<usize> { ... }
    fn match_node<'tree, D: Doc<Lang = L>>(
        &self,
        node: Node<'tree, D>
    ) -> Option<NodeMatch<'tree, D>> { ... }
    fn find_node<'tree, D: Doc<Lang = L>>(
        &self,
        node: Node<'tree, D>
    ) -> Option<NodeMatch<'tree, D>> { ... }
}
Expand description

Matcher defines whether a tree-sitter node matches certain pattern, and update the matched meta-variable values in MetaVarEnv. N.B. At least one positive term is required for matching

Required Methods§

source

fn match_node_with_env<'tree, D: Doc<Lang = L>>( &self, _node: Node<'tree, D>, _env: &mut Cow<'_, MetaVarEnv<'tree, D>> ) -> Option<Node<'tree, D>>

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§

source

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.

source

fn get_match_len<D: Doc<Lang = L>>(&self, _node: Node<'_, D>) -> Option<usize>

get_match_len will skip trailing anonymous child node to exclude punctuation.

source

fn match_node<'tree, D: Doc<Lang = L>>( &self, node: Node<'tree, D> ) -> Option<NodeMatch<'tree, D>>

source

fn find_node<'tree, D: Doc<Lang = L>>( &self, node: Node<'tree, D> ) -> Option<NodeMatch<'tree, D>>

Object Safety§

This trait is not object safe.

Implementations on Foreign Types§

source§

impl<L, T> Matcher<L> for &T
where L: Language, T: Matcher<L> + ?Sized,

source§

fn match_node_with_env<'tree, D: Doc<Lang = L>>( &self, node: Node<'tree, D>, env: &mut Cow<'_, MetaVarEnv<'tree, D>> ) -> Option<Node<'tree, D>>

source§

fn potential_kinds(&self) -> Option<BitSet>

source§

fn match_node<'tree, D: Doc<Lang = L>>( &self, node: Node<'tree, D> ) -> Option<NodeMatch<'tree, D>>

source§

fn find_node<'tree, D: Doc<Lang = L>>( &self, node: Node<'tree, D> ) -> Option<NodeMatch<'tree, D>>

source§

fn get_match_len<D: Doc<Lang = L>>(&self, node: Node<'_, D>) -> Option<usize>

source§

impl<L: Language> Matcher<L> for str

source§

fn match_node_with_env<'tree, D: Doc<Lang = L>>( &self, node: Node<'tree, D>, env: &mut Cow<'_, MetaVarEnv<'tree, D>> ) -> Option<Node<'tree, D>>

source§

fn get_match_len<D: Doc<Lang = L>>(&self, node: Node<'_, D>) -> Option<usize>

Implementors§

source§

impl<L, M> Matcher<L> for Op<L, M>
where L: Language, M: Matcher<L>,

source§

impl<L, P1, P2> Matcher<L> for Or<L, P1, P2>
where L: Language, P1: Matcher<L>, P2: Matcher<L>,

source§

impl<L, P> Matcher<L> for Not<L, P>
where L: Language, P: Matcher<L>,

source§

impl<L: Language> Matcher<L> for Pattern<L>

source§

impl<L: Language> Matcher<L> for KindMatcher<L>

source§

impl<L: Language> Matcher<L> for MatchAll

source§

impl<L: Language> Matcher<L> for MatchNone

source§

impl<L: Language> Matcher<L> for RegexMatcher<L>

source§

impl<L: Language, M: Matcher<L>> Matcher<L> for Any<L, M>

source§

impl<L: Language, P1, P2> Matcher<L> for And<L, P1, P2>
where P1: Matcher<L>, P2: Matcher<L>,

source§

impl<L: Language, P: Matcher<L>> Matcher<L> for All<L, P>