Skip to main content

NodePredicate

Trait NodePredicate 

Source
pub trait NodePredicate<Ctx>: Send + Sync {
    // Required method
    fn test(&self, input: Input<'_, Ctx>) -> bool;
}
Expand description

A predicate over an Input — returns true when the node matches.

Any F: Fn(Input<'_, Ctx>) -> bool + Send + Sync implements this trait automatically via the blanket implementation, so plain closures work too.

Use the free-function constructors (kind_is, kind_is_not, …) to obtain named predicate values, or supply any compatible closure directly.

§Example

use tree_sitter_utils::{NodePredicate, kind_is};

fn accepts_pred<Ctx: Copy, P: NodePredicate<Ctx>>(_: P) {}
accepts_pred::<(), _>(kind_is(&["identifier"]));
accepts_pred::<(), _>(|input: tree_sitter_utils::Input<()>| input.node.kind() == "identifier");

Required Methods§

Source

fn test(&self, input: Input<'_, Ctx>) -> bool

Test whether the predicate holds for the given input.

Implementors§

Source§

impl<Ctx> NodePredicate<Ctx> for HasAncestorKind

Source§

impl<Ctx> NodePredicate<Ctx> for HasAncestorKinds

Source§

impl<Ctx> NodePredicate<Ctx> for HasParentKind

Source§

impl<Ctx> NodePredicate<Ctx> for KindIs

Source§

impl<Ctx> NodePredicate<Ctx> for KindIsNot

Source§

impl<Ctx> NodePredicate<Ctx> for NodeDepthLte

Source§

impl<Ctx, F> NodePredicate<Ctx> for F
where F: Fn(Input<'_, Ctx>) -> bool + Send + Sync,

Blanket impl: every Fn(Input<'_, Ctx>) -> bool + Send + Sync is a predicate.