Parses multiple items separated by a comma into a tuple expression. Uses the `parse_func` to parse each item in the tuple.
(
&mut self,
first_element: Expr,
start: TextSize,
parenthesized: Parenthesized,
mut parse_func: impl FnMut(&mut Parser<'src>) -> ParsedExpr,
)
| 2438 | /// |
| 2439 | /// Uses the `parse_func` to parse each item in the tuple. |
| 2440 | pub(super) fn parse_tuple_expression( |
| 2441 | &mut self, |
| 2442 | first_element: Expr, |
| 2443 | start: TextSize, |
| 2444 | parenthesized: Parenthesized, |
| 2445 | mut parse_func: impl FnMut(&mut Parser<'src>) -> ParsedExpr, |
| 2446 | ) -> ast::ExprTuple { |
| 2447 | // TODO(dhruvmanila): Can we remove `parse_func` and use `parenthesized` to |
| 2448 | // determine the parsing function? |
| 2449 | |
| 2450 | if !self.at_sequence_end() { |
| 2451 | self.expect(TokenKind::Comma); |
| 2452 | } |
| 2453 | |
| 2454 | let elts_snapshot = self.expr_scratch.snapshot(); |
| 2455 | self.expr_scratch.push(first_element); |
| 2456 | |
| 2457 | self.parse_comma_separated_list(RecoveryContextKind::TupleElements(parenthesized), |p| { |
| 2458 | let element = parse_func(p).expr; |
| 2459 | p.expr_scratch.push(element); |
| 2460 | }); |
| 2461 | |
| 2462 | if parenthesized.is_yes() { |
| 2463 | self.expect(TokenKind::Rpar); |
| 2464 | } |
| 2465 | |
| 2466 | ast::ExprTuple { |
| 2467 | elts: self.expr_scratch.take(elts_snapshot), |
| 2468 | ctx: ExprContext::Load, |
| 2469 | range: self.node_range(start), |
| 2470 | node_index: AtomicNodeIndex::NONE, |
| 2471 | parenthesized: parenthesized.is_yes(), |
| 2472 | } |
| 2473 | } |
| 2474 | |
| 2475 | /// Parses a list expression. |
| 2476 | /// |
no test coverage detected