mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-01 09:22:19 +00:00
Refactor the ExprDict
node (#11267)
Co-authored-by: Micha Reiser <micha@reiser.io>
This commit is contained in:
parent
de270154a1
commit
6774f27f4b
52 changed files with 2425 additions and 2240 deletions
|
@ -1544,8 +1544,7 @@ impl<'src> Parser<'src> {
|
|||
// Return an empty `DictExpr` when finding a `}` right after the `{`
|
||||
if self.eat(TokenKind::Rbrace) {
|
||||
return Expr::Dict(ast::ExprDict {
|
||||
keys: vec![],
|
||||
values: vec![],
|
||||
items: vec![],
|
||||
range: self.node_range(start),
|
||||
});
|
||||
}
|
||||
|
@ -1794,21 +1793,24 @@ impl<'src> Parser<'src> {
|
|||
self.expect(TokenKind::Comma);
|
||||
}
|
||||
|
||||
let mut keys = vec![key];
|
||||
let mut values = vec![value];
|
||||
let mut items = vec![ast::DictItem { key, value }];
|
||||
|
||||
self.parse_comma_separated_list(RecoveryContextKind::DictElements, |parser| {
|
||||
if parser.eat(TokenKind::DoubleStar) {
|
||||
keys.push(None);
|
||||
|
||||
// Handle dictionary unpacking. Here, the grammar is `'**' bitwise_or`
|
||||
// which requires limiting the expression.
|
||||
values.push(parser.parse_expression_with_bitwise_or_precedence().expr);
|
||||
items.push(ast::DictItem {
|
||||
key: None,
|
||||
value: parser.parse_expression_with_bitwise_or_precedence().expr,
|
||||
});
|
||||
} else {
|
||||
keys.push(Some(parser.parse_conditional_expression_or_higher().expr));
|
||||
let key = parser.parse_conditional_expression_or_higher().expr;
|
||||
parser.expect(TokenKind::Colon);
|
||||
|
||||
values.push(parser.parse_conditional_expression_or_higher().expr);
|
||||
items.push(ast::DictItem {
|
||||
key: Some(key),
|
||||
value: parser.parse_conditional_expression_or_higher().expr,
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -1816,8 +1818,7 @@ impl<'src> Parser<'src> {
|
|||
|
||||
ast::ExprDict {
|
||||
range: self.node_range(start),
|
||||
keys,
|
||||
values,
|
||||
items,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue