Browse Source

feat: match block arms

match-statements
Garrit Franke 3 years ago
parent
commit
602d8e7be0
  1. 1
      src/parser/rules.rs
  2. 15
      tests/match_statements.sb

1
src/parser/rules.rs

@ -158,6 +158,7 @@ impl Parser {
fn parse_statement(&mut self) -> Result<Statement, String> {
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(),

15
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()
}

Loading…
Cancel
Save