use sindra::{Identifier, Node};
use ast::Annotation;
#[derive(Debug, Clone, PartialEq)]
pub struct Program(pub Node<Block>);
annotate!(Program, Annotation);
#[derive(Debug, Clone, PartialEq)]
pub struct Block(pub Vec<Node<Statement>>);
annotate!(Block, Annotation);
#[derive(Debug, Clone, PartialEq)]
pub enum Statement {
Expression(Node<Expression>),
Declare(Node<Identifier>, Node<Expression>),
Assign(Node<Identifier>, Node<Expression>),
FnDefine(FunctionDef),
Return(Node<Expression>),
Break(Node<Expression>),
Print(Vec<Node<Expression>>),
}
annotate!(Statement, Annotation);
#[derive(Debug, Clone, PartialEq)]
pub struct FunctionDef {
pub name: Node<Identifier>,
pub ret_type: Node<Identifier>,
pub params: Vec<Node<Parameter>>,
pub body: Node<Block>,
}
#[derive(Debug, Clone, PartialEq)]
pub struct Parameter {
pub name: Node<Identifier>,
pub ty: Node<Identifier>,
}
annotate!(Parameter, Annotation);
#[derive(Debug, Clone, PartialEq)]
pub enum Expression {
Literal(Node<Literal>),
Identifier(Node<Identifier>),
Infix {
op: InfixOp,
left: Box<Node<Expression>>,
right: Box<Node<Expression>>,
},
Prefix {
op: PrefixOp,
right: Box<Node<Expression>>,
},
Postfix {
op: PostfixOp,
left: Box<Node<Expression>>,
},
Block(Node<Block>),
FnCall {
name: Node<Identifier>,
args: Vec<Node<Expression>>
},
IfElse {
cond: Box<Node<Expression>>,
if_block: Node<Block>,
else_block: Option<Node<Block>>
},
Loop {
variant: Option<Node<Identifier>>,
set: Node<Set>,
body: Node<Block>,
}
}
annotate!(Expression, Annotation);
#[derive(Debug, Clone, PartialEq)]
pub enum Set {
Interval {
start: Box<Node<Expression>>,
end: Box<Node<Expression>>,
end_inclusive: bool,
step: Box<Node<Expression>>
},
}
annotate!(Set, Annotation);
#[derive(Debug, Clone, PartialEq)]
pub enum Literal {
String(String),
Float(f64),
Int(i64),
Boolean(bool),
}
annotate!(Literal);
#[derive(Debug, Copy, Clone, PartialEq)]
pub enum PrefixOp {
UnaryMinus,
UnaryPlus,
}
#[derive(Debug, Copy, Clone, PartialEq)]
pub enum InfixOp {
Add,
Subtract,
Multiply,
Divide,
Power,
Comparison(CompareOp),
}
#[derive(Debug, Copy, Clone, PartialEq)]
pub enum PostfixOp {
Conjugate,
Imaginary,
}
#[derive(Debug, Copy, Clone, PartialEq)]
pub enum CompareOp {
LessThan,
LessThanEqual,
GreaterThan,
GreaterThanEqual,
Equal,
NotEqual
}