diff options
Diffstat (limited to 'crates')
-rw-r--r-- | crates/ra_parser/src/grammar.rs | 4 | ||||
-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 | ||||
-rw-r--r-- | crates/ra_parser/src/lib.rs | 2 | ||||
-rw-r--r-- | crates/ra_syntax/test_data/parser/err/0010_unsafe_lambda_block.rast | 2 | ||||
-rw-r--r-- | crates/ra_syntax/test_data/parser/err/0163_weird_blocks.rast | 71 | ||||
-rw-r--r-- | crates/ra_syntax/test_data/parser/err/0163_weird_blocks.rs | 6 | ||||
-rw-r--r-- | crates/ra_syntax/test_data/parser/inline/ok/0105_block_expr.rast | 21 | ||||
-rw-r--r-- | crates/ra_syntax/test_data/parser/inline/ok/0105_block_expr.rs | 3 |
11 files changed, 107 insertions, 62 deletions
diff --git a/crates/ra_parser/src/grammar.rs b/crates/ra_parser/src/grammar.rs index d9824ff9b..be0cd5661 100644 --- a/crates/ra_parser/src/grammar.rs +++ b/crates/ra_parser/src/grammar.rs | |||
@@ -54,7 +54,7 @@ pub(crate) mod fragments { | |||
54 | use super::*; | 54 | use super::*; |
55 | 55 | ||
56 | pub(crate) use super::{ | 56 | pub(crate) use super::{ |
57 | expressions::block, paths::type_path as path, patterns::pattern, types::type_, | 57 | expressions::block_expr, paths::type_path as path, patterns::pattern, types::type_, |
58 | }; | 58 | }; |
59 | 59 | ||
60 | pub(crate) fn expr(p: &mut Parser) { | 60 | pub(crate) fn expr(p: &mut Parser) { |
@@ -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_EXPR => expressions::block, | 146 | BLOCK_EXPR => expressions::block_expr, |
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 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() => { |
diff --git a/crates/ra_parser/src/lib.rs b/crates/ra_parser/src/lib.rs index 652492c1e..e08ad4dae 100644 --- a/crates/ra_parser/src/lib.rs +++ b/crates/ra_parser/src/lib.rs | |||
@@ -112,7 +112,7 @@ pub fn parse_fragment( | |||
112 | FragmentKind::Type => grammar::fragments::type_, | 112 | FragmentKind::Type => grammar::fragments::type_, |
113 | FragmentKind::Pattern => grammar::fragments::pattern, | 113 | FragmentKind::Pattern => grammar::fragments::pattern, |
114 | FragmentKind::Item => grammar::fragments::item, | 114 | FragmentKind::Item => grammar::fragments::item, |
115 | FragmentKind::Block => grammar::fragments::block, | 115 | FragmentKind::Block => grammar::fragments::block_expr, |
116 | FragmentKind::Visibility => grammar::fragments::opt_visibility, | 116 | FragmentKind::Visibility => grammar::fragments::opt_visibility, |
117 | FragmentKind::MetaItem => grammar::fragments::meta_item, | 117 | FragmentKind::MetaItem => grammar::fragments::meta_item, |
118 | FragmentKind::Statement => grammar::fragments::stmt, | 118 | FragmentKind::Statement => grammar::fragments::stmt, |
diff --git a/crates/ra_syntax/test_data/parser/err/0010_unsafe_lambda_block.rast b/crates/ra_syntax/test_data/parser/err/0010_unsafe_lambda_block.rast index 06a326d26..3bf57eacc 100644 --- a/crates/ra_syntax/test_data/parser/err/0010_unsafe_lambda_block.rast +++ b/crates/ra_syntax/test_data/parser/err/0010_unsafe_lambda_block.rast | |||
@@ -40,5 +40,5 @@ [email protected] | |||
40 | [email protected] "\n" | 40 | [email protected] "\n" |
41 | [email protected] "}" | 41 | [email protected] "}" |
42 | [email protected] "\n" | 42 | [email protected] "\n" |
43 | error 24..24: expected `{` | 43 | error 24..24: expected a block |
44 | error 24..24: expected SEMICOLON | 44 | error 24..24: expected SEMICOLON |
diff --git a/crates/ra_syntax/test_data/parser/err/0163_weird_blocks.rast b/crates/ra_syntax/test_data/parser/err/0163_weird_blocks.rast new file mode 100644 index 000000000..e46456384 --- /dev/null +++ b/crates/ra_syntax/test_data/parser/err/0163_weird_blocks.rast | |||
@@ -0,0 +1,71 @@ | |||
1 | [email protected] | ||
2 | [email protected] | ||
3 | [email protected] "fn" | ||
4 | [email protected] " " | ||
5 | [email protected] | ||
6 | [email protected] "main" | ||
7 | [email protected] | ||
8 | [email protected] "(" | ||
9 | [email protected] ")" | ||
10 | [email protected] " " | ||
11 | [email protected] | ||
12 | [email protected] "{" | ||
13 | [email protected] "\n " | ||
14 | [email protected] | ||
15 | [email protected] | ||
16 | [email protected] "{" | ||
17 | [email protected] " " | ||
18 | [email protected] | ||
19 | [email protected] "unsafe" | ||
20 | [email protected] " " | ||
21 | [email protected] | ||
22 | [email protected] "92" | ||
23 | [email protected] " " | ||
24 | [email protected] "}" | ||
25 | [email protected] "\n " | ||
26 | [email protected] | ||
27 | [email protected] | ||
28 | [email protected] "{" | ||
29 | [email protected] " " | ||
30 | [email protected] | ||
31 | [email protected] "async" | ||
32 | [email protected] " " | ||
33 | [email protected] | ||
34 | [email protected] "92" | ||
35 | [email protected] " " | ||
36 | [email protected] "}" | ||
37 | [email protected] "\n " | ||
38 | [email protected] | ||
39 | [email protected] | ||
40 | [email protected] "{" | ||
41 | [email protected] " " | ||
42 | [email protected] | ||
43 | [email protected] | ||
44 | [email protected] "try" | ||
45 | [email protected] " " | ||
46 | [email protected] | ||
47 | [email protected] "92" | ||
48 | [email protected] " " | ||
49 | [email protected] "}" | ||
50 | [email protected] "\n " | ||
51 | [email protected] | ||
52 | [email protected] "{" | ||
53 | [email protected] " " | ||
54 | [email protected] | ||
55 | [email protected] | ||
56 | [email protected] | ||
57 | [email protected] "\'label" | ||
58 | [email protected] ":" | ||
59 | [email protected] " " | ||
60 | [email protected] | ||
61 | [email protected] "92" | ||
62 | [email protected] " " | ||
63 | [email protected] "}" | ||
64 | [email protected] "\n" | ||
65 | [email protected] "}" | ||
66 | [email protected] "\n" | ||
67 | error 24..24: expected existential, fn, trait or impl | ||
68 | error 41..41: expected existential, fn, trait or impl | ||
69 | error 56..56: expected a block | ||
70 | error 75..75: expected a loop | ||
71 | error 75..75: expected SEMICOLON | ||
diff --git a/crates/ra_syntax/test_data/parser/err/0163_weird_blocks.rs b/crates/ra_syntax/test_data/parser/err/0163_weird_blocks.rs new file mode 100644 index 000000000..8fa324c1a --- /dev/null +++ b/crates/ra_syntax/test_data/parser/err/0163_weird_blocks.rs | |||
@@ -0,0 +1,6 @@ | |||
1 | fn main() { | ||
2 | { unsafe 92 } | ||
3 | { async 92 } | ||
4 | { try 92 } | ||
5 | { 'label: 92 } | ||
6 | } | ||
diff --git a/crates/ra_syntax/test_data/parser/inline/ok/0105_block_expr.rast b/crates/ra_syntax/test_data/parser/inline/ok/0105_block_expr.rast deleted file mode 100644 index f3a5e3096..000000000 --- a/crates/ra_syntax/test_data/parser/inline/ok/0105_block_expr.rast +++ /dev/null | |||
@@ -1,21 +0,0 @@ | |||
1 | [email protected] | ||
2 | [email protected] | ||
3 | [email protected] "fn" | ||
4 | [email protected] " " | ||
5 | [email protected] | ||
6 | [email protected] "foo" | ||
7 | [email protected] | ||
8 | [email protected] "(" | ||
9 | [email protected] ")" | ||
10 | [email protected] " " | ||
11 | [email protected] | ||
12 | [email protected] "{" | ||
13 | [email protected] "\n " | ||
14 | [email protected] | ||
15 | [email protected] | ||
16 | [email protected] "{" | ||
17 | [email protected] "}" | ||
18 | [email protected] ";" | ||
19 | [email protected] "\n" | ||
20 | [email protected] "}" | ||
21 | [email protected] "\n" | ||
diff --git a/crates/ra_syntax/test_data/parser/inline/ok/0105_block_expr.rs b/crates/ra_syntax/test_data/parser/inline/ok/0105_block_expr.rs deleted file mode 100644 index 9c6019fb1..000000000 --- a/crates/ra_syntax/test_data/parser/inline/ok/0105_block_expr.rs +++ /dev/null | |||
@@ -1,3 +0,0 @@ | |||
1 | fn foo() { | ||
2 | {}; | ||
3 | } | ||