(&mut self, access: Visibility)
| 558 | } |
| 559 | |
| 560 | fn function_declaration(&mut self, access: Visibility) -> Result<Statement, ParseError> { |
| 561 | let start_token = self.previous(); |
| 562 | let function_name = self.expect_token(TokenKind::Identifier, "function name", "'def'")?; |
| 563 | |
| 564 | self.expect_token( |
| 565 | TokenKind::Punctuation(PunctuationKind::LeftParen), |
| 566 | "'('", |
| 567 | "function name", |
| 568 | )?; |
| 569 | |
| 570 | let mut params: Vec<FieldDeclaration> = Vec::new(); |
| 571 | |
| 572 | if !self.check(&[TokenKind::Punctuation(PunctuationKind::RightParen)]) { |
| 573 | let param_name = self.eat( |
| 574 | TokenKind::Identifier, |
| 575 | CompilationErrorKind::ExpectedToken { |
| 576 | expect: "param name".into(), |
| 577 | found: self.peek().lexeme, |
| 578 | after: None, |
| 579 | }, |
| 580 | )?; |
| 581 | |
| 582 | self.expect_token( |
| 583 | TokenKind::Punctuation(PunctuationKind::Colon), |
| 584 | "':'", |
| 585 | "param name", |
| 586 | )?; |
| 587 | |
| 588 | let param_type = self.type_composition()?; |
| 589 | |
| 590 | params.push(FieldDeclaration::new( |
| 591 | Visibility::Public, |
| 592 | param_name, |
| 593 | param_type, |
| 594 | )); |
| 595 | |
| 596 | while self.try_eat(&[TokenKind::Punctuation(PunctuationKind::Comma)]) { |
| 597 | let param_name = self.eat( |
| 598 | TokenKind::Identifier, |
| 599 | CompilationErrorKind::ExpectedToken { |
| 600 | expect: "param name".into(), |
| 601 | found: self.peek().lexeme, |
| 602 | after: None, |
| 603 | }, |
| 604 | )?; |
| 605 | |
| 606 | self.expect_token( |
| 607 | TokenKind::Punctuation(PunctuationKind::Colon), |
| 608 | "':'", |
| 609 | "param name", |
| 610 | )?; |
| 611 | |
| 612 | let param_type = self.type_composition()?; |
| 613 | |
| 614 | params.push(FieldDeclaration::new( |
| 615 | Visibility::Public, |
| 616 | param_name, |
| 617 | param_type, |
no test coverage detected