From fd030f9450ed6910677e30f8fa65b06e71fcffa2 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 2 May 2020 01:12:37 +0200 Subject: Revert "Merge #4233" This reverts commit a5f2b16366f027ad60c58266a66eb7fbdcbda9f9, reversing changes made to c96b2180c1c4206a0a98c280b4d30897eb116336. --- crates/ra_parser/src/grammar/expressions/atom.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'crates/ra_parser/src/grammar/expressions') diff --git a/crates/ra_parser/src/grammar/expressions/atom.rs b/crates/ra_parser/src/grammar/expressions/atom.rs index 76aa601cb..166dfc472 100644 --- a/crates/ra_parser/src/grammar/expressions/atom.rs +++ b/crates/ra_parser/src/grammar/expressions/atom.rs @@ -84,7 +84,7 @@ pub(super) fn atom_expr(p: &mut Parser, r: Restrictions) -> Option<(CompletedMar T![box] => box_expr(p, None), T![for] => for_expr(p, None), T![while] => while_expr(p, None), - T![try] => try_expr(p, None), + T![try] => try_block_expr(p, None), LIFETIME if la == T![:] => { let m = p.start(); label(p); @@ -134,7 +134,7 @@ pub(super) fn atom_expr(p: &mut Parser, r: Restrictions) -> Option<(CompletedMar } }; let blocklike = match done.kind() { - IF_EXPR | WHILE_EXPR | FOR_EXPR | LOOP_EXPR | MATCH_EXPR | BLOCK_EXPR | TRY_EXPR => { + IF_EXPR | WHILE_EXPR | FOR_EXPR | LOOP_EXPR | MATCH_EXPR | BLOCK_EXPR | TRY_BLOCK_EXPR => { BlockLike::Block } _ => BlockLike::NotBlock, @@ -532,7 +532,7 @@ fn break_expr(p: &mut Parser, r: Restrictions) -> CompletedMarker { // fn foo() { // let _ = try {}; // } -fn try_expr(p: &mut Parser, m: Option) -> CompletedMarker { +fn try_block_expr(p: &mut Parser, m: Option) -> CompletedMarker { assert!(p.at(T![try])); let m = m.unwrap_or_else(|| p.start()); // Special-case `try!` as macro. -- cgit v1.2.3 From 4f2134cc33f07c09fe166cec42971828843bc0ef Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 2 May 2020 01:18:19 +0200 Subject: Introduce EffectExpr --- crates/ra_parser/src/grammar/expressions/atom.rs | 29 +++++++++++++++--------- 1 file changed, 18 insertions(+), 11 deletions(-) (limited to 'crates/ra_parser/src/grammar/expressions') diff --git a/crates/ra_parser/src/grammar/expressions/atom.rs b/crates/ra_parser/src/grammar/expressions/atom.rs index 166dfc472..c76b7330c 100644 --- a/crates/ra_parser/src/grammar/expressions/atom.rs +++ b/crates/ra_parser/src/grammar/expressions/atom.rs @@ -92,7 +92,10 @@ pub(super) fn atom_expr(p: &mut Parser, r: Restrictions) -> Option<(CompletedMar T![loop] => loop_expr(p, Some(m)), T![for] => for_expr(p, Some(m)), T![while] => while_expr(p, Some(m)), - T!['{'] => block_expr(p, Some(m)), + T!['{'] => { + block_expr(p); + m.complete(p, EFFECT_EXPR) + } _ => { // test_err misplaced_label_err // fn main() { @@ -108,13 +111,15 @@ pub(super) fn atom_expr(p: &mut Parser, r: Restrictions) -> Option<(CompletedMar let m = p.start(); p.bump(T![async]); p.eat(T![move]); - block_expr(p, Some(m)) + block_expr(p); + m.complete(p, EFFECT_EXPR) } T![match] => match_expr(p), T![unsafe] if la == T!['{'] => { let m = p.start(); p.bump(T![unsafe]); - block_expr(p, Some(m)) + block_expr(p); + m.complete(p, EFFECT_EXPR) } T!['{'] => { // test for_range_from @@ -123,7 +128,7 @@ pub(super) fn atom_expr(p: &mut Parser, r: Restrictions) -> Option<(CompletedMar // break; // } // } - block_expr(p, None) + block_expr(p) } T![return] => return_expr(p), T![continue] => continue_expr(p), @@ -134,7 +139,7 @@ pub(super) fn atom_expr(p: &mut Parser, r: Restrictions) -> Option<(CompletedMar } }; let blocklike = match done.kind() { - IF_EXPR | WHILE_EXPR | FOR_EXPR | LOOP_EXPR | MATCH_EXPR | BLOCK_EXPR | TRY_BLOCK_EXPR => { + IF_EXPR | WHILE_EXPR | FOR_EXPR | LOOP_EXPR | MATCH_EXPR | BLOCK_EXPR | EFFECT_EXPR => { BlockLike::Block } _ => BlockLike::NotBlock, @@ -234,7 +239,7 @@ fn lambda_expr(p: &mut Parser) -> CompletedMarker { if p.at(T!['{']) { // test lambda_ret_block // fn main() { || -> i32 { 92 }(); } - block_expr(p, None); + block_expr(p); } else { p.error("expected `{`"); } @@ -464,10 +469,12 @@ fn match_guard(p: &mut Parser) -> CompletedMarker { // unsafe {}; // 'label: {}; // } -pub(super) fn block_expr(p: &mut Parser, m: Option) -> CompletedMarker { +pub(super) fn block_expr(p: &mut Parser) -> CompletedMarker { assert!(p.at(T!['{'])); - let m = m.unwrap_or_else(|| p.start()); - naked_block(p); + let m = p.start(); + p.bump(T!['{']); + expr_block_contents(p); + p.expect(T!['}']); m.complete(p, BLOCK_EXPR) } @@ -552,8 +559,8 @@ fn try_block_expr(p: &mut Parser, m: Option) -> CompletedMarker { } p.bump(T![try]); - block(p); - m.complete(p, TRY_EXPR) + block_expr(p); + m.complete(p, EFFECT_EXPR) } // test box_expr -- cgit v1.2.3 From 623faefcda3536185232be1676709b0233bb10ba Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 2 May 2020 01:57:21 +0200 Subject: Cleanup inline tests --- crates/ra_parser/src/grammar/expressions/atom.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'crates/ra_parser/src/grammar/expressions') diff --git a/crates/ra_parser/src/grammar/expressions/atom.rs b/crates/ra_parser/src/grammar/expressions/atom.rs index c76b7330c..efb424dae 100644 --- a/crates/ra_parser/src/grammar/expressions/atom.rs +++ b/crates/ra_parser/src/grammar/expressions/atom.rs @@ -92,6 +92,8 @@ pub(super) fn atom_expr(p: &mut Parser, r: Restrictions) -> Option<(CompletedMar T![loop] => loop_expr(p, Some(m)), T![for] => for_expr(p, Some(m)), T![while] => while_expr(p, Some(m)), + // test labeled_block + // fn f() { 'label: {}; } T!['{'] => { block_expr(p); m.complete(p, EFFECT_EXPR) @@ -115,6 +117,8 @@ pub(super) fn atom_expr(p: &mut Parser, r: Restrictions) -> Option<(CompletedMar m.complete(p, EFFECT_EXPR) } T![match] => match_expr(p), + // test unsafe_block + // fn f() { unsafe { } } T![unsafe] if la == T!['{'] => { let m = p.start(); p.bump(T![unsafe]); @@ -466,8 +470,6 @@ fn match_guard(p: &mut Parser) -> CompletedMarker { // test block_expr // fn foo() { // {}; -// unsafe {}; -// 'label: {}; // } pub(super) fn block_expr(p: &mut Parser) -> CompletedMarker { assert!(p.at(T!['{'])); -- cgit v1.2.3