diff options
author | Aleksey Kladov <[email protected]> | 2020-05-02 00:18:19 +0100 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2020-05-02 10:21:39 +0100 |
commit | 4f2134cc33f07c09fe166cec42971828843bc0ef (patch) | |
tree | 0e2440d51717dd0dfcefbf77e5ef546f1ee5c60d /crates/ra_parser | |
parent | 3c96de5380a09fe06752ce146edeb017ae8c701c (diff) |
Introduce EffectExpr
Diffstat (limited to 'crates/ra_parser')
-rw-r--r-- | crates/ra_parser/src/grammar.rs | 2 | ||||
-rw-r--r-- | crates/ra_parser/src/grammar/expressions.rs | 13 | ||||
-rw-r--r-- | crates/ra_parser/src/grammar/expressions/atom.rs | 29 | ||||
-rw-r--r-- | crates/ra_parser/src/syntax_kind/generated.rs | 3 |
4 files changed, 22 insertions, 25 deletions
diff --git a/crates/ra_parser/src/grammar.rs b/crates/ra_parser/src/grammar.rs index c2a6e82e9..d9824ff9b 100644 --- a/crates/ra_parser/src/grammar.rs +++ b/crates/ra_parser/src/grammar.rs | |||
@@ -143,7 +143,7 @@ pub(crate) fn reparser( | |||
143 | parent: Option<SyntaxKind>, | 143 | parent: Option<SyntaxKind>, |
144 | ) -> Option<fn(&mut Parser)> { | 144 | ) -> Option<fn(&mut Parser)> { |
145 | let res = match node { | 145 | let res = match node { |
146 | BLOCK => expressions::naked_block, | 146 | BLOCK_EXPR => expressions::block, |
147 | RECORD_FIELD_DEF_LIST => items::record_field_def_list, | 147 | RECORD_FIELD_DEF_LIST => items::record_field_def_list, |
148 | RECORD_FIELD_LIST => items::record_field_list, | 148 | RECORD_FIELD_LIST => items::record_field_list, |
149 | ENUM_VARIANT_LIST => items::enum_variant_list, | 149 | ENUM_VARIANT_LIST => items::enum_variant_list, |
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 | |||
65 | pub(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 | ||
74 | fn is_expr_stmt_attr_allowed(kind: SyntaxKind) -> bool { | 65 | fn 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 | ||
200 | pub(crate) fn expr_block_contents(p: &mut Parser) { | 191 | pub(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..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 | |||
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 | T!['{'] => { |
96 | block_expr(p); | ||
97 | m.complete(p, EFFECT_EXPR) | ||
98 | } | ||
96 | _ => { | 99 | _ => { |
97 | // test_err misplaced_label_err | 100 | // test_err misplaced_label_err |
98 | // fn main() { | 101 | // fn main() { |
@@ -108,13 +111,15 @@ pub(super) fn atom_expr(p: &mut Parser, r: Restrictions) -> Option<(CompletedMar | |||
108 | let m = p.start(); | 111 | let m = p.start(); |
109 | p.bump(T![async]); | 112 | p.bump(T![async]); |
110 | p.eat(T![move]); | 113 | p.eat(T![move]); |
111 | block_expr(p, Some(m)) | 114 | block_expr(p); |
115 | m.complete(p, EFFECT_EXPR) | ||
112 | } | 116 | } |
113 | T![match] => match_expr(p), | 117 | T![match] => match_expr(p), |
114 | T![unsafe] if la == T!['{'] => { | 118 | T![unsafe] if la == T!['{'] => { |
115 | let m = p.start(); | 119 | let m = p.start(); |
116 | p.bump(T![unsafe]); | 120 | p.bump(T![unsafe]); |
117 | block_expr(p, Some(m)) | 121 | block_expr(p); |
122 | m.complete(p, EFFECT_EXPR) | ||
118 | } | 123 | } |
119 | T!['{'] => { | 124 | T!['{'] => { |
120 | // test for_range_from | 125 | // test for_range_from |
@@ -123,7 +128,7 @@ pub(super) fn atom_expr(p: &mut Parser, r: Restrictions) -> Option<(CompletedMar | |||
123 | // break; | 128 | // break; |
124 | // } | 129 | // } |
125 | // } | 130 | // } |
126 | block_expr(p, None) | 131 | block_expr(p) |
127 | } | 132 | } |
128 | T![return] => return_expr(p), | 133 | T![return] => return_expr(p), |
129 | T![continue] => continue_expr(p), | 134 | T![continue] => continue_expr(p), |
@@ -134,7 +139,7 @@ pub(super) fn atom_expr(p: &mut Parser, r: Restrictions) -> Option<(CompletedMar | |||
134 | } | 139 | } |
135 | }; | 140 | }; |
136 | let blocklike = match done.kind() { | 141 | let blocklike = match done.kind() { |
137 | IF_EXPR | WHILE_EXPR | FOR_EXPR | LOOP_EXPR | MATCH_EXPR | BLOCK_EXPR | TRY_BLOCK_EXPR => { | 142 | IF_EXPR | WHILE_EXPR | FOR_EXPR | LOOP_EXPR | MATCH_EXPR | BLOCK_EXPR | EFFECT_EXPR => { |
138 | BlockLike::Block | 143 | BlockLike::Block |
139 | } | 144 | } |
140 | _ => BlockLike::NotBlock, | 145 | _ => BlockLike::NotBlock, |
@@ -234,7 +239,7 @@ fn lambda_expr(p: &mut Parser) -> CompletedMarker { | |||
234 | if p.at(T!['{']) { | 239 | if p.at(T!['{']) { |
235 | // test lambda_ret_block | 240 | // test lambda_ret_block |
236 | // fn main() { || -> i32 { 92 }(); } | 241 | // fn main() { || -> i32 { 92 }(); } |
237 | block_expr(p, None); | 242 | block_expr(p); |
238 | } else { | 243 | } else { |
239 | p.error("expected `{`"); | 244 | p.error("expected `{`"); |
240 | } | 245 | } |
@@ -464,10 +469,12 @@ fn match_guard(p: &mut Parser) -> CompletedMarker { | |||
464 | // unsafe {}; | 469 | // unsafe {}; |
465 | // 'label: {}; | 470 | // 'label: {}; |
466 | // } | 471 | // } |
467 | pub(super) fn block_expr(p: &mut Parser, m: Option<Marker>) -> CompletedMarker { | 472 | pub(super) fn block_expr(p: &mut Parser) -> CompletedMarker { |
468 | assert!(p.at(T!['{'])); | 473 | assert!(p.at(T!['{'])); |
469 | let m = m.unwrap_or_else(|| p.start()); | 474 | let m = p.start(); |
470 | naked_block(p); | 475 | p.bump(T!['{']); |
476 | expr_block_contents(p); | ||
477 | p.expect(T!['}']); | ||
471 | m.complete(p, BLOCK_EXPR) | 478 | m.complete(p, BLOCK_EXPR) |
472 | } | 479 | } |
473 | 480 | ||
@@ -552,8 +559,8 @@ fn try_block_expr(p: &mut Parser, m: Option<Marker>) -> CompletedMarker { | |||
552 | } | 559 | } |
553 | 560 | ||
554 | p.bump(T![try]); | 561 | p.bump(T![try]); |
555 | block(p); | 562 | block_expr(p); |
556 | m.complete(p, TRY_EXPR) | 563 | m.complete(p, EFFECT_EXPR) |
557 | } | 564 | } |
558 | 565 | ||
559 | // test box_expr | 566 | // test box_expr |
diff --git a/crates/ra_parser/src/syntax_kind/generated.rs b/crates/ra_parser/src/syntax_kind/generated.rs index 524e7d784..e7404492a 100644 --- a/crates/ra_parser/src/syntax_kind/generated.rs +++ b/crates/ra_parser/src/syntax_kind/generated.rs | |||
@@ -191,7 +191,7 @@ pub enum SyntaxKind { | |||
191 | RECORD_LIT, | 191 | RECORD_LIT, |
192 | RECORD_FIELD_LIST, | 192 | RECORD_FIELD_LIST, |
193 | RECORD_FIELD, | 193 | RECORD_FIELD, |
194 | TRY_BLOCK_EXPR, | 194 | EFFECT_EXPR, |
195 | BOX_EXPR, | 195 | BOX_EXPR, |
196 | CALL_EXPR, | 196 | CALL_EXPR, |
197 | INDEX_EXPR, | 197 | INDEX_EXPR, |
@@ -204,7 +204,6 @@ pub enum SyntaxKind { | |||
204 | PREFIX_EXPR, | 204 | PREFIX_EXPR, |
205 | RANGE_EXPR, | 205 | RANGE_EXPR, |
206 | BIN_EXPR, | 206 | BIN_EXPR, |
207 | BLOCK, | ||
208 | EXTERN_BLOCK, | 207 | EXTERN_BLOCK, |
209 | EXTERN_ITEM_LIST, | 208 | EXTERN_ITEM_LIST, |
210 | ENUM_VARIANT, | 209 | ENUM_VARIANT, |