From ef4620e90a7068703cafd011d302ff5af0c46b1c Mon Sep 17 00:00:00 2001 From: greg Date: Mon, 12 Feb 2018 00:25:48 -0800 Subject: [PATCH] TypeSingletonName broken out --- src/schala_lang/parsing.rs | 23 +++++++++++++---------- src/schala_lang/type_check.rs | 4 ++-- 2 files changed, 15 insertions(+), 12 deletions(-) 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),