diff --git a/src/schala_lang/parsing.rs b/src/schala_lang/parsing.rs index 7185bec..f3ade32 100644 --- a/src/schala_lang/parsing.rs +++ b/src/schala_lang/parsing.rs @@ -396,15 +396,15 @@ pub enum Statement { } type ParamName = Rc; -type TraitName = Rc; +type TraitName = Rc; //should be a singleton I think?? type FormalParam = (ParamName, Option); #[derive(Debug, PartialEq, Clone)] pub enum Declaration { FuncSig(Signature), FuncDecl(Signature, Vec), - TypeDecl(Rc, TypeBody), - TypeAlias(Rc, Rc), + TypeDecl(Rc, 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, @@ -440,10 +440,13 @@ pub struct Expression(pub ExpressionType, pub Option); #[derive(Debug, PartialEq, Clone)] pub enum TypeName { Tuple(Vec), - Singleton { - name: Rc, - params: Vec, - } + Singleton(TypeSingletonName) +} + +#[derive(Debug, PartialEq, Clone)] +pub struct TypeSingletonName { + pub name: Rc, + pub params: Vec, } #[derive(Debug, PartialEq, Clone)] @@ -710,7 +713,7 @@ impl Parser { let result = match (first, second) { (first, Some(second)) => { match first { - TypeName::Singleton { ref name, ref params } if params.len() == 0 => + TypeName::Singleton(TypeSingletonName { ref name, ref params }) if params.len() == 0 => Declaration::Impl { type_name: second, trait_name: Some(name.clone()), block }, _ => return ParseError::new(&format!("Invalid name for a trait")), } @@ -746,13 +749,13 @@ impl Parser { use self::TypeName::*; Ok(match self.peek() { LParen => Tuple(delimited!(self, LParen, '(', type_name, Comma, RParen, ')')), - _ => Singleton { + _ => Singleton(TypeSingletonName { name: self.identifier()?, params: match self.peek() { LAngleBracket => delimited!(self, LAngleBracket, '<', type_name, Comma, RAngleBracket, '>'), _ => vec![], } - } + }) }) }); diff --git a/src/schala_lang/type_check.rs b/src/schala_lang/type_check.rs index d62c78f..12838fc 100644 --- a/src/schala_lang/type_check.rs +++ b/src/schala_lang/type_check.rs @@ -2,7 +2,7 @@ use std::collections::HashMap; use std::rc::Rc; -use schala_lang::parsing::{AST, Statement, Declaration, Signature, Expression, ExpressionType, Operation, Variant, TypeName}; +use schala_lang::parsing::{AST, Statement, Declaration, Signature, Expression, ExpressionType, Operation, Variant, TypeName, TypeSingletonName}; // from Niko's talk /* fn type_check(expression, expected_ty) -> Ty { @@ -234,7 +234,7 @@ impl TypeContext { use self::TypeConst::*; match anno { - &TypeName::Singleton { ref name, .. } => { + &TypeName::Singleton(TypeSingletonName { ref name, .. }) => { match name.as_ref().as_ref() { "Int" => TConst(Integer), "Float" => TConst(Float),