|
| 1 | +use sml_util::interner::Symbol; |
| 2 | +use sml_util::span::{Span, Spanned}; |
| 3 | + |
| 4 | +#[derive(Copy, Clone, Debug, PartialEq, PartialOrd)] |
| 5 | +pub enum Literal { |
| 6 | + Unit, |
| 7 | + Int(usize), |
| 8 | + Char(char), |
| 9 | + String(Symbol), |
| 10 | +} |
| 11 | + |
| 12 | +#[derive(Clone, Debug, PartialEq, PartialOrd)] |
| 13 | +pub enum DeclKind { |
| 14 | + Datatype(Symbol, Vec<Symbol>, Spanned<Vec<Variant>>), |
| 15 | + Type(Symbol, Vec<Symbol>, Type), |
| 16 | + Function(Symbol, Function), |
| 17 | + Value(Pat, Expr), |
| 18 | + Infix(u8, Symbol), |
| 19 | + Infixr(u8, Symbol), |
| 20 | +} |
| 21 | + |
| 22 | +#[derive(Clone, Debug, PartialEq, PartialOrd)] |
| 23 | +pub enum TypeKind { |
| 24 | + /// Type variable |
| 25 | + Var(Symbol), |
| 26 | + /// Constructor, with applied arguments |
| 27 | + Con(Symbol, Vec<Type>), |
| 28 | + /// Tuple type |
| 29 | + Product(Vec<Type>), |
| 30 | + /// Record type |
| 31 | + Record(Vec<Row>), |
| 32 | + /// Universally quantified type |
| 33 | + Univ(Symbol, Box<Type>), |
| 34 | +} |
| 35 | + |
| 36 | +#[derive(Clone, Debug, PartialEq, PartialOrd)] |
| 37 | +pub enum ExprKind { |
| 38 | + Lit(Literal), |
| 39 | + Var(Symbol), |
| 40 | + Abs(Box<Pat>, Box<Expr>), |
| 41 | + App(Box<Expr>, Box<Expr>), |
| 42 | + FlatApp(Vec<Expr>), |
| 43 | + Ann(Box<Expr>, Box<Type>), |
| 44 | + Record(Vec<Field>), |
| 45 | + Tuple(Vec<Expr>), |
| 46 | + Projection(Box<Expr>, Box<Expr>), |
| 47 | + Case(Box<Expr>, Vec<Arm>), |
| 48 | + Let(Vec<Decl>, Box<Expr>), |
| 49 | +} |
| 50 | + |
| 51 | +#[derive(Clone, Debug, PartialEq, PartialOrd)] |
| 52 | +pub enum PatKind { |
| 53 | + /// Wildcard |
| 54 | + Any, |
| 55 | + /// Literal |
| 56 | + Lit(Literal), |
| 57 | + /// Type ascription |
| 58 | + Ascribe(Box<Pat>, Box<Type>), |
| 59 | + /// Variable binding |
| 60 | + Variable(Symbol), |
| 61 | + /// Tuple of pattern bindings (_, x) |
| 62 | + Product(Vec<Pat>), |
| 63 | + /// Record pattern { label1, label2 } |
| 64 | + Record(Vec<Pat>), |
| 65 | + /// A collection of pat applications, possibly including infix constructors |
| 66 | + FlatApp(Vec<Pat>), |
| 67 | + /// Algebraic datatype constructor, along with binding pattern |
| 68 | + App(Box<Pat>, Box<Pat>), |
| 69 | +} |
| 70 | + |
| 71 | +#[derive(Clone, Debug, PartialEq, PartialOrd)] |
| 72 | +pub struct Function { |
| 73 | + pub ty: Option<Type>, |
| 74 | + pub body: Vec<FnBinding>, |
| 75 | + pub span: Span, |
| 76 | +} |
| 77 | + |
| 78 | +#[derive(Clone, Debug, PartialEq, PartialOrd)] |
| 79 | +pub struct FnBinding { |
| 80 | + pub pats: Vec<Pat>, |
| 81 | + pub expr: Expr, |
| 82 | +} |
| 83 | + |
| 84 | +/// Arm of a case expression |
| 85 | +#[derive(Clone, Debug, PartialEq, PartialOrd)] |
| 86 | +pub struct Arm { |
| 87 | + pub pat: Pat, |
| 88 | + pub expr: Expr, |
| 89 | + pub span: Span, |
| 90 | +} |
| 91 | + |
| 92 | +#[derive(Clone, Debug, PartialEq, PartialOrd)] |
| 93 | +pub struct Field { |
| 94 | + pub label: Symbol, |
| 95 | + pub expr: Expr, |
| 96 | + pub span: Span, |
| 97 | +} |
| 98 | + |
| 99 | +#[derive(Clone, Debug, PartialEq, PartialOrd)] |
| 100 | +pub struct Variant { |
| 101 | + pub label: Symbol, |
| 102 | + pub ty: Vec<Type>, |
| 103 | + pub span: Span, |
| 104 | +} |
| 105 | + |
| 106 | +#[derive(Clone, Debug, PartialEq, PartialOrd)] |
| 107 | +pub struct Row { |
| 108 | + pub label: Symbol, |
| 109 | + pub ty: Type, |
| 110 | + pub span: Span, |
| 111 | +} |
| 112 | + |
| 113 | +pub type Decl = Spanned<DeclKind>; |
| 114 | +pub type Type = Spanned<TypeKind>; |
| 115 | +pub type Expr = Spanned<ExprKind>; |
| 116 | +pub type Pat = Spanned<PatKind>; |
0 commit comments