1use crate::{Expr, Op};
2use smartstring::alias::String;
3
4pub type Identifier = Vec<String>;
5pub type Identifiers = Vec<Expr>;
6pub type Block = Vec<Action>;
7
8#[derive(Debug, PartialEq, PartialOrd, Clone)]
9pub enum Action {
10 Comment(String),
12 VarAssign(Expr, Expr),
14 SingleShot(Expr, Op, Expr),
15 If(Vec<IfPart>),
17 FnCall(Expr, Identifiers),
19 FnDef(Expr, Identifier, Block),
20 Return(Option<Expr>),
21 Loop(Block),
23 Break,
24 Continue,
25 For(Identifier, Expr, Block),
26 While(Expr, Block),
27 Import(Expr, Option<Expr>),
29}
30
31#[derive(Debug, PartialEq, PartialOrd, Clone)]
32pub enum IfPart {
33 If(Expr, Block),
34 IfElse(Expr, Block),
35 Else(Block),
36}
37
38impl Action {
39 pub fn to_expr(&self) -> Expr {
40 match self {
41 Action::FnCall(i, a) => Expr::FnCall(Box::new(i.to_owned()), a.to_owned()),
42 _ => unreachable!(),
43 }
44 }
45}