| 78 | } |
| 79 | |
| 80 | fn parse_internal_function(&mut self, access: Visibility) -> Result<Statement, ParseError> { |
| 81 | let start_token = self.previous(); |
| 82 | self.eat( |
| 83 | TokenKind::Keyword(KeywordKind::Def), |
| 84 | CompilationErrorKind::ExpectedToken { |
| 85 | expect: "def".into(), |
| 86 | found: self.peek().lexeme.clone(), |
| 87 | after: None, |
| 88 | }, |
| 89 | )?; |
| 90 | |
| 91 | let function_name = self.eat( |
| 92 | TokenKind::Identifier, |
| 93 | CompilationErrorKind::ExpectedToken { |
| 94 | expect: "identifier".into(), |
| 95 | found: self.peek().lexeme.clone(), |
| 96 | after: None, |
| 97 | }, |
| 98 | )?; |
| 99 | |
| 100 | self.eat( |
| 101 | TokenKind::Punctuation(PunctuationKind::LeftParen), |
| 102 | CompilationErrorKind::ExpectedToken { |
| 103 | expect: "(".into(), |
| 104 | found: self.peek().lexeme.clone(), |
| 105 | after: None, |
| 106 | }, |
| 107 | )?; |
| 108 | |
| 109 | let mut params: Vec<FieldDeclaration> = Vec::new(); |
| 110 | |
| 111 | let param_name = self.eat( |
| 112 | TokenKind::Identifier, |
| 113 | CompilationErrorKind::ExpectedConstruction { |
| 114 | expect: "'self' param".into(), |
| 115 | found: self.peek().lexeme, |
| 116 | }, |
| 117 | )?; |
| 118 | |
| 119 | self.eat( |
| 120 | TokenKind::Punctuation(PunctuationKind::Colon), |
| 121 | CompilationErrorKind::ExpectedToken { |
| 122 | expect: "':'".into(), |
| 123 | found: self.peek().lexeme.clone(), |
| 124 | after: None, |
| 125 | }, |
| 126 | )?; |
| 127 | |
| 128 | let param_type = self.type_composition()?; |
| 129 | |
| 130 | params.push(FieldDeclaration::new( |
| 131 | Visibility::Public, |
| 132 | param_name, |
| 133 | param_type, |
| 134 | )); |
| 135 | |
| 136 | if !self.check(&[TokenKind::Punctuation(PunctuationKind::RightParen)]) { |
| 137 | while self.try_eat(&[TokenKind::Punctuation(PunctuationKind::Comma)]) { |