MCPcopy Create free account
hub / github.com/agenticsorg/lean-agentic / parse_match_expr

Method parse_match_expr

leanr-syntax/src/parser.rs:464–495  ·  view source on GitHub ↗

Parse match expression

(&mut self)

Source from the content-addressed store, hash-verified

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> {

Callers 1

parse_let_exprMethod · 0.80

Calls 9

parse_app_exprMethod · 0.80
expectMethod · 0.80
parse_patternMethod · 0.80
parse_exprMethod · 0.80
toMethod · 0.80
spanMethod · 0.80
checkMethod · 0.45
advanceMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected