From 602d8e7be0819d3fc6887a609a81be20b5d2fbd2 Mon Sep 17 00:00:00 2001 From: Garrit Franke Date: Sun, 21 Feb 2021 17:46:25 +0100 Subject: [PATCH] feat: match block arms --- src/parser/rules.rs | 1 + tests/match_statements.sb | 15 +++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/src/parser/rules.rs b/src/parser/rules.rs index a739ebb..fe296e9 100644 --- a/src/parser/rules.rs +++ b/src/parser/rules.rs @@ -158,6 +158,7 @@ impl Parser { fn parse_statement(&mut self) -> Result { let token = self.peek()?; match &token.kind { + TokenKind::CurlyBracesOpen => self.parse_block(), TokenKind::Keyword(Keyword::Let) => self.parse_declare(), TokenKind::Keyword(Keyword::Return) => self.parse_return(), TokenKind::Keyword(Keyword::If) => self.parse_conditional_statement(), diff --git a/tests/match_statements.sb b/tests/match_statements.sb index 0ce62f2..70e559b 100644 --- a/tests/match_statements.sb +++ b/tests/match_statements.sb @@ -16,7 +16,22 @@ fn test_boolean_match() { } } +fn test_match_with_block_statement() { + let x = 42 + + match x { + 1 => println("x is 1") + 2 => { + println("This is a branch with multiple statements.") + println("x is 2, in case you are wondering") + } + 42 => println("The answer to the universe and everything!") + // default => println("Default case") + } +} + fn main() { test_basic_match() test_boolean_match() + test_match_with_block_statement() }