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 +- .../data/parser/inline/ok/0106_lambda_expr.rs | 3 ++ .../data/parser/inline/ok/0106_lambda_expr.txt | 56 +++++++++++++++++++--- 4 files changed, 66 insertions(+), 9 deletions(-) (limited to 'crates') 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; } diff --git a/crates/ra_syntax/tests/data/parser/inline/ok/0106_lambda_expr.rs b/crates/ra_syntax/tests/data/parser/inline/ok/0106_lambda_expr.rs index c20d29751..075717823 100644 --- a/crates/ra_syntax/tests/data/parser/inline/ok/0106_lambda_expr.rs +++ b/crates/ra_syntax/tests/data/parser/inline/ok/0106_lambda_expr.rs @@ -3,4 +3,7 @@ fn foo() { || -> i32 { 92 }; |x| x; move |x: i32,| x; + async || {}; + move || {}; + async move || {}; } diff --git a/crates/ra_syntax/tests/data/parser/inline/ok/0106_lambda_expr.txt b/crates/ra_syntax/tests/data/parser/inline/ok/0106_lambda_expr.txt index 98271c233..b885d239a 100644 --- a/crates/ra_syntax/tests/data/parser/inline/ok/0106_lambda_expr.txt +++ b/crates/ra_syntax/tests/data/parser/inline/ok/0106_lambda_expr.txt @@ -1,5 +1,5 @@ -SOURCE_FILE@[0; 79) - FN_DEF@[0; 78) +SOURCE_FILE@[0; 134) + FN_DEF@[0; 133) FN_KW@[0; 2) WHITESPACE@[2; 3) NAME@[3; 6) @@ -8,7 +8,7 @@ SOURCE_FILE@[0; 79) L_PAREN@[6; 7) R_PAREN@[7; 8) WHITESPACE@[8; 9) - BLOCK@[9; 78) + BLOCK@[9; 133) L_CURLY@[9; 10) WHITESPACE@[10; 15) EXPR_STMT@[15; 21) @@ -90,6 +90,50 @@ SOURCE_FILE@[0; 79) NAME_REF@[74; 75) IDENT@[74; 75) "x" SEMI@[75; 76) - WHITESPACE@[76; 77) - R_CURLY@[77; 78) - WHITESPACE@[78; 79) + WHITESPACE@[76; 81) + EXPR_STMT@[81; 93) + LAMBDA_EXPR@[81; 92) + ASYNC_KW@[81; 86) + WHITESPACE@[86; 87) + PARAM_LIST@[87; 89) + PIPE@[87; 88) + PIPE@[88; 89) + WHITESPACE@[89; 90) + BLOCK_EXPR@[90; 92) + BLOCK@[90; 92) + L_CURLY@[90; 91) + R_CURLY@[91; 92) + SEMI@[92; 93) + WHITESPACE@[93; 98) + EXPR_STMT@[98; 109) + LAMBDA_EXPR@[98; 108) + MOVE_KW@[98; 102) + WHITESPACE@[102; 103) + PARAM_LIST@[103; 105) + PIPE@[103; 104) + PIPE@[104; 105) + WHITESPACE@[105; 106) + BLOCK_EXPR@[106; 108) + BLOCK@[106; 108) + L_CURLY@[106; 107) + R_CURLY@[107; 108) + SEMI@[108; 109) + WHITESPACE@[109; 114) + EXPR_STMT@[114; 131) + LAMBDA_EXPR@[114; 130) + ASYNC_KW@[114; 119) + WHITESPACE@[119; 120) + MOVE_KW@[120; 124) + WHITESPACE@[124; 125) + PARAM_LIST@[125; 127) + PIPE@[125; 126) + PIPE@[126; 127) + WHITESPACE@[127; 128) + BLOCK_EXPR@[128; 130) + BLOCK@[128; 130) + L_CURLY@[128; 129) + R_CURLY@[129; 130) + SEMI@[130; 131) + WHITESPACE@[131; 132) + R_CURLY@[132; 133) + WHITESPACE@[133; 134) -- cgit v1.2.3