Struct ASTNode

Source
pub struct ASTNode { /* private fields */ }
Expand description

Describes a node in an Abstract Syntax Tree.

We can imagine an AST to look like a tree from a root-down approach:

AST:
       [Root Token]
  [LToken]    [RToken]
[...]       [...]  [...]

Looking at any node in the tree, we see that it consists of its own value and 0-2 children. Thus, we define an ASTNode to be a Token with up to two neighboring ASTNodes.

Implementations§

Source§

impl ASTNode

Source

pub fn from(token: Token, children: Vec<ASTNode>) -> ASTNode

Creates an ASTNode from a Token and a vector of children nodes.

let token = Token::NUMBER(5);
let children : Vec<ASTNode> = vec![];
let node = ASTNode::from(token, children);
Source

pub fn token(&self) -> &Token

Returns the token of an ASTNode.

Source

pub fn children(&self) -> &Vec<ASTNode>

Returns the children of an ASTNode as a Vec.

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, 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.