pub enum Statement {
VarDeclaration {
name: String,
value: Expression,
is_const: bool,
},
Assignment {
target: AssignmentTarget,
operator: AssignmentOperator,
value: Expression,
},
Expression(Expression),
If {
condition: Expression,
then_branch: Vec<Statement>,
else_branch: Option<Vec<Statement>>,
},
While {
condition: Expression,
body: Vec<Statement>,
},
For {
variable: String,
iterable: Expression,
body: Vec<Statement>,
},
Function {
name: String,
parameters: Vec<Parameter>,
body: Vec<Statement>,
return_type: Option<Type>,
},
Return(Option<Expression>),
Break,
Continue,
Block(Vec<Statement>),
}
Expand description
Top-level statements in OpenScript
Variants§
VarDeclaration
Variable declaration: let x = 5
or const y = "hello"
Fields
§
value: Expression
The initial value of the variable
Assignment
Assignment: x = 10
or x += 5
Fields
§
target: AssignmentTarget
The target of the assignment
§
operator: AssignmentOperator
The assignment operator
§
value: Expression
The value to assign
Expression(Expression)
Expression statement: print("hello")
If
If statement with optional else
Fields
§
condition: Expression
The condition to evaluate
While
While loop
For
For loop: for item in collection
Fields
§
iterable: Expression
The expression to iterate over
Function
Function definition
Fields
Return(Option<Expression>)
Return statement
Break
Break statement
Continue
Continue statement
Block(Vec<Statement>)
Block statement
Implementations§
Source§impl Statement
impl Statement
Sourcepub fn is_control_flow(&self) -> bool
pub fn is_control_flow(&self) -> bool
Check if this statement can affect control flow
Sourcepub fn is_declaration(&self) -> bool
pub fn is_declaration(&self) -> bool
Check if this is a declaration statement
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Statement
impl<'de> Deserialize<'de> for Statement
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
impl StructuralPartialEq for Statement
Auto Trait Implementations§
impl Freeze for Statement
impl RefUnwindSafe for Statement
impl Send for Statement
impl Sync for Statement
impl Unpin for Statement
impl UnwindSafe for Statement
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more