Skip to main content

Visitor

Struct Visitor 

Source
pub struct Visitor<M, A = PreOrder> { /* private fields */ }
Expand description

Configurable tree visitor that combines traversal algorithms with pattern matching.

Visitor allows you to traverse an AST while filtering nodes based on patterns. It supports different traversal algorithms and provides fine-grained control over matching behavior through reentrancy and node type filtering.

§Type Parameters

  • M: Matcher - The pattern matcher to filter nodes
  • A - The traversal algorithm (defaults to PreOrder)

§Example

let ast = Tsx.ast_grep("let x = foo(); let y = bar();");
let root = ast.root();

// Find all identifiers, visiting only named nodes
let identifiers: Vec<_> = Visitor::new("$ID")
    .named_only(true)
    .reentrant(false)
    .visit(root)
    .collect();

Implementations§

Source§

impl<M> Visitor<M>

Source

pub const fn new(matcher: M) -> Self

Source§

impl<M, A> Visitor<M, A>

Source

pub fn algorithm<Algo>(self) -> Visitor<M, Algo>

Source

pub fn reentrant(self, reentrant: bool) -> Self

Source

pub fn named_only(self, named_only: bool) -> Self

Source§

impl<M, A> Visitor<M, A>
where A: Algorithm,

Source

pub fn visit<L: LanguageExt>( self, node: Node<'_, StrDoc<L>>, ) -> Visit<'_, StrDoc<L>, A::Traversal<'_, L>, M>
where M: Matcher,

Auto Trait Implementations§

§

impl<M, A> Freeze for Visitor<M, A>
where M: Freeze,

§

impl<M, A> RefUnwindSafe for Visitor<M, A>

§

impl<M, A> Send for Visitor<M, A>
where M: Send, A: Send,

§

impl<M, A> Sync for Visitor<M, A>
where M: Sync, A: Sync,

§

impl<M, A> Unpin for Visitor<M, A>
where M: Unpin, A: Unpin,

§

impl<M, A> UnsafeUnpin for Visitor<M, A>
where M: UnsafeUnpin,

§

impl<M, A> UnwindSafe for Visitor<M, A>
where M: UnwindSafe, A: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.