ast_grep_core::traversal

Trait Traversal

Source
pub trait Traversal<'t, D: Doc + 't>: Iterator<Item = Node<'t, D>> {
    // Required methods
    fn calibrate_for_match(&mut self, depth: Option<usize>);
    fn get_current_depth(&self) -> usize;
}
Expand description

Traversal can iterate over node by using traversal algorithm. The next method should only handle normal, reentrant iteration. If reentrancy is not desired, traversal should mutate cursor in calibrate_for_match. Visit will maintain the matched node depth so traversal does not need to use extra field.

Required Methods§

Source

fn calibrate_for_match(&mut self, depth: Option<usize>)

Calibrate cursor position to skip overlapping matches. node depth will be passed if matched, otherwise None.

Source

fn get_current_depth(&self) -> usize

Returns the current depth of cursor depth. Cursor depth is incremented by 1 when moving from parent to child. Cursor depth at Root node is 0.

Implementors§

Source§

impl<'t, D: Doc> Traversal<'t, D> for Post<'t, D>

Source§

impl<'t, D: Doc> Traversal<'t, D> for Pre<'t, D>