From 44334f6f56bd99635f650796af0db8047e4c21c4 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 8 Sep 2018 09:18:42 +0300 Subject: fix labled expressions --- crates/libsyntax2/src/grammar/expressions/atom.rs | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) (limited to 'crates/libsyntax2/src/grammar') 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 loop_expr(p, Some(m)), FOR_KW => for_expr(p, Some(m)), WHILE_KW => while_expr(p, Some(m)), + L_CURLY => block_expr(p, Some(m)), _ => { + // test misplaced_label_err + // fn main() { + // 'loop: impl + // } p.error("expected a loop"); + m.complete(p, ERROR); return None; } } } MATCH_KW => match_expr(p), - UNSAFE_KW if la == L_CURLY => block_expr(p), - L_CURLY => block_expr(p), + UNSAFE_KW if la == L_CURLY => { + let m = p.start(); + p.bump(); + block_expr(p, Some(m)) + }, + L_CURLY => block_expr(p, None), RETURN_KW => return_expr(p), CONTINUE_KW => continue_expr(p), BREAK_KW => break_expr(p), @@ -323,11 +333,11 @@ fn match_arm(p: &mut Parser) -> BlockLike { // fn foo() { // {}; // unsafe {}; +// 'label: {}; // } -pub(super) fn block_expr(p: &mut Parser) -> CompletedMarker { - assert!(p.at(L_CURLY) || p.at(UNSAFE_KW) && p.nth(1) == L_CURLY); - let m = p.start(); - p.eat(UNSAFE_KW); +fn block_expr(p: &mut Parser, m: Option) -> CompletedMarker { + assert!(p.at(L_CURLY)); + let m = m.unwrap_or_else(|| p.start()); block(p); m.complete(p, BLOCK_EXPR) } -- cgit v1.2.3