Refactor the ExprDict node (#11267)

Co-authored-by: Micha Reiser <micha@reiser.io>
This commit is contained in:
Alex Waygood 2024-05-07 12:46:10 +01:00 committed by GitHub
parent de270154a1
commit 6774f27f4b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
52 changed files with 2425 additions and 2240 deletions

View file

@ -51,24 +51,23 @@ pub(super) fn pattern_to_expr(pattern: Pattern) -> Expr {
patterns,
rest,
}) => {
let mut keys = keys.into_iter().map(Option::Some).collect::<Vec<_>>();
let mut values = patterns
let mut items: Vec<ast::DictItem> = keys
.into_iter()
.map(pattern_to_expr)
.collect::<Vec<_>>();
.zip(patterns)
.map(|(key, pattern)| ast::DictItem {
key: Some(key),
value: pattern_to_expr(pattern),
})
.collect();
if let Some(rest) = rest {
keys.push(None);
values.push(Expr::Name(ast::ExprName {
let value = Expr::Name(ast::ExprName {
range: rest.range,
id: rest.id,
ctx: ExprContext::Store,
}));
});
items.push(ast::DictItem { key: None, value });
}
Expr::Dict(ast::ExprDict {
range,
keys,
values,
})
Expr::Dict(ast::ExprDict { range, items })
}
Pattern::MatchClass(ast::PatternMatchClass {
range,