(&mut self)
| 387 | } |
| 388 | |
| 389 | fn native_function(&mut self) -> Result<Statement, ParseError> { |
| 390 | let start_token = self.previous(); |
| 391 | let function_name = self.expect_token(TokenKind::Identifier, "function name", "'def'")?; |
| 392 | |
| 393 | self.expect_token( |
| 394 | TokenKind::Punctuation(PunctuationKind::LeftParen), |
| 395 | "'('", |
| 396 | "function name", |
| 397 | )?; |
| 398 | |
| 399 | let mut params: Vec<FieldDeclaration> = Vec::new(); |
| 400 | |
| 401 | if !self.check(&[TokenKind::Punctuation(PunctuationKind::RightParen)]) { |
| 402 | let param_name = self.eat( |
| 403 | TokenKind::Identifier, |
| 404 | CompilationErrorKind::ExpectedToken { |
| 405 | expect: "param name".into(), |
| 406 | found: self.peek().lexeme, |
| 407 | after: None, |
| 408 | }, |
| 409 | )?; |
| 410 | |
| 411 | self.expect_token( |
| 412 | TokenKind::Punctuation(PunctuationKind::Colon), |
| 413 | "':'", |
| 414 | "param name", |
| 415 | )?; |
| 416 | |
| 417 | let param_type = self.type_composition()?; |
| 418 | |
| 419 | params.push(FieldDeclaration::new( |
| 420 | Visibility::Public, |
| 421 | param_name, |
| 422 | param_type, |
| 423 | )); |
| 424 | |
| 425 | while self.try_eat(&[TokenKind::Punctuation(PunctuationKind::Comma)]) { |
| 426 | let param_name = self.eat( |
| 427 | TokenKind::Identifier, |
| 428 | CompilationErrorKind::ExpectedToken { |
| 429 | expect: "param name".into(), |
| 430 | found: self.peek().lexeme, |
| 431 | after: None, |
| 432 | }, |
| 433 | )?; |
| 434 | |
| 435 | self.expect_token( |
| 436 | TokenKind::Punctuation(PunctuationKind::Colon), |
| 437 | "':'", |
| 438 | "param name", |
| 439 | )?; |
| 440 | |
| 441 | let param_type = self.type_composition()?; |
| 442 | |
| 443 | params.push(FieldDeclaration::new( |
| 444 | Visibility::Public, |
| 445 | param_name, |
| 446 | param_type, |
no test coverage detected