Skip to main content

Crate tree_sitter_utils

Crate tree_sitter_utils 

Source
Expand description

§tree-sitter-utils

A composable, parser-combinator-style abstraction over tree-sitter node dispatch. Instead of writing ad-hoc match node.kind() { ... } loops, you build a chain of typed, zero-cost Handler combinators that express “how to map a syntax-tree node (plus arbitrary context) to an output value”.

The crate is fully language-agnostic. All grammar knowledge lives in the consumer crate.

§Quick example

use tree_sitter_utils::{Input, handler_fn, HandlerExt};

// A minimal handler that labels identifier nodes.
let h = handler_fn(|input: Input<()>| format!("node:{}", input.node.kind()))
    .for_kinds(&["identifier", "type_identifier"])
    .map(|s| s.to_uppercase());

Re-exports§

pub use input::Input;
pub use handler::Handler;
pub use handler::HandlerResult;
pub use predicates::NodePredicate;
pub use predicates::kind_is;
pub use predicates::kind_is_not;
pub use predicates::has_parent_kind;
pub use predicates::node_depth_lte;
pub use predicates::has_ancestor_kind;
pub use predicates::HasAncestorKind;
pub use predicates::has_ancestor_kinds;
pub use predicates::HasAncestorKinds;
pub use combinators::HandlerExt;
pub use combinators::boxed::BoxedHandler;
pub use combinators::find_ancestor::FindAncestor;
pub use combinators::for_children::ForChildren;
pub use combinators::for_children::ScanChildren;
pub use constructors::handler_fn;
pub use constructors::dispatch_on_kind;
pub use constructors::never;
pub use constructors::always;
pub use constructors::first_of;

Modules§

combinators
Combinator extension trait and sub-modules.
constructors
Free-function handler constructors.
handler
The Handler trait and blanket implementations.
input
The Input type — a cheap, copyable snapshot passed to every handler.
predicates
NodePredicate trait and built-in predicate constructors.
query
Query execution helpers.
traversal
Pure node-returning traversal utilities.