Parse destructuring assignment

The only patterns we should parse are `..` in structs and `_`: the rest are either not supported or already valid expressions.
This commit is contained in:
Chayim Refael Friedman 2022-02-24 08:49:47 +00:00 committed by GitHub
parent ab2af50655
commit d9f0731bd2
18 changed files with 543 additions and 218 deletions

View file

@ -593,7 +593,16 @@ pub(crate) fn record_expr_field_list(p: &mut Parser) {
T![.] if p.at(T![..]) => {
m.abandon(p);
p.bump(T![..]);
expr(p);
// test destructuring_assignment_struct_rest_pattern
// fn foo() {
// S { .. } = S {};
// }
// We permit `.. }` on the left-hand side of a destructuring assignment.
if !p.at(T!['}']) {
expr(p);
}
}
T!['{'] => {
error_block(p, "expected a field");

View file

@ -81,6 +81,17 @@ pub(super) fn atom_expr(p: &mut Parser, r: Restrictions) -> Option<(CompletedMar
T![if] => if_expr(p),
T![let] => let_expr(p),
T![_] => {
// test destructuring_assignment_wildcard_pat
// fn foo() {
// _ = 1;
// Some(_) = None;
// }
let m = p.start();
p.bump(T![_]);
m.complete(p, UNDERSCORE_EXPR)
}
T![loop] => loop_expr(p, None),
T![box] => box_expr(p, None),
T![for] => for_expr(p, None),

View file

@ -188,6 +188,7 @@ pub enum SyntaxKind {
RETURN_EXPR,
YIELD_EXPR,
LET_EXPR,
UNDERSCORE_EXPR,
MATCH_EXPR,
MATCH_ARM_LIST,
MATCH_ARM,