use std::rc::Rc; use builtin::{BinOp, PrefixOp}; #[derive(Debug, PartialEq)] pub struct AST(pub Vec); #[derive(Debug, PartialEq, Clone)] pub enum Statement { ExpressionStatement(Expression), Declaration(Declaration), } pub type Block = Vec; pub type ParamName = Rc; pub type InterfaceName = Rc; //should be a singleton I think?? pub type FormalParam = (ParamName, Option); #[derive(Debug, PartialEq, Clone)] pub enum Declaration { FuncSig(Signature), FuncDecl(Signature, Block), TypeDecl(TypeSingletonName, TypeBody), //should have TypeSingletonName in it TypeAlias(Rc, Rc), //should have TypeSingletonName in it, or maybe just String, not sure Binding { name: Rc, constant: bool, expr: Expression, }, Impl { type_name: TypeName, interface_name: Option, block: Vec, }, Interface { name: Rc, signatures: Vec } } #[derive(Debug, PartialEq, Clone)] pub struct Signature { pub name: Rc, pub params: Vec, pub type_anno: Option, } #[derive(Debug, PartialEq, Clone)] pub struct TypeBody(pub Vec); #[derive(Debug, PartialEq, Clone)] pub enum Variant { UnitStruct(Rc), TupleStruct(Rc, Vec), Record(Rc, Vec<(Rc, TypeName)>), } #[derive(Debug, PartialEq, Clone)] pub struct Expression(pub ExpressionType, pub Option); #[derive(Debug, PartialEq, Clone)] pub enum TypeName { Tuple(Vec), Singleton(TypeSingletonName) } #[derive(Debug, PartialEq, Clone)] pub struct TypeSingletonName { pub name: Rc, pub params: Vec, } #[derive(Debug, PartialEq, Clone)] pub enum ExpressionType { NatLiteral(u64), FloatLiteral(f64), StringLiteral(Rc), BoolLiteral(bool), BinExp(BinOp, Box, Box), PrefixExp(PrefixOp, Box), TupleLiteral(Vec), Value(Rc), NamedStruct { name: Rc, fields: Vec<(Rc, Expression)>, }, Call { f: Box, arguments: Vec, }, Index { indexee: Box, indexers: Vec, }, IfExpression { discriminator: Box, body: Box, }, WhileExpression { condition: Option>, body: Block, }, ForExpression { enumerators: Vec, body: Box, }, Lambda { params: Vec, body: Block, }, ListLiteral(Vec), } #[derive(Debug, PartialEq, Clone)] pub enum Discriminator { Simple(Expression), BinOp(Expression, BinOp) } #[derive(Debug, PartialEq, Clone)] pub enum IfExpressionBody { SimpleConditional(Block, Option), SimplePatternMatch(Pattern, Block, Option), GuardList(Vec) } #[derive(Debug, PartialEq, Clone)] pub struct Guard { pat: Pattern, body: Block, } #[derive(Debug, PartialEq, Clone)] pub struct Pattern { pub free_vars: Vec>, pub var: Variant, } #[derive(Debug, PartialEq, Clone)] pub struct Enumerator { pub id: Rc, pub generator: Expression, } #[derive(Debug, PartialEq, Clone)] pub enum ForBody { MonadicReturn(Expression), StatementBlock(Block), }