aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_parser
diff options
context:
space:
mode:
authorrobojumper <[email protected]>2019-03-31 15:35:22 +0100
committerrobojumper <[email protected]>2019-03-31 15:35:22 +0100
commitd43dff43b4bb89306c418222df3b262a715c0fda (patch)
treef9a7c3eb9c1d8ac7caad5e88330a1cc5cd86b051 /crates/ra_parser
parentdec9bde10868b5e459535449476d17a6a0987b3e (diff)
Async closure syntax
Diffstat (limited to 'crates/ra_parser')
-rw-r--r--crates/ra_parser/src/grammar/expressions/atom.rs14
-rw-r--r--crates/ra_parser/src/grammar/items.rs2
2 files changed, 13 insertions, 3 deletions
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
68 L_BRACK => array_expr(p), 68 L_BRACK => array_expr(p),
69 PIPE => lambda_expr(p), 69 PIPE => lambda_expr(p),
70 MOVE_KW if la == PIPE => lambda_expr(p), 70 MOVE_KW if la == PIPE => lambda_expr(p),
71 ASYNC_KW if la == PIPE || (la == MOVE_KW && p.nth(2) == PIPE) => lambda_expr(p),
71 IF_KW => if_expr(p), 72 IF_KW => if_expr(p),
72 73
73 LOOP_KW => loop_expr(p, None), 74 LOOP_KW => loop_expr(p, None),
@@ -92,7 +93,7 @@ pub(super) fn atom_expr(p: &mut Parser, r: Restrictions) -> Option<(CompletedMar
92 } 93 }
93 } 94 }
94 } 95 }
95 ASYNC_KW if la == L_CURLY || la == MOVE_KW => { 96 ASYNC_KW if la == L_CURLY || (la == MOVE_KW && p.nth(2) == L_CURLY) => {
96 let m = p.start(); 97 let m = p.start();
97 p.bump(); 98 p.bump();
98 p.eat(MOVE_KW); 99 p.eat(MOVE_KW);
@@ -190,10 +191,19 @@ fn array_expr(p: &mut Parser) -> CompletedMarker {
190// || -> i32 { 92 }; 191// || -> i32 { 92 };
191// |x| x; 192// |x| x;
192// move |x: i32,| x; 193// move |x: i32,| x;
194// async || {};
195// move || {};
196// async move || {};
193// } 197// }
194fn lambda_expr(p: &mut Parser) -> CompletedMarker { 198fn lambda_expr(p: &mut Parser) -> CompletedMarker {
195 assert!(p.at(PIPE) || (p.at(MOVE_KW) && p.nth(1) == PIPE)); 199 assert!(
200 p.at(PIPE)
201 || (p.at(MOVE_KW) && p.nth(1) == PIPE)
202 || (p.at(ASYNC_KW) && p.nth(1) == PIPE)
203 || (p.at(ASYNC_KW) && p.nth(1) == MOVE_KW && p.nth(2) == PIPE)
204 );
196 let m = p.start(); 205 let m = p.start();
206 p.eat(ASYNC_KW);
197 p.eat(MOVE_KW); 207 p.eat(MOVE_KW);
198 params::param_list_opt_types(p); 208 params::param_list_opt_types(p);
199 if opt_fn_ret_type(p) { 209 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
82 // test_err async_without_semicolon 82 // test_err async_without_semicolon
83 // fn foo() { let _ = async {} } 83 // fn foo() { let _ = async {} }
84 has_mods |= p.eat(CONST_KW); 84 has_mods |= p.eat(CONST_KW);
85 if p.at(ASYNC_KW) && p.nth(1) != L_CURLY && p.nth(1) != MOVE_KW { 85 if p.at(ASYNC_KW) && p.nth(1) != L_CURLY && p.nth(1) != MOVE_KW && p.nth(1) != PIPE {
86 p.eat(ASYNC_KW); 86 p.eat(ASYNC_KW);
87 has_mods = true; 87 has_mods = true;
88 } 88 }