psi_lang/
enums.rs

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    // Comments
11    Comment(String),
12    // Asignment
13    VarAssign(Expr, Expr),
14    SingleShot(Expr, Op, Expr),
15    // Selection
16    If(Vec<IfPart>),
17    // Functions
18    FnCall(Expr, Identifiers),
19    FnDef(Expr, Identifier, Block),
20    Return(Option<Expr>),
21    // Iteration
22    Loop(Block),
23    Break,
24    Continue,
25    For(Identifier, Expr, Block),
26    While(Expr, Block),
27    // Importing
28    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}