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

Method native_function

crates/skyl-parser/src/parser.rs:389–483  ·  view source on GitHub ↗
(&mut self)

Source from the content-addressed store, hash-verified

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,

Callers 1

parse_native_declMethod · 0.80

Calls 11

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

Tested by

no test coverage detected