T!['('],
T!['{'],
T!['['],
- L_DOLLAR,
T![|],
T![move],
T![box],
LIFETIME_IDENT,
]));
-const EXPR_RECOVERY_SET: TokenSet = TokenSet::new(&[T![let], R_DOLLAR]);
+const EXPR_RECOVERY_SET: TokenSet = TokenSet::new(&[T![let]]);
pub(super) fn atom_expr(p: &mut Parser, r: Restrictions) -> Option<(CompletedMarker, BlockLike)> {
if let Some(m) = literal(p) {
let done = match p.current() {
T!['('] => tuple_expr(p),
T!['['] => array_expr(p),
- L_DOLLAR => meta_var_expr(p),
T![|] => closure_expr(p),
- T![move] if la == T![|] => closure_expr(p),
- T![async] if la == T![|] || (la == T![move] && p.nth(2) == T![|]) => closure_expr(p),
+ T![static] | T![async] | T![move] if la == T![|] => closure_expr(p),
+ T![static] | T![async] if la == T![move] && p.nth(2) == T![|] => closure_expr(p),
+ T![static] if la == T![async] && p.nth(2) == T![|] => closure_expr(p),
+ T![static] if la == T![async] && p.nth(2) == T![move] && p.nth(3) == T![|] => {
+ closure_expr(p)
+ }
T![if] => if_expr(p),
+ T![let] => let_expr(p),
T![loop] => loop_expr(p, None),
T![box] => box_expr(p, None),
// async || {};
// move || {};
// async move || {};
+// static || {};
+// static move || {};
+// static async || {};
+// static async move || {};
// }
fn closure_expr(p: &mut Parser) -> CompletedMarker {
assert!(
|| (p.at(T![move]) && p.nth(1) == T![|])
|| (p.at(T![async]) && p.nth(1) == T![|])
|| (p.at(T![async]) && p.nth(1) == T![move] && p.nth(2) == T![|])
+ || (p.at(T![static]) && p.nth(1) == T![|])
+ || (p.at(T![static]) && p.nth(1) == T![move] && p.nth(2) == T![|])
+ || (p.at(T![static]) && p.nth(1) == T![async] && p.nth(2) == T![|])
+ || (p.at(T![static])
+ && p.nth(1) == T![async]
+ && p.nth(2) == T![move]
+ && p.nth(3) == T![|])
);
let m = p.start();
+ p.eat(T![static]);
p.eat(T![async]);
p.eat(T![move]);
params::param_list_closure(p);
assert!(p.at(T![if]));
let m = p.start();
p.bump(T![if]);
- condition(p);
+ expr_no_struct(p);
block_expr(p);
if p.at(T![else]) {
p.bump(T![else]);
assert!(p.at(T![while]));
let m = m.unwrap_or_else(|| p.start());
p.bump(T![while]);
- condition(p);
+ expr_no_struct(p);
block_expr(p);
m.complete(p, WHILE_EXPR)
}
m.complete(p, FOR_EXPR)
}
-// test cond
-// fn foo() { if let Some(_) = None {} }
-// fn bar() {
-// if let Some(_) | Some(_) = None {}
-// if let | Some(_) = None {}
-// while let Some(_) | Some(_) = None {}
-// while let | Some(_) = None {}
+// test let_expr
+// fn foo() {
+// if let Some(_) = None && true {}
+// while 1 == 5 && (let None = None) {}
// }
-fn condition(p: &mut Parser) {
+fn let_expr(p: &mut Parser) -> CompletedMarker {
let m = p.start();
- if p.eat(T![let]) {
- patterns::pattern_top(p);
- p.expect(T![=]);
- }
- expr_no_struct(p);
- m.complete(p, CONDITION);
+ p.bump(T![let]);
+ patterns::pattern_top(p);
+ p.expect(T![=]);
+ expr_let(p);
+ m.complete(p, LET_EXPR)
}
// test match_expr
if p.at(T!['{']) {
match_arm_list(p);
} else {
- p.error("expected `{`")
+ p.error("expected `{`");
}
m.complete(p, MATCH_EXPR)
}
assert!(p.at(T![if]));
let m = p.start();
p.bump(T![if]);
- if p.eat(T![let]) {
- patterns::pattern_top(p);
- p.expect(T![=]);
- }
expr(p);
m.complete(p, MATCH_GUARD)
}
if p.at(T!['{']) {
stmt_list(p);
} else {
- p.error("expected a block")
+ p.error("expected a block");
}
m.complete(p, BLOCK_EXPR)
}
}
m.complete(p, BOX_EXPR)
}
-
-/// Expression from `$var` macro expansion, wrapped in dollars
-fn meta_var_expr(p: &mut Parser) -> CompletedMarker {
- assert!(p.at(L_DOLLAR));
- let m = p.start();
- p.bump(L_DOLLAR);
- let expr = expr_bp(p, None, Restrictions { forbid_structs: false, prefer_stmt: false }, 1);
-
- match (expr, p.current()) {
- (Some((cm, _)), R_DOLLAR) => {
- p.bump(R_DOLLAR);
- // FIXME: this leaves the dollar hanging in the air...
- m.abandon(p);
- cm
- }
- _ => {
- while !p.at(R_DOLLAR) {
- p.bump_any()
- }
- p.bump(R_DOLLAR);
- m.complete(p, ERROR)
- }
- }
-}