MCPcopy Create free account
hub / github.com/astral-sh/ruff / parse_tuple_expression

Method parse_tuple_expression

crates/ruff_python_parser/src/parser/expression.rs:2444–2477  ·  view source on GitHub ↗

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,
    )

Source from the content-addressed store, hash-verified

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

Calls 7

at_sequence_endMethod · 0.80
expectMethod · 0.80
node_rangeMethod · 0.80
pushMethod · 0.45
is_yesMethod · 0.45
shrink_to_fitMethod · 0.45

Tested by

no test coverage detected