Parse `impl Type { method: (self: Type*, ...) -> R { ... } }`; each method desugars to a free function `Type_method` (static dispatch, explicit self).
(&mut self)
| 486 | } |
| 487 | self.expect_rparen()?; |
| 488 | } |
| 489 | variants.push(Variant { |
| 490 | name: variant_name, |
| 491 | payload, |
| 492 | }); |
| 493 | |
| 494 | let newline_separated = matches!(self.peek(), Some(Token::StatementTerminator)); |
| 495 | self.consume_terminators(); |
| 496 | if self.match_comma() { |
| 497 | self.consume_terminators(); |
| 498 | } else if !newline_separated && !self.check_rbrace() { |
| 499 | return Err(self.error("expected `,` or newline between enum variants")); |
| 500 | } |
| 501 | } |
| 502 | |
| 503 | self.expect_rbrace()?; |
| 504 | Ok(DeclNode::Enum { |
| 505 | name, |
| 506 | generics, |
| 507 | bounds, |
| 508 | variants, |
| 509 | }) |
| 510 | } |
| 511 | |
| 512 | fn parse_function_decl( |
| 513 | &mut self, |
| 514 | is_extern: bool, |
| 515 | is_import_interface: bool, |
| 516 | ) -> Result<DeclNode, ParserError> { |
| 517 | let name = self.expect_ident()?; |
| 518 | self.expect_colon()?; |
| 519 | |
| 520 | let (generics, bounds) = self.parse_generic_params_with_bounds()?; |
| 521 | |
| 522 | let params = self.parse_param_list()?; |
| 523 | |
| 524 | let return_type = if self.match_arrow() { |
| 525 | if self.peek() == Some(&Token::LParen) && self.peek_n(1) == Some(&Token::RParen) { |
| 526 | return Err(self.error("void functions omit `->`; `-> ()` is not valid")); |
| 527 | } |
| 528 | Some(self.parse_return_type()?) |
| 529 | } else { |
| 530 | None |
| 531 | }; |
| 532 | |
| 533 | let body = if is_extern { |
| 534 | None |
| 535 | } else if self.check_lbrace() { |
| 536 | Some(self.parse_block()?) |
| 537 | } else { |
| 538 | return Err(self.error("expected function body block")); |
| 539 | }; |
| 540 | |
| 541 | Ok(DeclNode::Function { |
| 542 | name, |
| 543 | generics, |
no test coverage detected