diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2020-05-02 13:36:52 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2020-05-02 13:36:52 +0100 |
commit | a2ae2bbb833be6874a420eaa33dcb28c89f7590d (patch) | |
tree | 73f335deb44a8ef894deb7394445d6f1166e28a6 /crates/ra_parser/src/grammar/expressions | |
parent | fb8fb65131c8d3e6335efd401e4e83287be49357 (diff) | |
parent | 359d3be308cab2415218200f5799c5031213c250 (diff) |
Merge #4261
4261: Fix parsing of blocks without `{` r=matklad a=matklad
bors r+
🤖
Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ra_parser/src/grammar/expressions')
-rw-r--r-- | crates/ra_parser/src/grammar/expressions/atom.rs | 41 |
1 files changed, 23 insertions, 18 deletions
diff --git a/crates/ra_parser/src/grammar/expressions/atom.rs b/crates/ra_parser/src/grammar/expressions/atom.rs index efb424dae..706a2f796 100644 --- a/crates/ra_parser/src/grammar/expressions/atom.rs +++ b/crates/ra_parser/src/grammar/expressions/atom.rs | |||
@@ -132,7 +132,7 @@ pub(super) fn atom_expr(p: &mut Parser, r: Restrictions) -> Option<(CompletedMar | |||
132 | // break; | 132 | // break; |
133 | // } | 133 | // } |
134 | // } | 134 | // } |
135 | block_expr(p) | 135 | block_expr_unchecked(p) |
136 | } | 136 | } |
137 | T![return] => return_expr(p), | 137 | T![return] => return_expr(p), |
138 | T![continue] => continue_expr(p), | 138 | T![continue] => continue_expr(p), |
@@ -240,13 +240,9 @@ fn lambda_expr(p: &mut Parser) -> CompletedMarker { | |||
240 | p.eat(T![move]); | 240 | p.eat(T![move]); |
241 | params::param_list_closure(p); | 241 | params::param_list_closure(p); |
242 | if opt_fn_ret_type(p) { | 242 | if opt_fn_ret_type(p) { |
243 | if p.at(T!['{']) { | 243 | // test lambda_ret_block |
244 | // test lambda_ret_block | 244 | // fn main() { || -> i32 { 92 }(); } |
245 | // fn main() { || -> i32 { 92 }(); } | 245 | block_expr(p); |
246 | block_expr(p); | ||
247 | } else { | ||
248 | p.error("expected `{`"); | ||
249 | } | ||
250 | } else { | 246 | } else { |
251 | if p.at_ts(EXPR_FIRST) { | 247 | if p.at_ts(EXPR_FIRST) { |
252 | expr(p); | 248 | expr(p); |
@@ -270,13 +266,13 @@ fn if_expr(p: &mut Parser) -> CompletedMarker { | |||
270 | let m = p.start(); | 266 | let m = p.start(); |
271 | p.bump(T![if]); | 267 | p.bump(T![if]); |
272 | cond(p); | 268 | cond(p); |
273 | block(p); | 269 | block_expr(p); |
274 | if p.at(T![else]) { | 270 | if p.at(T![else]) { |
275 | p.bump(T![else]); | 271 | p.bump(T![else]); |
276 | if p.at(T![if]) { | 272 | if p.at(T![if]) { |
277 | if_expr(p); | 273 | if_expr(p); |
278 | } else { | 274 | } else { |
279 | block(p); | 275 | block_expr(p); |
280 | } | 276 | } |
281 | } | 277 | } |
282 | m.complete(p, IF_EXPR) | 278 | m.complete(p, IF_EXPR) |
@@ -304,7 +300,7 @@ fn loop_expr(p: &mut Parser, m: Option<Marker>) -> CompletedMarker { | |||
304 | assert!(p.at(T![loop])); | 300 | assert!(p.at(T![loop])); |
305 | let m = m.unwrap_or_else(|| p.start()); | 301 | let m = m.unwrap_or_else(|| p.start()); |
306 | p.bump(T![loop]); | 302 | p.bump(T![loop]); |
307 | block(p); | 303 | block_expr(p); |
308 | m.complete(p, LOOP_EXPR) | 304 | m.complete(p, LOOP_EXPR) |
309 | } | 305 | } |
310 | 306 | ||
@@ -319,7 +315,7 @@ fn while_expr(p: &mut Parser, m: Option<Marker>) -> CompletedMarker { | |||
319 | let m = m.unwrap_or_else(|| p.start()); | 315 | let m = m.unwrap_or_else(|| p.start()); |
320 | p.bump(T![while]); | 316 | p.bump(T![while]); |
321 | cond(p); | 317 | cond(p); |
322 | block(p); | 318 | block_expr(p); |
323 | m.complete(p, WHILE_EXPR) | 319 | m.complete(p, WHILE_EXPR) |
324 | } | 320 | } |
325 | 321 | ||
@@ -334,7 +330,7 @@ fn for_expr(p: &mut Parser, m: Option<Marker>) -> CompletedMarker { | |||
334 | patterns::pattern(p); | 330 | patterns::pattern(p); |
335 | p.expect(T![in]); | 331 | p.expect(T![in]); |
336 | expr_no_struct(p); | 332 | expr_no_struct(p); |
337 | block(p); | 333 | block_expr(p); |
338 | m.complete(p, FOR_EXPR) | 334 | m.complete(p, FOR_EXPR) |
339 | } | 335 | } |
340 | 336 | ||
@@ -467,11 +463,20 @@ fn match_guard(p: &mut Parser) -> CompletedMarker { | |||
467 | m.complete(p, MATCH_GUARD) | 463 | m.complete(p, MATCH_GUARD) |
468 | } | 464 | } |
469 | 465 | ||
470 | // test block_expr | 466 | // test block |
471 | // fn foo() { | 467 | // fn a() {} |
472 | // {}; | 468 | // fn b() { let _ = 1; } |
473 | // } | 469 | // fn c() { 1; 2; } |
474 | pub(super) fn block_expr(p: &mut Parser) -> CompletedMarker { | 470 | // fn d() { 1; 2 } |
471 | pub(crate) fn block_expr(p: &mut Parser) { | ||
472 | if !p.at(T!['{']) { | ||
473 | p.error("expected a block"); | ||
474 | return; | ||
475 | } | ||
476 | block_expr_unchecked(p); | ||
477 | } | ||
478 | |||
479 | fn block_expr_unchecked(p: &mut Parser) -> CompletedMarker { | ||
475 | assert!(p.at(T!['{'])); | 480 | assert!(p.at(T!['{'])); |
476 | let m = p.start(); | 481 | let m = p.start(); |
477 | p.bump(T!['{']); | 482 | p.bump(T!['{']); |