Skip to main content

NodeUtil

Trait NodeUtil 

Source
pub trait NodeUtil<'tree> {
    // Required methods
    fn text_of(&self, source: &str) -> String;
    fn line_span(&self) -> LineSpan;
    fn field_text(&self, field: &str, source: &str) -> Option<String>;
    fn child_of_kind(&self, kind: &str) -> Option<Node<'tree>>;
    fn children_of_kind(&self, kind: &str) -> Vec<Node<'tree>>;
    fn descendants_of_kinds(
        &self,
        kinds: &[&str],
        enter_matches: bool,
    ) -> Vec<Node<'tree>>;
    fn first_identifier(&self, source: &str) -> Option<String>;
    fn signature_head(&self, body_kinds: &[&str], source: &str) -> String;
}
Expand description

Convenience methods every extractor needs on tree-sitter nodes.

Required Methods§

Source

fn text_of(&self, source: &str) -> String

Source

fn line_span(&self) -> LineSpan

Source

fn field_text(&self, field: &str, source: &str) -> Option<String>

Source

fn child_of_kind(&self, kind: &str) -> Option<Node<'tree>>

Source

fn children_of_kind(&self, kind: &str) -> Vec<Node<'tree>>

Source

fn descendants_of_kinds( &self, kinds: &[&str], enter_matches: bool, ) -> Vec<Node<'tree>>

Every descendant (including self) whose kind is in kinds, in document order. Does not descend into matched nodes when enter_matches is false.

Source

fn first_identifier(&self, source: &str) -> Option<String>

The first identifier-like descendant’s text.

Source

fn signature_head(&self, body_kinds: &[&str], source: &str) -> String

The declaration’s text cut at the start of its body child — the signature head as written, whitespace-normalized.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl<'tree> NodeUtil<'tree> for Node<'tree>

Source§

fn text_of(&self, source: &str) -> String

Source§

fn line_span(&self) -> LineSpan

Source§

fn field_text(&self, field: &str, source: &str) -> Option<String>

Source§

fn child_of_kind(&self, kind: &str) -> Option<Node<'tree>>

Source§

fn children_of_kind(&self, kind: &str) -> Vec<Node<'tree>>

Source§

fn descendants_of_kinds( &self, kinds: &[&str], enter_matches: bool, ) -> Vec<Node<'tree>>

Source§

fn first_identifier(&self, source: &str) -> Option<String>

Source§

fn signature_head(&self, body_kinds: &[&str], source: &str) -> String

Implementors§