From 5a91957fa15611c961df4471be28e17158a92bf6 Mon Sep 17 00:00:00 2001 From: greg Date: Fri, 13 Jul 2018 03:19:02 -0700 Subject: [PATCH] Some incomplete parse work --- schala-lang/src/parsing.rs | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/schala-lang/src/parsing.rs b/schala-lang/src/parsing.rs index 13649a8..4923b5d 100644 --- a/schala-lang/src/parsing.rs +++ b/schala-lang/src/parsing.rs @@ -715,7 +715,10 @@ impl Parser { Identifier(_) => { let id = self.identifier()?; match self.peek() { - LCurlyBrace => { unimplemented!() }, + LCurlyBrace => { + let members = delimited!(self, LCurlyBrace, record_pattern_entry, Comma, RCurlyBrace); + Pattern::Record(id, members) + }, LParen => { let members = delimited!(self, LParen, pattern, Comma, RParen); Pattern::TupleStruct(id, members) @@ -739,6 +742,10 @@ impl Parser { }) }); + parse_method!(record_pattern_entry(&mut self) -> ParseResult<(Rc, Pattern)> { + unimplemented!() + }); + parse_method!(block(&mut self) -> ParseResult { Ok(delimited!(self, LCurlyBrace, statement, Newline | Semicolon, RCurlyBrace, nonstrict)) }); @@ -964,7 +971,7 @@ mod parse_tests { use ::std::rc::Rc; use super::{parse, tokenize}; use builtin::{PrefixOp, BinOp}; - use ast::{AST, Expression, Statement, IfExpressionBody, Discriminator, TypeBody, Variant, Enumerator, ForBody}; + use ast::{AST, Expression, Statement, IfExpressionBody, Discriminator, Pattern, TypeBody, Variant, Enumerator, ForBody}; use super::Statement::*; use super::Declaration::*; use super::Signature; @@ -1393,4 +1400,17 @@ fn a(x) { })]) } } + + #[test] + fn patterns() { + parse_test! { + "if x is Some(a) then { 4 } else { 9 }", AST(vec![ + exprstatement!( + IfExpression { + discriminator: Discriminator::Simple(ex!(Value("x"))), + body: SimplePatternMatch(TupleStruct("Some", [Literal(VarPattern("a"))]), [ExpressionStatement(Expression(NatLiteral(4), None))], Some([ExpressionStatement(Expression(NatLiteral(9), None))])) } + ) + ]) + } + } }