From a6d71821b9dd53717c658b3007c055afa84ddb67 Mon Sep 17 00:00:00 2001 From: greg Date: Sun, 8 Oct 2017 18:47:57 -0700 Subject: [PATCH] More type work I --- src/schala_lang/parsing.rs | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/src/schala_lang/parsing.rs b/src/schala_lang/parsing.rs index 0bcf163..4d34761 100644 --- a/src/schala_lang/parsing.rs +++ b/src/schala_lang/parsing.rs @@ -280,9 +280,10 @@ declaration := type_declaration | func_declaration | binding_declaration | impl_ type_declaration := 'type' type_declaration_body type_declaration_body := 'alias' type_alias | IDENTIFIER '=' type_body -type_alias := IDENTIFIER '=' IDENTIFIER +type_alias := IDENTIFIER '=' type_name type_body := variant_specifier ('|' variant_specifier)* -variant_specifier := '{' member_list '}' + +variant_specifier := IDENTIFIER | IDENTIFIER '{' member_list '}' | IDENTIFIER '(' type_name* ')' member_list := (IDENTIFIER type_anno)* func_declaration := 'fn' IDENTIFIER '(' param_list ')' @@ -401,7 +402,7 @@ pub enum Statement { } type ParamName = Rc; -type TypeName = Rc; +type TypeName = Rc; //TODO change TypeName to TypeAnno everywhere type TraitName = Rc; type FormalParamList = Vec<(ParamName, Option)>; @@ -431,8 +432,8 @@ pub struct TypeBody(pub Vec); #[derive(Debug, PartialEq, Clone)] pub enum Variant { Singleton(Rc), - //ArgumentConstructor, - //Record + ArgumentConstructor(Rc, Vec), + Record(Rc, Vec<(Rc, TypeAnno)>), } #[derive(Debug, PartialEq, Clone)] @@ -604,8 +605,21 @@ impl Parser { }); parse_method!(type_body(&mut self) -> ParseResult { - let variant = Variant::Singleton(self.identifier()?); - Ok(TypeBody(vec!(variant))) + let mut variants = Vec::new(); + variants.push(self.variant_specifier()?); + loop { + if let Pipe = self.peek() { + self.next(); + variants.push(self.variant_specifier()?); + } else { + break; + } + } + Ok(TypeBody(variants)) + }); + + parse_method!(variant_specifier(&mut self) -> ParseResult { + Ok(Variant::Singleton(self.identifier()?)) }); parse_method!(func_declaration(&mut self) -> ParseResult {