Skip to main content

Token

Enum Token 

Source
pub enum Token {
Show 27 variants Function { name: String, params: Vec<String>, body: Box<Block>, }, VariableDeclaration { name: String, value: Option<Box<Expression>>, }, StringLiteral(String), NumberLiteral(f64), BooleanLiteral(bool), Null, Undefined, Identifier(String), BinaryOperation { left: Box<Expression>, operator: String, right: Box<Expression>, }, UnaryOperation { operator: String, operand: Box<Expression>, }, FunctionCall { callee: Box<Expression>, arguments: Vec<Expression>, }, MemberAccess { object: Box<Expression>, property: Box<Expression>, computed: bool, }, IfStatement { condition: Box<Expression>, consequent: Box<Block>, alternate: Option<Box<Block>>, }, WhileLoop { condition: Box<Expression>, body: Box<Block>, }, ForLoop { init: Option<Box<Token>>, condition: Option<Box<Expression>>, update: Option<Box<Expression>>, body: Box<Block>, }, ReturnStatement(Option<Box<Expression>>), BreakStatement, ContinueStatement, ExpressionStatement(Box<Expression>), Block(Block), Assignment { target: Box<Expression>, value: Box<Expression>, }, ArrayLiteral(Vec<Expression>), ObjectLiteral(Vec<(String, Expression)>), Conditional { condition: Box<Expression>, consequent: Box<Expression>, alternate: Box<Expression>, }, TryCatch { body: Box<Block>, handler: Option<CatchClause>, finalizer: Option<Box<Block>>, }, ThrowStatement(Box<Expression>), Unknown(Vec<u8>),
}
Expand description

Represents an opcode/token in the binary

Variants§

§

Function

Function declaration

Fields

§name: String
§params: Vec<String>
§body: Box<Block>
§

VariableDeclaration

Variable declaration with optional initializer

Fields

§name: String
§

StringLiteral(String)

String literal

§

NumberLiteral(f64)

Numeric literal

§

BooleanLiteral(bool)

Boolean literal

§

Null

Null value

§

Undefined

Undefined value

§

Identifier(String)

Identifier reference

§

BinaryOperation

Binary operation (e.g., +, -, *, /)

Fields

§operator: String
§

UnaryOperation

Unary operation (e.g., !, -, +)

Fields

§operator: String
§operand: Box<Expression>
§

FunctionCall

Function call

Fields

§callee: Box<Expression>
§arguments: Vec<Expression>
§

MemberAccess

Member access (obj.prop or obj[“prop”])

Fields

§object: Box<Expression>
§property: Box<Expression>
§computed: bool
§

IfStatement

If statement

Fields

§condition: Box<Expression>
§consequent: Box<Block>
§alternate: Option<Box<Block>>
§

WhileLoop

While loop

Fields

§condition: Box<Expression>
§body: Box<Block>
§

ForLoop

For loop

Fields

§condition: Option<Box<Expression>>
§body: Box<Block>
§

ReturnStatement(Option<Box<Expression>>)

Return statement

§

BreakStatement

Break statement

§

ContinueStatement

Continue statement

§

ExpressionStatement(Box<Expression>)

Expression statement

§

Block(Block)

Block of statements

§

Assignment

Assignment (var = value)

Fields

§target: Box<Expression>
§

ArrayLiteral(Vec<Expression>)

Array literal

§

ObjectLiteral(Vec<(String, Expression)>)

Object literal

§

Conditional

Ternary conditional (condition ? consequent : alternate)

Fields

§condition: Box<Expression>
§consequent: Box<Expression>
§alternate: Box<Expression>
§

TryCatch

Try-catch block

Fields

§body: Box<Block>
§finalizer: Option<Box<Block>>
§

ThrowStatement(Box<Expression>)

Throw statement

§

Unknown(Vec<u8>)

Unknown/unhandled token (with raw bytes for debugging)

Trait Implementations§

Source§

impl Clone for Token

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Token

Source§

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

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

impl<'de> Deserialize<'de> for Token

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl From<Token> for Expression

Source§

fn from(token: Token) -> Self

Converts to this type from the input type.
Source§

impl PartialEq for Token

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl Serialize for Token

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
Source§

impl StructuralPartialEq for Token

Auto Trait Implementations§

§

impl Freeze for Token

§

impl RefUnwindSafe for Token

§

impl Send for Token

§

impl Sync for Token

§

impl Unpin for Token

§

impl UnsafeUnpin for Token

§

impl UnwindSafe for Token

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> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

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 = !

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

fn try_from(value: U) -> Result<T, !>

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.