Skip to main content

AstNode

Struct AstNode 

Source
pub struct AstNode {
    pub type: &'static str,
    pub value: String,
    pub span: Span,
    pub field_name: Option<&'static str>,
    pub children: Vec<AstNode>,
}
Expand description

Information on an AST node.

Fields§

§type: &'static str

The type of node

§value: String

The code associated to a node

§span: Span

The start and end positions of a node in a code

§field_name: Option<&'static str>

Tree-sitter grammar field name through which the parent reaches this node (e.g. left, right, name, body).

None for the root node, anonymous tokens (punctuation, keywords), and any child that does not occupy a named grammar field. Consumers of the JSON output rely on this to distinguish structurally equivalent children without grammar-specific positional knowledge.

§children: Vec<AstNode>

The children of a node

Implementations§

Source§

impl AstNode

Source

pub fn new( type: &'static str, value: String, span: Span, children: Vec<AstNode>, ) -> Self

Builds an AstNode with the supplied type, value, span, and children. The field_name is set to None; use AstNode::with_field_name to record the tree-sitter grammar field through which the parent reaches this node.

Source

pub fn with_field_name( type: &'static str, value: String, span: Span, field_name: Option<&'static str>, children: Vec<AstNode>, ) -> Self

Builds an AstNode carrying the tree-sitter grammar field name (left, right, name, body, …) through which the parent reaches this node.

Trait Implementations§

Source§

impl Debug for AstNode

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Serialize for AstNode

Source§

fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

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> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. 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.