use std::collections::HashMap;
#[derive(Debug, Clone, PartialEq)]
pub enum Statement {
VariableDeclaration {
var_type: VarType,
name: String,
value: Expression,
},
FunctionDeclaration {
return_type: VarType,
name: String,
params: Vec<Parameter>,
body: Vec<Statement>,
},
StructDeclaration {
name: String,
fields: Vec<Parameter>,
},
#[allow(dead_code)]
Expression(Expression),
Return(Expression),
#[allow(dead_code)]
Assignment {
name: String,
value: Expression,
op: AssingmentOp,
},
Conditional {
conditional_type: ConditionalType,
body: Vec<Statement>,
},
Loop {
loop_over: Expression,
index_var: String,
body: Vec<Statement>,
},
}
#[derive(Debug, Clone, PartialEq)]
pub enum ConditionalType {
If(Expression),
Elif(Expression),
Else,
}
#[derive(Debug, Clone, PartialEq)]
pub enum AssingmentOp {
Equals,
PlusEquals,
MinusEquals,
TimesEquals,
DivideEquals,
}
#[derive(Debug, Clone, PartialEq)]
pub enum BinaryOp {
Add,
Subtract,
Multiply,
Divide,
LessThan,
LessThanOrEqual,
GreaterThan,
GreaterThanOrEqual,
Equals,
Index,
}
#[derive(Debug, Clone, PartialEq)]
pub enum UnaryOp {
#[allow(dead_code)]
Reference,
#[allow(dead_code)]
Dereference,
#[allow(dead_code)]
Negative,
#[allow(dead_code)]
Not,
}
#[derive(Debug, Clone, PartialEq)]
pub enum Expression {
Identifier(String),
Literal(Literal),
CompositeLiteral(CompositeLiteral),
BinaryOperation {
left: Box<Expression>,
op: BinaryOp,
right: Box<Expression>,
},
#[allow(dead_code)]
UnaryOperation { op: UnaryOp, expr: Box<Expression> },
FunctionCall { name: String, args: Vec<Expression> },
#[allow(dead_code)]
MemberAccess {
object: Box<Expression>,
field: String,
},
Conversion { to: VarType, expr: Box<Expression> },
}
#[derive(Debug, Clone, PartialEq)]
pub enum Literal {
Int(i32),
Float(f32),
String(String),
Bool(bool),
}
#[derive(Debug, Clone, PartialEq)]
pub enum CompositeLiteral {
Vec(Vec<Expression>),
Set(Vec<Expression>),
Map(Vec<(Expression, Expression)>),
Empty,
Struct(HashMap<String, Expression>),
}
#[derive(Debug, Clone, PartialEq)]
pub enum VarType {
Void,
Int,
Str,
Float,
Bool,
Vec(Box<VarType>),
Map(Box<VarType>, Box<VarType>),
Set(Box<VarType>),
#[allow(dead_code)]
Reference(Box<VarType>),
Struct(String),
}
#[derive(Debug, Clone, PartialEq)]
pub struct Parameter {
pub name: String,
pub param_type: VarType,
}