Trait 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> { ... }
}
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.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so 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 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 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 Pattern<L>

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>