pub enum Stmt {
}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
impl Stmt
pub fn into_function(self) -> Fn
Sourcepub fn new_continue(continue_token: Token) -> Stmt
pub fn new_continue(continue_token: Token) -> Stmt
Sourcepub fn new_try(
try_token: Token,
try_block: Block,
error_ident: Token,
catch_block: Block,
) -> Stmt
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 thetrykeyword.try_block- The block of code to execute within thetry.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.
Sourcepub fn new_fn(
fn_token: Token,
name: String,
params: Vec<FnParam>,
body: Block,
public: bool,
return_type: Option<FunctionType>,
is_static: bool,
) -> Stmt
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 thefnkeyword.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.
Sourcepub fn new_if(
if_token: Token,
condition: Box<Expr>,
then_block: Block,
else_ifs: Vec<ElseBlock>,
else_block: Option<ElseBlock>,
) -> Stmt
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 theifkeyword.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 ofElseBlockrepresentingelse ifclauses.else_block- An optionalElseBlockrepresenting theelseclause.
§Returns
A Stmt::If variant containing the provided condition and blocks.
Sourcepub fn new_let(
ident: Token,
initializer: Box<Expr>,
type_annotation: Option<TypeAnnotation>,
) -> Stmt
pub fn new_let( ident: Token, initializer: Box<Expr>, type_annotation: Option<TypeAnnotation>, ) -> Stmt
Sourcepub fn new_struct(
struct_token: Token,
name: Token,
fields: Vec<StructField>,
public: bool,
) -> Stmt
pub fn new_struct( struct_token: Token, name: Token, fields: Vec<StructField>, public: bool, ) -> Stmt
Sourcepub fn new_trait_def(
trait_token: Token,
name: Token,
methods: Vec<Fn>,
public: bool,
) -> Stmt
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 thetraitkeyword.name- The name of the trait.methods- A vector of function declarations representing the trait methods.
Sourcepub fn new_struct_impl(
impl_token: Token,
struct_name: Token,
methods: Vec<Fn>,
) -> Stmt
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 theimplkeyword.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.
Sourcepub fn new_trait_impl(
impl_token: Token,
trait_name: Token,
for_token: Token,
struct_name: Token,
methods: Vec<Fn>,
) -> Stmt
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 theimplkeyword.trait_name- The name of the trait being implemented.for_token- The token representing theforkeyword.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.