diff options
author | Aleksey Kladov <[email protected]> | 2018-09-08 07:18:42 +0100 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2018-09-08 07:18:42 +0100 |
commit | 44334f6f56bd99635f650796af0db8047e4c21c4 (patch) | |
tree | 2cee555747588449ba3cc1279b254e9b2140b83e /crates/libsyntax2/src/grammar/expressions | |
parent | 127814d9a7f62c834c0893ff05e933aac4be89e9 (diff) |
fix labled expressions
Diffstat (limited to 'crates/libsyntax2/src/grammar/expressions')
-rw-r--r-- | crates/libsyntax2/src/grammar/expressions/atom.rs | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/crates/libsyntax2/src/grammar/expressions/atom.rs b/crates/libsyntax2/src/grammar/expressions/atom.rs index a17c27b31..f8b50b355 100644 --- a/crates/libsyntax2/src/grammar/expressions/atom.rs +++ b/crates/libsyntax2/src/grammar/expressions/atom.rs | |||
@@ -62,16 +62,26 @@ pub(super) fn atom_expr(p: &mut Parser, r: Restrictions) -> Option<CompletedMark | |||
62 | LOOP_KW => loop_expr(p, Some(m)), | 62 | LOOP_KW => loop_expr(p, Some(m)), |
63 | FOR_KW => for_expr(p, Some(m)), | 63 | FOR_KW => for_expr(p, Some(m)), |
64 | WHILE_KW => while_expr(p, Some(m)), | 64 | WHILE_KW => while_expr(p, Some(m)), |
65 | L_CURLY => block_expr(p, Some(m)), | ||
65 | _ => { | 66 | _ => { |
67 | // test misplaced_label_err | ||
68 | // fn main() { | ||
69 | // 'loop: impl | ||
70 | // } | ||
66 | p.error("expected a loop"); | 71 | p.error("expected a loop"); |
72 | m.complete(p, ERROR); | ||
67 | return None; | 73 | return None; |
68 | } | 74 | } |
69 | } | 75 | } |
70 | } | 76 | } |
71 | 77 | ||
72 | MATCH_KW => match_expr(p), | 78 | MATCH_KW => match_expr(p), |
73 | UNSAFE_KW if la == L_CURLY => block_expr(p), | 79 | UNSAFE_KW if la == L_CURLY => { |
74 | L_CURLY => block_expr(p), | 80 | let m = p.start(); |
81 | p.bump(); | ||
82 | block_expr(p, Some(m)) | ||
83 | }, | ||
84 | L_CURLY => block_expr(p, None), | ||
75 | RETURN_KW => return_expr(p), | 85 | RETURN_KW => return_expr(p), |
76 | CONTINUE_KW => continue_expr(p), | 86 | CONTINUE_KW => continue_expr(p), |
77 | BREAK_KW => break_expr(p), | 87 | BREAK_KW => break_expr(p), |
@@ -323,11 +333,11 @@ fn match_arm(p: &mut Parser) -> BlockLike { | |||
323 | // fn foo() { | 333 | // fn foo() { |
324 | // {}; | 334 | // {}; |
325 | // unsafe {}; | 335 | // unsafe {}; |
336 | // 'label: {}; | ||
326 | // } | 337 | // } |
327 | pub(super) fn block_expr(p: &mut Parser) -> CompletedMarker { | 338 | fn block_expr(p: &mut Parser, m: Option<Marker>) -> CompletedMarker { |
328 | assert!(p.at(L_CURLY) || p.at(UNSAFE_KW) && p.nth(1) == L_CURLY); | 339 | assert!(p.at(L_CURLY)); |
329 | let m = p.start(); | 340 | let m = m.unwrap_or_else(|| p.start()); |
330 | p.eat(UNSAFE_KW); | ||
331 | block(p); | 341 | block(p); |
332 | m.complete(p, BLOCK_EXPR) | 342 | m.complete(p, BLOCK_EXPR) |
333 | } | 343 | } |