Parse match expression
(&mut self)
| 462 | |
| 463 | /// Parse match expression |
| 464 | fn parse_match_expr(&mut self) -> crate::Result<Expr> { |
| 465 | if self.check(&TokenKind::Match) { |
| 466 | let start = self.advance().span; |
| 467 | let scrutinee = Box::new(self.parse_app_expr()?); |
| 468 | |
| 469 | self.expect(TokenKind::With)?; |
| 470 | |
| 471 | let mut arms = Vec::new(); |
| 472 | while self.check(&TokenKind::Pipe) { |
| 473 | self.advance(); |
| 474 | let pattern = self.parse_pattern()?; |
| 475 | self.expect(TokenKind::FatArrow)?; |
| 476 | let body = Box::new(self.parse_expr()?); |
| 477 | |
| 478 | arms.push(MatchArm { |
| 479 | span: pattern.span().to(body.span()), |
| 480 | pattern, |
| 481 | body, |
| 482 | }); |
| 483 | } |
| 484 | |
| 485 | let end = arms.last().map(|a| a.span).unwrap_or(scrutinee.span()); |
| 486 | |
| 487 | Ok(Expr::Match { |
| 488 | span: start.to(end), |
| 489 | scrutinee, |
| 490 | arms, |
| 491 | }) |
| 492 | } else { |
| 493 | self.parse_app_expr() |
| 494 | } |
| 495 | } |
| 496 | |
| 497 | /// Parse application: f x y z |
| 498 | fn parse_app_expr(&mut self) -> crate::Result<Expr> { |
no test coverage detected