From d43dff43b4bb89306c418222df3b262a715c0fda Mon Sep 17 00:00:00 2001 From: robojumper Date: Sun, 31 Mar 2019 16:35:22 +0200 Subject: Async closure syntax --- crates/ra_parser/src/grammar/expressions/atom.rs | 14 ++++++++++++-- crates/ra_parser/src/grammar/items.rs | 2 +- 2 files changed, 13 insertions(+), 3 deletions(-) (limited to 'crates/ra_parser') diff --git a/crates/ra_parser/src/grammar/expressions/atom.rs b/crates/ra_parser/src/grammar/expressions/atom.rs index 8653d4055..d0feed616 100644 --- a/crates/ra_parser/src/grammar/expressions/atom.rs +++ b/crates/ra_parser/src/grammar/expressions/atom.rs @@ -68,6 +68,7 @@ pub(super) fn atom_expr(p: &mut Parser, r: Restrictions) -> Option<(CompletedMar L_BRACK => array_expr(p), PIPE => lambda_expr(p), MOVE_KW if la == PIPE => lambda_expr(p), + ASYNC_KW if la == PIPE || (la == MOVE_KW && p.nth(2) == PIPE) => lambda_expr(p), IF_KW => if_expr(p), LOOP_KW => loop_expr(p, None), @@ -92,7 +93,7 @@ pub(super) fn atom_expr(p: &mut Parser, r: Restrictions) -> Option<(CompletedMar } } } - ASYNC_KW if la == L_CURLY || la == MOVE_KW => { + ASYNC_KW if la == L_CURLY || (la == MOVE_KW && p.nth(2) == L_CURLY) => { let m = p.start(); p.bump(); p.eat(MOVE_KW); @@ -190,10 +191,19 @@ fn array_expr(p: &mut Parser) -> CompletedMarker { // || -> i32 { 92 }; // |x| x; // move |x: i32,| x; +// async || {}; +// move || {}; +// async move || {}; // } fn lambda_expr(p: &mut Parser) -> CompletedMarker { - assert!(p.at(PIPE) || (p.at(MOVE_KW) && p.nth(1) == PIPE)); + assert!( + p.at(PIPE) + || (p.at(MOVE_KW) && p.nth(1) == PIPE) + || (p.at(ASYNC_KW) && p.nth(1) == PIPE) + || (p.at(ASYNC_KW) && p.nth(1) == MOVE_KW && p.nth(2) == PIPE) + ); let m = p.start(); + p.eat(ASYNC_KW); p.eat(MOVE_KW); params::param_list_opt_types(p); if opt_fn_ret_type(p) { diff --git a/crates/ra_parser/src/grammar/items.rs b/crates/ra_parser/src/grammar/items.rs index 8d8828652..c4b8ef3c7 100644 --- a/crates/ra_parser/src/grammar/items.rs +++ b/crates/ra_parser/src/grammar/items.rs @@ -82,7 +82,7 @@ pub(super) fn maybe_item(p: &mut Parser, m: Marker, flavor: ItemFlavor) -> Resul // test_err async_without_semicolon // fn foo() { let _ = async {} } has_mods |= p.eat(CONST_KW); - if p.at(ASYNC_KW) && p.nth(1) != L_CURLY && p.nth(1) != MOVE_KW { + if p.at(ASYNC_KW) && p.nth(1) != L_CURLY && p.nth(1) != MOVE_KW && p.nth(1) != PIPE { p.eat(ASYNC_KW); has_mods = true; } -- cgit v1.2.3