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,
)
| 2364 | /// |
| 2365 | /// Uses the `parse_func` to parse each item in the tuple. |
| 2366 | pub(super) fn parse_tuple_expression( |
| 2367 | &mut self, |
| 2368 | first_element: Expr, |
| 2369 | start: TextSize, |
| 2370 | parenthesized: Parenthesized, |
| 2371 | mut parse_func: impl FnMut(&mut Parser<'src>) -> ParsedExpr, |
| 2372 | ) -> ast::ExprTuple { |
| 2373 | // TODO(dhruvmanila): Can we remove `parse_func` and use `parenthesized` to |
| 2374 | // determine the parsing function? |
| 2375 | |
| 2376 | if !self.at_sequence_end() { |
| 2377 | self.expect(TokenKind::Comma); |
| 2378 | } |
| 2379 | |
| 2380 | let elts_snapshot = self.expr_scratch.snapshot(); |
| 2381 | self.expr_scratch.push(first_element); |
| 2382 | |
| 2383 | self.parse_comma_separated_list(RecoveryContextKind::TupleElements(parenthesized), |p| { |
| 2384 | let element = parse_func(p).expr; |
| 2385 | p.expr_scratch.push(element); |
| 2386 | }); |
| 2387 | |
| 2388 | if parenthesized.is_yes() { |
| 2389 | self.expect(TokenKind::Rpar); |
| 2390 | } |
| 2391 | |
| 2392 | ast::ExprTuple { |
| 2393 | elts: self.expr_scratch.take(elts_snapshot), |
| 2394 | ctx: ExprContext::Load, |
| 2395 | range: self.node_range(start), |
| 2396 | node_index: AtomicNodeIndex::NONE, |
| 2397 | parenthesized: parenthesized.is_yes(), |
| 2398 | } |
| 2399 | } |
| 2400 | |
| 2401 | /// Parses a list expression. |
| 2402 | /// |
no test coverage detected