A pipeline of `expr`, separated by pipes. Doesn't require parentheses.
(expr: E)
| 338 | |
| 339 | /// A pipeline of `expr`, separated by pipes. Doesn't require parentheses. |
| 340 | pub(crate) fn pipeline<'a, I, E>(expr: E) -> impl Parser<'a, I, Expr, ParserError<'a>> + Clone + 'a |
| 341 | where |
| 342 | I: Input<'a, Token = lr::Token, Span = Span> + BorrowInput<'a>, |
| 343 | E: Parser<'a, I, Expr, ParserError<'a>> + Clone + 'a, |
| 344 | { |
| 345 | // expr has to be a param, because it can be either a normal expr() or a |
| 346 | // recursive expr called from within expr(), which causes a stack overflow |
| 347 | |
| 348 | // TODO: do we need the `maybe_aliased` here rather than in `expr`? We had |
| 349 | // tried `with_doc_comment(expr)` in #4775 (and push an aliased expr into |
| 350 | // `expr`) but couldn't get it work. |
| 351 | with_doc_comment(maybe_aliased(expr)) |
| 352 | .separated_by(pipe()) |
| 353 | .at_least(1) |
| 354 | .collect::<Vec<_>>() |
| 355 | .map_with(|exprs: Vec<Expr>, extra| { |
| 356 | let span = extra.span(); |
| 357 | // If there's only one expr, then we don't need to wrap it |
| 358 | // in a pipeline — just return the lone expr. Otherwise, |
| 359 | // wrap them in a pipeline. |
| 360 | exprs.into_iter().exactly_one().unwrap_or_else(|exprs| { |
| 361 | ExprKind::Pipeline(Pipeline { |
| 362 | exprs: exprs.collect(), |
| 363 | }) |
| 364 | .into_expr(span) |
| 365 | }) |
| 366 | }) |
| 367 | .labelled("pipeline") |
| 368 | } |
| 369 | |
| 370 | // Can remove if we don't end up using this |
| 371 | #[allow(dead_code)] |