From d60cf99ab53a35cc58403ca133135c941361d8c6 Mon Sep 17 00:00:00 2001 From: greg Date: Fri, 29 Sep 2017 14:10:49 -0700 Subject: [PATCH] Parsing sorta works Need to handle double >> bug --- src/schala_lang/parsing.rs | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/src/schala_lang/parsing.rs b/src/schala_lang/parsing.rs index dd3d389..bea72b3 100644 --- a/src/schala_lang/parsing.rs +++ b/src/schala_lang/parsing.rs @@ -502,10 +502,22 @@ macro_rules! parse_method { } macro_rules! delimited { - ($self:expr, $parse_fn:expr, $delim:pat, $end:pat) => { + ($self:expr, $start:pat, $parse_fn:ident, $delim:pat, $end:pat) => { { - let mut acc = vec![]; - acc + expect!($self, $start, "Expected "); + let mut acc = vec![]; + loop { + if let $end = $self.peek() { + break; + } + acc.push($self.$parse_fn()?); + match $self.peek() { + $delim => { $self.next(); continue }, + _ => break + }; + } + expect!($self, $end, "Expected "); + acc } } } @@ -603,6 +615,10 @@ impl Parser { parse_method!(type_anno(&mut self) -> ParseResult { expect!(self, Colon, "Expected ':'"); + self.type_name() + }); + + parse_method!(type_name(&mut self) -> ParseResult { Ok(match self.peek() { LParen => { unimplemented!("Not done with tuple types yet") @@ -610,7 +626,7 @@ impl Parser { _ => { let type_name = self.identifier()?; let params = match self.peek() { - LAngleBracket => delimited!(self, self.type_anno, Comma, RAngleBracket), + LAngleBracket => delimited!(self, LAngleBracket, type_name, Comma, RAngleBracket), _ => vec![], }; TypeAnno::Singleton {