MCPcopy Create free account
hub / github.com/GPPVM-Project/SkyLC / function_declaration

Method function_declaration

crates/skyl-parser/src/parser.rs:560–657  ·  view source on GitHub ↗
(&mut self, access: Visibility)

Source from the content-addressed store, hash-verified

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,

Callers 3

declarationMethod · 0.80
parse_pub_accessMethod · 0.80
parse_mod_accessMethod · 0.80

Calls 12

OperatorClass · 0.85
expect_tokenMethod · 0.80
eatMethod · 0.80
type_compositionMethod · 0.80
parse_scopeMethod · 0.80
mergeMethod · 0.80
previousMethod · 0.45
checkMethod · 0.45
peekMethod · 0.45
pushMethod · 0.45
try_eatMethod · 0.45
spanMethod · 0.45

Tested by

no test coverage detected