diff options
Diffstat (limited to 'crates/ra_parser/src/grammar')
-rw-r--r-- | crates/ra_parser/src/grammar/expressions.rs | 15 | ||||
-rw-r--r-- | crates/ra_parser/src/grammar/expressions/atom.rs | 41 | ||||
-rw-r--r-- | crates/ra_parser/src/grammar/items.rs | 2 | ||||
-rw-r--r-- | crates/ra_parser/src/grammar/type_args.rs | 2 |
4 files changed, 26 insertions, 34 deletions
diff --git a/crates/ra_parser/src/grammar/expressions.rs b/crates/ra_parser/src/grammar/expressions.rs index a23dbcacf..34f039768 100644 --- a/crates/ra_parser/src/grammar/expressions.rs +++ b/crates/ra_parser/src/grammar/expressions.rs | |||
@@ -2,7 +2,7 @@ | |||
2 | 2 | ||
3 | mod atom; | 3 | mod atom; |
4 | 4 | ||
5 | pub(crate) use self::atom::match_arm_list; | 5 | pub(crate) use self::atom::{block_expr, match_arm_list}; |
6 | pub(super) use self::atom::{literal, LITERAL_FIRST}; | 6 | pub(super) use self::atom::{literal, LITERAL_FIRST}; |
7 | use super::*; | 7 | use super::*; |
8 | 8 | ||
@@ -49,19 +49,6 @@ fn expr_no_struct(p: &mut Parser) { | |||
49 | expr_bp(p, r, 1); | 49 | expr_bp(p, r, 1); |
50 | } | 50 | } |
51 | 51 | ||
52 | // test block | ||
53 | // fn a() {} | ||
54 | // fn b() { let _ = 1; } | ||
55 | // fn c() { 1; 2; } | ||
56 | // fn d() { 1; 2 } | ||
57 | pub(crate) fn block(p: &mut Parser) { | ||
58 | if !p.at(T!['{']) { | ||
59 | p.error("expected a block"); | ||
60 | return; | ||
61 | } | ||
62 | atom::block_expr(p); | ||
63 | } | ||
64 | |||
65 | fn is_expr_stmt_attr_allowed(kind: SyntaxKind) -> bool { | 52 | fn is_expr_stmt_attr_allowed(kind: SyntaxKind) -> bool { |
66 | match kind { | 53 | match kind { |
67 | BIN_EXPR | RANGE_EXPR | IF_EXPR => false, | 54 | BIN_EXPR | RANGE_EXPR | IF_EXPR => false, |
diff --git a/crates/ra_parser/src/grammar/expressions/atom.rs b/crates/ra_parser/src/grammar/expressions/atom.rs index efb424dae..706a2f796 100644 --- a/crates/ra_parser/src/grammar/expressions/atom.rs +++ b/crates/ra_parser/src/grammar/expressions/atom.rs | |||
@@ -132,7 +132,7 @@ pub(super) fn atom_expr(p: &mut Parser, r: Restrictions) -> Option<(CompletedMar | |||
132 | // break; | 132 | // break; |
133 | // } | 133 | // } |
134 | // } | 134 | // } |
135 | block_expr(p) | 135 | block_expr_unchecked(p) |
136 | } | 136 | } |
137 | T![return] => return_expr(p), | 137 | T![return] => return_expr(p), |
138 | T![continue] => continue_expr(p), | 138 | T![continue] => continue_expr(p), |
@@ -240,13 +240,9 @@ fn lambda_expr(p: &mut Parser) -> CompletedMarker { | |||
240 | p.eat(T![move]); | 240 | p.eat(T![move]); |
241 | params::param_list_closure(p); | 241 | params::param_list_closure(p); |
242 | if opt_fn_ret_type(p) { | 242 | if opt_fn_ret_type(p) { |
243 | if p.at(T!['{']) { | 243 | // test lambda_ret_block |
244 | // test lambda_ret_block | 244 | // fn main() { || -> i32 { 92 }(); } |
245 | // fn main() { || -> i32 { 92 }(); } | 245 | block_expr(p); |
246 | block_expr(p); | ||
247 | } else { | ||
248 | p.error("expected `{`"); | ||
249 | } | ||
250 | } else { | 246 | } else { |
251 | if p.at_ts(EXPR_FIRST) { | 247 | if p.at_ts(EXPR_FIRST) { |
252 | expr(p); | 248 | expr(p); |
@@ -270,13 +266,13 @@ fn if_expr(p: &mut Parser) -> CompletedMarker { | |||
270 | let m = p.start(); | 266 | let m = p.start(); |
271 | p.bump(T![if]); | 267 | p.bump(T![if]); |
272 | cond(p); | 268 | cond(p); |
273 | block(p); | 269 | block_expr(p); |
274 | if p.at(T![else]) { | 270 | if p.at(T![else]) { |
275 | p.bump(T![else]); | 271 | p.bump(T![else]); |
276 | if p.at(T![if]) { | 272 | if p.at(T![if]) { |
277 | if_expr(p); | 273 | if_expr(p); |
278 | } else { | 274 | } else { |
279 | block(p); | 275 | block_expr(p); |
280 | } | 276 | } |
281 | } | 277 | } |
282 | m.complete(p, IF_EXPR) | 278 | m.complete(p, IF_EXPR) |
@@ -304,7 +300,7 @@ fn loop_expr(p: &mut Parser, m: Option<Marker>) -> CompletedMarker { | |||
304 | assert!(p.at(T![loop])); | 300 | assert!(p.at(T![loop])); |
305 | let m = m.unwrap_or_else(|| p.start()); | 301 | let m = m.unwrap_or_else(|| p.start()); |
306 | p.bump(T![loop]); | 302 | p.bump(T![loop]); |
307 | block(p); | 303 | block_expr(p); |
308 | m.complete(p, LOOP_EXPR) | 304 | m.complete(p, LOOP_EXPR) |
309 | } | 305 | } |
310 | 306 | ||
@@ -319,7 +315,7 @@ fn while_expr(p: &mut Parser, m: Option<Marker>) -> CompletedMarker { | |||
319 | let m = m.unwrap_or_else(|| p.start()); | 315 | let m = m.unwrap_or_else(|| p.start()); |
320 | p.bump(T![while]); | 316 | p.bump(T![while]); |
321 | cond(p); | 317 | cond(p); |
322 | block(p); | 318 | block_expr(p); |
323 | m.complete(p, WHILE_EXPR) | 319 | m.complete(p, WHILE_EXPR) |
324 | } | 320 | } |
325 | 321 | ||
@@ -334,7 +330,7 @@ fn for_expr(p: &mut Parser, m: Option<Marker>) -> CompletedMarker { | |||
334 | patterns::pattern(p); | 330 | patterns::pattern(p); |
335 | p.expect(T![in]); | 331 | p.expect(T![in]); |
336 | expr_no_struct(p); | 332 | expr_no_struct(p); |
337 | block(p); | 333 | block_expr(p); |
338 | m.complete(p, FOR_EXPR) | 334 | m.complete(p, FOR_EXPR) |
339 | } | 335 | } |
340 | 336 | ||
@@ -467,11 +463,20 @@ fn match_guard(p: &mut Parser) -> CompletedMarker { | |||
467 | m.complete(p, MATCH_GUARD) | 463 | m.complete(p, MATCH_GUARD) |
468 | } | 464 | } |
469 | 465 | ||
470 | // test block_expr | 466 | // test block |
471 | // fn foo() { | 467 | // fn a() {} |
472 | // {}; | 468 | // fn b() { let _ = 1; } |
473 | // } | 469 | // fn c() { 1; 2; } |
474 | pub(super) fn block_expr(p: &mut Parser) -> CompletedMarker { | 470 | // fn d() { 1; 2 } |
471 | pub(crate) fn block_expr(p: &mut Parser) { | ||
472 | if !p.at(T!['{']) { | ||
473 | p.error("expected a block"); | ||
474 | return; | ||
475 | } | ||
476 | block_expr_unchecked(p); | ||
477 | } | ||
478 | |||
479 | fn block_expr_unchecked(p: &mut Parser) -> CompletedMarker { | ||
475 | assert!(p.at(T!['{'])); | 480 | assert!(p.at(T!['{'])); |
476 | let m = p.start(); | 481 | let m = p.start(); |
477 | p.bump(T!['{']); | 482 | p.bump(T!['{']); |
diff --git a/crates/ra_parser/src/grammar/items.rs b/crates/ra_parser/src/grammar/items.rs index 1503a8730..67a924de5 100644 --- a/crates/ra_parser/src/grammar/items.rs +++ b/crates/ra_parser/src/grammar/items.rs | |||
@@ -329,7 +329,7 @@ fn fn_def(p: &mut Parser) { | |||
329 | if p.at(T![;]) { | 329 | if p.at(T![;]) { |
330 | p.bump(T![;]); | 330 | p.bump(T![;]); |
331 | } else { | 331 | } else { |
332 | expressions::block(p) | 332 | expressions::block_expr(p) |
333 | } | 333 | } |
334 | } | 334 | } |
335 | 335 | ||
diff --git a/crates/ra_parser/src/grammar/type_args.rs b/crates/ra_parser/src/grammar/type_args.rs index 33d9973e9..2d61f9d80 100644 --- a/crates/ra_parser/src/grammar/type_args.rs +++ b/crates/ra_parser/src/grammar/type_args.rs | |||
@@ -48,7 +48,7 @@ fn type_arg(p: &mut Parser) { | |||
48 | m.complete(p, ASSOC_TYPE_ARG); | 48 | m.complete(p, ASSOC_TYPE_ARG); |
49 | } | 49 | } |
50 | T!['{'] => { | 50 | T!['{'] => { |
51 | expressions::block(p); | 51 | expressions::block_expr(p); |
52 | m.complete(p, CONST_ARG); | 52 | m.complete(p, CONST_ARG); |
53 | } | 53 | } |
54 | k if k.is_literal() => { | 54 | k if k.is_literal() => { |