Cursor

Struct Cursor 

Source
pub struct Cursor<'a, L: Language> { /* private fields */ }
Expand description

A cursor for traversing a GreenTree.

It maintains a path from the root to the current node, allowing for parent() navigation and offset tracking.

Implementations§

Source§

impl<'a, L: Language> Cursor<'a, L>

Source

pub fn new(root: &'a GreenNode<'a, L>) -> Self

Creates a new cursor starting at the given root node.

Source

pub fn current(&self) -> GreenTree<'a, L>

Returns the current element.

Source

pub fn as_node(&self) -> Option<&'a GreenNode<'a, L>>

Returns the current element as a node, if it is one.

Source

pub fn offset(&self) -> usize

Returns the absolute start offset of the current element.

Source

pub fn len(&self) -> usize

Returns the text length of the current element.

Source

pub fn end_offset(&self) -> usize

Returns the absolute end offset of the current element.

Source

pub fn step_into(&mut self) -> bool

Tries to move to the first child of the current node. Returns true if successful (current was a node with children).

Source

pub fn step_over(&mut self) -> bool

Tries to move to the next sibling. Returns true if successful.

Source

pub fn step_out(&mut self) -> bool

Tries to move to the parent node. Returns true if successful (not at root).

Source

pub fn step(&mut self) -> bool

Pre-order traversal step: try into, then over, then out + over. Returns true if moved to a new node, false if finished traversal.

Source

pub fn step_next(&mut self) -> bool

Skips the current subtree (like step_over), but if that fails, goes up and over. Effectively “next node in post-order” or “next node not in this subtree”.

Trait Implementations§

Source§

impl<'a, L: Clone + Language> Clone for Cursor<'a, L>

Source§

fn clone(&self) -> Cursor<'a, L>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'a, L: Debug + Language> Debug for Cursor<'a, L>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a, L> Freeze for Cursor<'a, L>
where <L as Language>::TokenType: Freeze,

§

impl<'a, L> RefUnwindSafe for Cursor<'a, L>

§

impl<'a, L> Send for Cursor<'a, L>

§

impl<'a, L> Sync for Cursor<'a, L>

§

impl<'a, L> Unpin for Cursor<'a, L>
where <L as Language>::TokenType: Unpin,

§

impl<'a, L> UnwindSafe for Cursor<'a, L>

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.