/// Representation of Tokens, function names, the like... pub type Id = String; /// Puck's fundamental types. pub enum Type { Void, Never, Integer, Float, String, // char et al are defined later Func{from: Box, to: Box}, // todo: multiple params, effects Struct(Vec<(Id, Box)>), Tuple(Vec<(Option, Box)>), Union(Vec<(Id, Box)>), Interface { funcs: Vec, for_type: Option>, }, Array{size: usize, kind: Box}, List(Box), Slice(Box), // todo: plus ownership Reference(Box), Mutable(Box), // parameters only Static(Box), // parameters only Alias{ id: Id, params: Vec }, // todo: this is wrong } /// Function signatures. pub struct Sig { effect: Option, id: Id, generics: Vec<(Id, Option)>, params: Vec, result: Option } /// Patterns are recognizable given zero context. /// This is why there is a generic Number term and no Bool term. /// Also can be considered to be a Term/Value. pub enum Pattern { Ident(Id), // type aliases, union variants, calls... Number(i64), Float(f64), Char(char), String(String), Struct(Vec), Tuple(Vec), List(Vec), // arrays, slices, lists } pub struct StructPattern { field: Id, value: Expr } pub struct TuplePattern { field: Option, value: Expr } /// Expressions introduce a new binding or bindings, in some regard. pub enum Binding { Let { id: Pattern, // id: Pattern supports ex. `let (a, b) = ...` kind: Option, value: Box }, Var { id: Pattern, kind: Option, value: Option> // variable bindings can be delayed }, Const { id: Pattern, kind: Option, value: Box }, FuncDecl { public: bool, effect: Option, id: Id, generics: Vec, params: Vec, kind: Type, body: Vec }, TypeDecl { id: Id, generics: Vec, alias: Type }, Import { from: Option, imports: Vec, alias: Option }, Module { id: Id, body: Vec }, } pub struct GenericDecl { id: Id, kind: Option } pub struct ParamDecl { id: Id, kind: Type } /// Expressions related to control flow. pub enum Control { Call { id: Id, params: Vec }, // function calls, macro invocations, field access... Cond { branches: Vec, else_body: Option> }, Try { body: Vec, catches: Vec, finally: Option> }, Match { item: Box, branches: Vec }, Block { id: Option, body: Vec }, Static { body: Vec }, For { binding: Pattern, range: Box, body: Vec }, While { cond: Box, body: Vec }, Loop { body: Vec }, } pub struct CondBranch { cond: Expr, body: Vec } pub struct CatchBranch { exceptions: Vec, binding: Option, body: Vec } pub struct MatchBranch { pattern: Pattern, guard: Option, body: Vec } /// Expressions are either Patterns, Bindings, or Control flow constructs. pub enum Expr { Pattern(Pattern), Binding(Binding), Control(Control), }