MCPcopy Create free account
hub / github.com/PRQL/prql / lambda_func

Function lambda_func

prqlc/prqlc-parser/src/parser/expr.rs:485–534  ·  view source on GitHub ↗
(expr: E)

Source from the content-addressed store, hash-verified

483}
484
485fn lambda_func<'a, I, E>(expr: E) -> impl Parser<'a, I, Expr, ParserError<'a>> + Clone + 'a
486where
487 I: Input<'a, Token = lr::Token, Span = Span> + BorrowInput<'a>,
488 E: Parser<'a, I, Expr, ParserError<'a>> + Clone + 'a,
489{
490 let param = ident_part()
491 .then(type_expr().delimited_by(ctrl('<'), ctrl('>')).or_not())
492 .then(ctrl(':').ignore_then(expr.clone().map(Box::new)).or_not());
493
494 choice((
495 // func
496 keyword("func").ignore_then(
497 param
498 .clone()
499 .separated_by(new_line().repeated())
500 .allow_leading()
501 .allow_trailing()
502 .collect::<Vec<_>>(),
503 ),
504 // plain
505 param.repeated().collect(),
506 ))
507 .then_ignore(select_ref! { lr::Token { kind: TokenKind::ArrowThin, .. } => () })
508 // return type
509 .then(type_expr().delimited_by(ctrl('<'), ctrl('>')).or_not())
510 // body
511 .then(func_call(expr))
512 .map(|((params, return_ty), body)| {
513 let (pos, name) = params
514 .into_iter()
515 .map(|((name, ty), default_value)| FuncParam {
516 name,
517 ty,
518 default_value,
519 })
520 .partition(|p| p.default_value.is_none());
521
522 Box::new(Func {
523 params: pos,
524 named_params: name,
525
526 body: Box::new(body),
527 return_ty,
528 })
529 })
530 .map(ExprKind::Func)
531 .map_with(|kind, extra| ExprKind::into_expr(kind, extra.span()))
532 .labelled("function definition")
533 .boxed()
534}
535
536pub(crate) fn ident<'a, I>() -> impl Parser<'a, I, Ident, ParserError<'a>> + Clone
537where

Callers 2

expr_callFunction · 0.85
exprFunction · 0.85

Calls 10

type_exprFunction · 0.85
ctrlFunction · 0.85
new_lineFunction · 0.85
func_callFunction · 0.85
mapMethod · 0.80
into_iterMethod · 0.80
ident_partFunction · 0.70
keywordFunction · 0.70
collectMethod · 0.45
spanMethod · 0.45

Tested by

no test coverage detected