MCPcopy Index your code
hub / github.com/endbasic/endbasic / parse_callable_args

Method parse_callable_args

core/src/parser.rs:1339–1382  ·  view source on GitHub ↗

Parses the optional parameter list that may appear after a `FUNCTION` or `SUB` definition, including the opening and closing parenthesis.

(&mut self)

Source from the content-addressed store, hash-verified

1337 /// Parses the optional parameter list that may appear after a `FUNCTION` or `SUB` definition,
1338 /// including the opening and closing parenthesis.
1339 fn parse_callable_args(&mut self) -> Result<Vec<VarRef>> {
1340 let mut params = vec![];
1341 let peeked = self.lexer.peek()?;
1342 if peeked.token == Token::LeftParen {
1343 self.lexer.consume_peeked();
1344
1345 loop {
1346 let token_span = self.lexer.read()?;
1347 match token_span.token {
1348 Token::Symbol(param) => {
1349 let peeked = self.lexer.peek()?;
1350 if peeked.token == Token::As {
1351 self.lexer.consume_peeked();
1352
1353 let name = vref_to_unannotated_string(param, token_span.pos)?;
1354 let (vtype, _pos) = self.parse_as_type()?;
1355 params.push(VarRef::new(name, Some(vtype)));
1356 } else {
1357 params.push(param);
1358 }
1359 }
1360 _ => {
1361 return Err(Error::Bad(
1362 token_span.pos,
1363 "Expected a parameter name".to_owned(),
1364 ));
1365 }
1366 }
1367
1368 let token_span = self.lexer.read()?;
1369 match token_span.token {
1370 Token::Comma => (),
1371 Token::RightParen => break,
1372 _ => {
1373 return Err(Error::Bad(
1374 token_span.pos,
1375 "Expected comma, AS, or end of parameters list".to_owned(),
1376 ));
1377 }
1378 }
1379 }
1380 }
1381 Ok(params)
1382 }
1383
1384 /// Parses the body of a callable and returns the collection of statements and the position
1385 /// of the end of the body.

Callers 1

Calls 6

consume_peekedMethod · 0.80
parse_as_typeMethod · 0.80
pushMethod · 0.80
peekMethod · 0.45
readMethod · 0.45

Tested by

no test coverage detected