Skip to content

Commit c5121d6

Browse files
committed
Reduce atom-parser return value size
1 parent 77c28c0 commit c5121d6

1 file changed

Lines changed: 13 additions & 10 deletions

File tree

‎crates/ruff_python_parser/src/parser/expression.rs‎

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -417,11 +417,12 @@ impl<'src> Parser<'src> {
417417
_ => {}
418418
}
419419

420-
let lhs = self.parse_atom(context);
420+
let mut is_parenthesized = false;
421+
let lhs = self.parse_atom(context, &mut is_parenthesized);
421422

422423
ParsedExpr {
423-
expr: self.parse_postfix_expression(lhs.expr, start, context),
424-
is_parenthesized: lhs.is_parenthesized,
424+
expr: self.parse_postfix_expression(lhs, start, context),
425+
is_parenthesized,
425426
}
426427
}
427428

@@ -577,13 +578,15 @@ impl<'src> Parser<'src> {
577578
}
578579
}
579580

580-
/// Parses an atom.
581+
/// Parses an atom, writing grouping-parenthesis metadata separately to keep
582+
/// the return value an `Expr`.
581583
///
582584
/// See: <https://docs.python.org/3/reference/expressions.html#atoms>
583-
fn parse_atom(&mut self, context: ExpressionContext) -> ParsedExpr {
585+
fn parse_atom(&mut self, context: ExpressionContext, is_parenthesized: &mut bool) -> Expr {
586+
*is_parenthesized = false;
584587
let start = self.node_start();
585588

586-
let lhs = match self.current_token_kind() {
589+
match self.current_token_kind() {
587590
TokenKind::Float => {
588591
let value = self.bump_float();
589592

@@ -647,7 +650,9 @@ impl<'src> Parser<'src> {
647650
self.parse_strings()
648651
}
649652
TokenKind::Lpar => {
650-
return self.parse_parenthesized_expression();
653+
let parsed = self.parse_parenthesized_expression();
654+
*is_parenthesized = parsed.is_parenthesized;
655+
parsed.expr
651656
}
652657
TokenKind::Lsqb => self.parse_list_like_expression(),
653658
TokenKind::Lbrace => self.parse_set_or_dict_like_expression(),
@@ -668,9 +673,7 @@ impl<'src> Parser<'src> {
668673
})
669674
}
670675
}
671-
};
672-
673-
lhs.into()
676+
}
674677
}
675678

676679
/// Parses a postfix expression in a loop until there are no postfix expressions left to parse.

0 commit comments

Comments
 (0)