roan_engine

Enum Stmt

Source
pub enum Stmt {
Show 18 variants Expr(Box<Expr>), Use(Use), Block(Block), If(If), Return(Return), Fn(Fn), Let(Let), Throw(Throw), Try(Try), Break(Token), Continue(Token), Loop(Loop), While(While), Struct(Struct), TraitDef(TraitDef), StructImpl(StructImpl), TraitImpl(TraitImpl), Const(Const),
}
Expand description

Represents a statement in the AST.

A statement can be an expression, a declaration, a control flow construct, etc.

Variants§

§

Expr(Box<Expr>)

An expression statement.

§

Use(Use)

A use statement for importing modules or items.

§

Block(Block)

A block of statements enclosed in braces.

§

If(If)

An if statement with optional else if and else blocks.

§

Return(Return)

A return statement to exit a function.

§

Fn(Fn)

A function declaration.

§

Let(Let)

A variable declaration.

§

Throw(Throw)

A throw statement for exception handling.

§

Try(Try)

A try statement for handling errors.

§

Break(Token)

A break statement to exit a loop.

§

Continue(Token)

A continue statement to skip the current iteration of a loop.

§

Loop(Loop)

A loop statement to create an infinite loop.

§

While(While)

A while statement to create a loop with a condition.

§

Struct(Struct)

A struct definition.

§

TraitDef(TraitDef)

A trait definition.

§

StructImpl(StructImpl)

A struct implementation.

§

TraitImpl(TraitImpl)

A trait implementation.

§

Const(Const)

A const statement

Implementations§

Source§

impl Stmt

Source

pub fn into_function(self) -> Fn

Source

pub fn new_loop(loop_token: Token, block: Block) -> Stmt

Creates a new Loop statement.

§Arguments
  • loop_token - The token representing the loop keyword.
  • block - The block of code to execute within the loop.
§Returns

A Stmt::Loop variant containing the provided components.

Source

pub fn new_while(while_token: Token, condition: Expr, block: Block) -> Stmt

Creates a new While statement.

§Arguments
  • while_token - The token representing the while keyword.
  • condition - The expression to evaluate as the loop condition.
  • block - The block of code to execute within the loop.
§Returns

A Stmt::While variant containing the provided components.

Source

pub fn new_break(break_token: Token) -> Stmt

Creates a new Break statement.

§Arguments
  • break_token - The token representing the break keyword.
§Returns

A Stmt::Break variant containing the provided token.

Source

pub fn new_continue(continue_token: Token) -> Stmt

Creates a new Continue statement.

§Arguments
  • continue_token - The token representing the continue keyword.
§Returns

A Stmt::Continue variant containing the provided token.

Source

pub fn new_try( try_token: Token, try_block: Block, error_ident: Token, catch_block: Block, ) -> Stmt

Creates a new Try statement.

§Arguments
  • try_token - The token for the try keyword.
  • try_block - The block of code to execute within the try.
  • error_ident - The identifier token for the caught error.
  • catch_block - The block of code to execute if an error is caught.
§Returns

A Stmt::Try variant containing the provided components.

Source

pub fn new_throw(token: Token, value: Expr) -> Stmt

Creates a new Throw statement.

§Arguments
  • token - The token representing the throw keyword.
  • value - The expression to be thrown.
§Returns

A Stmt::Throw variant containing the provided value and token.

Source

pub fn new_fn( fn_token: Token, name: String, params: Vec<FnParam>, body: Block, public: bool, return_type: Option<FunctionType>, is_static: bool, ) -> Stmt

Creates a new function (Fn) statement.

§Arguments
  • fn_token - The token representing the fn keyword.
  • name - The name of the function.
  • params - A vector of function parameters.
  • body - The block of code representing the function body.
  • public - A boolean indicating if the function is public.
  • return_type - An optional return type annotation.
  • is_static - A boolean indicating if the function is static.
§Returns

A Stmt::Fn variant containing the provided function details.

Source

pub fn new_use(use_token: Token, from: Token, items: Vec<Token>) -> Stmt

Creates a new Use statement.

§Arguments
  • use_token - The token representing the use keyword.
  • from - The token representing the module or path to import from.
  • items - A vector of tokens representing the items to import.
§Returns

A Stmt::Use variant containing the provided import details.

Source

pub fn new_if( if_token: Token, condition: Box<Expr>, then_block: Block, else_ifs: Vec<ElseBlock>, else_block: Option<ElseBlock>, ) -> Stmt

Creates a new If statement.

§Arguments
  • if_token - The token representing the if keyword.
  • condition - The expression to evaluate as the condition.
  • then_block - The block of code to execute if the condition is true.
  • else_ifs - A vector of ElseBlock representing else if clauses.
  • else_block - An optional ElseBlock representing the else clause.
§Returns

A Stmt::If variant containing the provided condition and blocks.

Source

pub fn new_let( ident: Token, initializer: Box<Expr>, type_annotation: Option<TypeAnnotation>, ) -> Stmt

Creates a new Let statement.

§Arguments
  • ident - The token representing the variable identifier.
  • initializer - The expression used to initialize the variable.
  • type_annotation - An optional type annotation for the variable.
§Returns

A Stmt::Let variant containing the provided variable details.

Source

pub fn new_return(return_token: Token, expr: Option<Box<Expr>>) -> Stmt

Creates a new Return statement.

§Arguments
  • return_token - The token representing the return keyword.
  • expr - An optional expression to return.
§Returns

A Stmt::Return variant containing the provided return value.

Source

pub fn new_struct( struct_token: Token, name: Token, fields: Vec<StructField>, public: bool, ) -> Stmt

Creates a new Struct statement.

§Arguments
  • struct_token - The token representing the struct keyword.
  • name - The name of the struct.
§Returns

A Stmt::Struct variant containing the provided struct details.

Source

pub fn new_const(expr: Box<Expr>, ident: Token, public: bool) -> Stmt

Creates a new Const statement.

§Arguments
  • expr - The expression to assign to the constant.
  • ident - The identifier token for the constant.
  • public - A boolean indicating if the constant is public.
§Returns

A Stmt::Const variant containing the provided constant details.

Source

pub fn new_trait_def( trait_token: Token, name: Token, methods: Vec<Fn>, public: bool, ) -> Stmt

Creates a new TraitDef statement.

§Arguments
  • trait_token - The token representing the trait keyword.
  • name - The name of the trait.
  • methods - A vector of function declarations representing the trait methods.
Source

pub fn new_struct_impl( impl_token: Token, struct_name: Token, methods: Vec<Fn>, ) -> Stmt

Creates a new StructImpl statement.

§Arguments
  • impl_token - The token representing the impl keyword.
  • struct_name - The name of the struct being implemented.
  • methods - A vector of function declarations representing the struct methods.
§Returns

A Stmt::StructImpl variant containing the provided struct implementation details.

Source

pub fn new_trait_impl( impl_token: Token, trait_name: Token, for_token: Token, struct_name: Token, methods: Vec<Fn>, ) -> Stmt

Creates a new TraitImpl statement.

§Arguments
  • impl_token - The token representing the impl keyword.
  • trait_name - The name of the trait being implemented.
  • for_token - The token representing the for keyword.
  • struct_name - The name of the struct implementing the trait.
  • methods - A vector of function declarations representing the trait methods.
§Returns

A Stmt::TraitImpl variant containing the provided trait implementation details.

Source§

impl Stmt

Source

pub fn as_function(&self) -> &Fn

Retrieves a reference to the function (Fn) contained within the statement.

§Panics

Panics if the statement is not a Fn variant.

§Returns

A reference to the contained Fn struct.

Trait Implementations§

Source§

impl Clone for Stmt

Source§

fn clone(&self) -> Stmt

Returns a copy 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 Debug for Stmt

Source§

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

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

impl From<Expr> for Stmt

Source§

fn from(expr: Expr) -> Stmt

Converts an Expr into a Stmt::Expr.

§Arguments
  • expr - The expression to convert into a statement.
§Returns

A Stmt::Expr variant containing the provided expression.

Source§

impl PartialEq for Stmt

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for Stmt

Auto Trait Implementations§

§

impl Freeze for Stmt

§

impl RefUnwindSafe for Stmt

§

impl Send for Stmt

§

impl Sync for Stmt

§

impl Unpin for Stmt

§

impl UnwindSafe for Stmt

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, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more