aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_parser/src/grammar
diff options
context:
space:
mode:
authorBenjamin Coenen <[email protected]>2020-05-02 11:25:04 +0100
committerBenjamin Coenen <[email protected]>2020-05-02 11:25:04 +0100
commit0b40876b993ab30421624b831cb03b4042eb0142 (patch)
tree85abb233dd8645480d61ab857a2b46c1209b142a /crates/ra_parser/src/grammar
parenteea21738ab9e0b7438d03f7b2efc18c15cc30cf2 (diff)
parent75bc0249463b72971200e482d69dad88d4e76ae3 (diff)
Merge branch 'master' of github.com:rust-analyzer/rust-analyzer
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.rs39
2 files changed, 26 insertions, 26 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 76aa601cb..efb424dae 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
84 T![box] => box_expr(p, None), 84 T![box] => box_expr(p, None),
85 T![for] => for_expr(p, None), 85 T![for] => for_expr(p, None),
86 T![while] => while_expr(p, None), 86 T![while] => while_expr(p, None),
87 T![try] => try_expr(p, None), 87 T![try] => try_block_expr(p, None),
88 LIFETIME if la == T![:] => { 88 LIFETIME if la == T![:] => {
89 let m = p.start(); 89 let m = p.start();
90 label(p); 90 label(p);
@@ -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_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
@@ -532,7 +541,7 @@ fn break_expr(p: &mut Parser, r: Restrictions) -> CompletedMarker {
532// fn foo() { 541// fn foo() {
533// let _ = try {}; 542// let _ = try {};
534// } 543// }
535fn try_expr(p: &mut Parser, m: Option<Marker>) -> CompletedMarker { 544fn try_block_expr(p: &mut Parser, m: Option<Marker>) -> CompletedMarker {
536 assert!(p.at(T![try])); 545 assert!(p.at(T![try]));
537 let m = m.unwrap_or_else(|| p.start()); 546 let m = m.unwrap_or_else(|| p.start());
538 // Special-case `try!` as macro. 547 // Special-case `try!` as macro.
@@ -552,8 +561,8 @@ fn try_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