deskc_ast/
ty.rs

1use crate::{expr::Expr, span::Spanned};
2
3#[derive(Clone, Debug, PartialEq)]
4pub struct Effect {
5    pub input: Spanned<Type>,
6    pub output: Spanned<Type>,
7}
8
9#[derive(Clone, Debug, PartialEq)]
10pub enum Type {
11    Brand {
12        brand: String,
13        item: Box<Spanned<Type>>,
14    },
15    Number,
16    String,
17    Trait(Vec<Spanned<Self>>),
18    Effectful {
19        ty: Box<Spanned<Self>>,
20        effects: Spanned<EffectExpr>,
21    },
22    Infer,
23    This,
24    Alias(String),
25    Product(Vec<Spanned<Self>>),
26    Sum(Vec<Spanned<Self>>),
27    Function {
28        parameters: Vec<Spanned<Self>>,
29        body: Box<Spanned<Self>>,
30    },
31    Array(Box<Spanned<Self>>),
32    Set(Box<Spanned<Self>>),
33    Let {
34        variable: String,
35        body: Box<Spanned<Self>>,
36    },
37    Variable(String),
38    BoundedVariable {
39        bound: Box<Spanned<Self>>,
40        identifier: String,
41    },
42    Attribute {
43        attr: Box<Spanned<Expr>>,
44        ty: Box<Spanned<Self>>,
45    },
46    Comment {
47        position: CommentPosition,
48        text: String,
49        item: Box<Spanned<Self>>,
50    },
51}
52
53#[derive(Clone, Debug, PartialEq)]
54pub enum CommentPosition {
55    Prefix,
56    Suffix,
57}
58
59#[derive(Clone, Debug, PartialEq)]
60pub enum EffectExpr {
61    Effects(Vec<Spanned<Effect>>),
62    Add(Vec<Spanned<EffectExpr>>),
63    Sub {
64        minuend: Box<Spanned<EffectExpr>>,
65        subtrahend: Box<Spanned<EffectExpr>>,
66    },
67    Apply {
68        function: Box<Spanned<Type>>,
69        arguments: Vec<Spanned<Type>>,
70    },
71}