aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_parser/src/grammar
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2020-05-02 10:57:45 +0100
committerGitHub <[email protected]>2020-05-02 10:57:45 +0100
commit75bc0249463b72971200e482d69dad88d4e76ae3 (patch)
treecf12a19a548f77af306bd8eeb4ba6a74175e1790 /crates/ra_parser/src/grammar
parent235728319fb545670e49db996e9c2cd94b8b34eb (diff)
parentb73dbbfbf2cad646eb3f8e3342a1c390a874dc53 (diff)
Merge #4257
4257: ast::EffectExpr r=matklad a=matklad closes #4230 Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ra_parser/src/grammar')
-rw-r--r--crates/ra_parser/src/grammar/expressions.rs13
-rw-r--r--crates/ra_parser/src/grammar/expressions/atom.rs35
2 files changed, 24 insertions, 24 deletions
diff --git a/crates/ra_parser/src/grammar/expressions.rs b/crates/ra_parser/src/grammar/expressions.rs
index cb30b25a8..a23dbcacf 100644
--- a/crates/ra_parser/src/grammar/expressions.rs
+++ b/crates/ra_parser/src/grammar/expressions.rs
@@ -59,16 +59,7 @@ pub(crate) fn block(p: &mut Parser) {
59 p.error("expected a block"); 59 p.error("expected a block");
60 return; 60 return;
61 } 61 }
62 atom::block_expr(p, None); 62 atom::block_expr(p);
63}
64
65pub(crate) fn naked_block(p: &mut Parser) {
66 assert!(p.at(T!['{']));
67 let m = p.start();
68 p.bump(T!['{']);
69 expr_block_contents(p);
70 p.expect(T!['}']);
71 m.complete(p, BLOCK);
72} 63}
73 64
74fn is_expr_stmt_attr_allowed(kind: SyntaxKind) -> bool { 65fn is_expr_stmt_attr_allowed(kind: SyntaxKind) -> bool {
@@ -197,7 +188,7 @@ pub(super) fn stmt(p: &mut Parser, with_semi: StmtWithSemi) {
197 } 188 }
198} 189}
199 190
200pub(crate) fn expr_block_contents(p: &mut Parser) { 191pub(super) fn expr_block_contents(p: &mut Parser) {
201 // This is checked by a validator 192 // This is checked by a validator
202 attributes::inner_attributes(p); 193 attributes::inner_attributes(p);
203 194
diff --git a/crates/ra_parser/src/grammar/expressions/atom.rs b/crates/ra_parser/src/grammar/expressions/atom.rs
index 166dfc472..efb424dae 100644
--- a/crates/ra_parser/src/grammar/expressions/atom.rs
+++ b/crates/ra_parser/src/grammar/expressions/atom.rs
@@ -92,7 +92,12 @@ pub(super) fn atom_expr(p: &mut Parser, r: Restrictions) -> Option<(CompletedMar
92 T![loop] => loop_expr(p, Some(m)), 92 T![loop] => loop_expr(p, Some(m)),
93 T![for] => for_expr(p, Some(m)), 93 T![for] => for_expr(p, Some(m)),
94 T![while] => while_expr(p, Some(m)), 94 T![while] => while_expr(p, Some(m)),
95 T!['{'] => block_expr(p, Some(m)), 95 // test labeled_block
96 // fn f() { 'label: {}; }
97 T!['{'] => {
98 block_expr(p);
99 m.complete(p, EFFECT_EXPR)
100 }
96 _ => { 101 _ => {
97 // test_err misplaced_label_err 102 // test_err misplaced_label_err
98 // fn main() { 103 // fn main() {
@@ -108,13 +113,17 @@ pub(super) fn atom_expr(p: &mut Parser, r: Restrictions) -> Option<(CompletedMar
108 let m = p.start(); 113 let m = p.start();
109 p.bump(T![async]); 114 p.bump(T![async]);
110 p.eat(T![move]); 115 p.eat(T![move]);
111 block_expr(p, Some(m)) 116 block_expr(p);
117 m.complete(p, EFFECT_EXPR)
112 } 118 }
113 T![match] => match_expr(p), 119 T![match] => match_expr(p),
120 // test unsafe_block
121 // fn f() { unsafe { } }
114 T![unsafe] if la == T!['{'] => { 122 T![unsafe] if la == T!['{'] => {
115 let m = p.start(); 123 let m = p.start();
116 p.bump(T![unsafe]); 124 p.bump(T![unsafe]);
117 block_expr(p, Some(m)) 125 block_expr(p);
126 m.complete(p, EFFECT_EXPR)
118 } 127 }
119 T!['{'] => { 128 T!['{'] => {
120 // test for_range_from 129 // test for_range_from
@@ -123,7 +132,7 @@ pub(super) fn atom_expr(p: &mut Parser, r: Restrictions) -> Option<(CompletedMar
123 // break; 132 // break;
124 // } 133 // }
125 // } 134 // }
126 block_expr(p, None) 135 block_expr(p)
127 } 136 }
128 T![return] => return_expr(p), 137 T![return] => return_expr(p),
129 T![continue] => continue_expr(p), 138 T![continue] => continue_expr(p),
@@ -134,7 +143,7 @@ pub(super) fn atom_expr(p: &mut Parser, r: Restrictions) -> Option<(CompletedMar
134 } 143 }
135 }; 144 };
136 let blocklike = match done.kind() { 145 let blocklike = match done.kind() {
137 IF_EXPR | WHILE_EXPR | FOR_EXPR | LOOP_EXPR | MATCH_EXPR | BLOCK_EXPR | TRY_BLOCK_EXPR => { 146 IF_EXPR | WHILE_EXPR | FOR_EXPR | LOOP_EXPR | MATCH_EXPR | BLOCK_EXPR | EFFECT_EXPR => {
138 BlockLike::Block 147 BlockLike::Block
139 } 148 }
140 _ => BlockLike::NotBlock, 149 _ => BlockLike::NotBlock,
@@ -234,7 +243,7 @@ fn lambda_expr(p: &mut Parser) -> CompletedMarker {
234 if p.at(T!['{']) { 243 if p.at(T!['{']) {
235 // test lambda_ret_block 244 // test lambda_ret_block
236 // fn main() { || -> i32 { 92 }(); } 245 // fn main() { || -> i32 { 92 }(); }
237 block_expr(p, None); 246 block_expr(p);
238 } else { 247 } else {
239 p.error("expected `{`"); 248 p.error("expected `{`");
240 } 249 }
@@ -461,13 +470,13 @@ fn match_guard(p: &mut Parser) -> CompletedMarker {
461// test block_expr 470// test block_expr
462// fn foo() { 471// fn foo() {
463// {}; 472// {};
464// unsafe {};
465// 'label: {};
466// } 473// }
467pub(super) fn block_expr(p: &mut Parser, m: Option<Marker>) -> CompletedMarker { 474pub(super) fn block_expr(p: &mut Parser) -> CompletedMarker {
468 assert!(p.at(T!['{'])); 475 assert!(p.at(T!['{']));
469 let m = m.unwrap_or_else(|| p.start()); 476 let m = p.start();
470 naked_block(p); 477 p.bump(T!['{']);
478 expr_block_contents(p);
479 p.expect(T!['}']);
471 m.complete(p, BLOCK_EXPR) 480 m.complete(p, BLOCK_EXPR)
472} 481}
473 482
@@ -552,8 +561,8 @@ fn try_block_expr(p: &mut Parser, m: Option<Marker>) -> CompletedMarker {
552 } 561 }
553 562
554 p.bump(T![try]); 563 p.bump(T![try]);
555 block(p); 564 block_expr(p);
556 m.complete(p, TRY_EXPR) 565 m.complete(p, EFFECT_EXPR)
557} 566}
558 567
559// test box_expr 568// test box_expr