diff options
Diffstat (limited to 'crates')
5 files changed, 83 insertions, 61 deletions
diff --git a/crates/ra_parser/src/grammar.rs b/crates/ra_parser/src/grammar.rs index 15aab6c6f..f94702e97 100644 --- a/crates/ra_parser/src/grammar.rs +++ b/crates/ra_parser/src/grammar.rs | |||
@@ -182,21 +182,11 @@ fn name_ref(p: &mut Parser) { | |||
182 | } | 182 | } |
183 | 183 | ||
184 | fn error_block(p: &mut Parser, message: &str) { | 184 | fn error_block(p: &mut Parser, message: &str) { |
185 | go(p, Some(message)); | 185 | assert!(p.at(L_CURLY)); |
186 | fn go(p: &mut Parser, message: Option<&str>) { | 186 | let m = p.start(); |
187 | assert!(p.at(L_CURLY)); | 187 | p.error(message); |
188 | let m = p.start(); | 188 | p.bump(); |
189 | if let Some(message) = message { | 189 | expressions::expr_block_contents(p); |
190 | p.error(message); | 190 | p.eat(R_CURLY); |
191 | } | 191 | m.complete(p, ERROR); |
192 | p.bump(); | ||
193 | while !p.at(EOF) && !p.at(R_CURLY) { | ||
194 | match p.current() { | ||
195 | L_CURLY => go(p, None), | ||
196 | _ => p.bump(), | ||
197 | } | ||
198 | } | ||
199 | p.eat(R_CURLY); | ||
200 | m.complete(p, ERROR); | ||
201 | } | ||
202 | } | 192 | } |
diff --git a/crates/ra_parser/src/grammar/expressions.rs b/crates/ra_parser/src/grammar/expressions.rs index d5a4f4d7b..70c71a8e1 100644 --- a/crates/ra_parser/src/grammar/expressions.rs +++ b/crates/ra_parser/src/grammar/expressions.rs | |||
@@ -33,6 +33,12 @@ pub(crate) fn block(p: &mut Parser) { | |||
33 | } | 33 | } |
34 | let m = p.start(); | 34 | let m = p.start(); |
35 | p.bump(); | 35 | p.bump(); |
36 | expr_block_contents(p); | ||
37 | p.expect(R_CURLY); | ||
38 | m.complete(p, BLOCK); | ||
39 | } | ||
40 | |||
41 | pub(crate) fn expr_block_contents(p: &mut Parser) { | ||
36 | // This is checked by a validator | 42 | // This is checked by a validator |
37 | attributes::inner_attributes(p); | 43 | attributes::inner_attributes(p); |
38 | 44 | ||
@@ -101,8 +107,6 @@ pub(crate) fn block(p: &mut Parser) { | |||
101 | } | 107 | } |
102 | } | 108 | } |
103 | } | 109 | } |
104 | p.expect(R_CURLY); | ||
105 | m.complete(p, BLOCK); | ||
106 | 110 | ||
107 | // test let_stmt; | 111 | // test let_stmt; |
108 | // fn foo() { | 112 | // fn foo() { |
diff --git a/crates/ra_syntax/tests/data/parser/err/0008_item_block_recovery.txt b/crates/ra_syntax/tests/data/parser/err/0008_item_block_recovery.txt index de5c81f29..870c818ae 100644 --- a/crates/ra_syntax/tests/data/parser/err/0008_item_block_recovery.txt +++ b/crates/ra_syntax/tests/data/parser/err/0008_item_block_recovery.txt | |||
@@ -28,29 +28,36 @@ SOURCE_FILE@[0; 95) | |||
28 | ERROR@[20; 80) | 28 | ERROR@[20; 80) |
29 | L_CURLY@[20; 21) | 29 | L_CURLY@[20; 21) |
30 | WHITESPACE@[21; 26) | 30 | WHITESPACE@[21; 26) |
31 | IF_KW@[26; 28) | 31 | IF_EXPR@[26; 78) |
32 | WHITESPACE@[28; 29) | 32 | IF_KW@[26; 28) |
33 | TRUE_KW@[29; 33) | 33 | WHITESPACE@[28; 29) |
34 | WHITESPACE@[33; 34) | 34 | CONDITION@[29; 33) |
35 | ERROR@[34; 51) | 35 | LITERAL@[29; 33) |
36 | L_CURLY@[34; 35) | 36 | TRUE_KW@[29; 33) |
37 | WHITESPACE@[35; 44) | 37 | WHITESPACE@[33; 34) |
38 | INT_NUMBER@[44; 45) "1" | 38 | BLOCK@[34; 51) |
39 | WHITESPACE@[45; 50) | 39 | L_CURLY@[34; 35) |
40 | R_CURLY@[50; 51) | 40 | WHITESPACE@[35; 44) |
41 | WHITESPACE@[51; 52) | 41 | LITERAL@[44; 45) |
42 | ELSE_KW@[52; 56) | 42 | INT_NUMBER@[44; 45) "1" |
43 | WHITESPACE@[56; 57) | 43 | WHITESPACE@[45; 50) |
44 | ERROR@[57; 78) | 44 | R_CURLY@[50; 51) |
45 | L_CURLY@[57; 58) | 45 | WHITESPACE@[51; 52) |
46 | WHITESPACE@[58; 67) | 46 | ELSE_KW@[52; 56) |
47 | INT_NUMBER@[67; 68) "2" | 47 | WHITESPACE@[56; 57) |
48 | WHITESPACE@[68; 69) | 48 | BLOCK@[57; 78) |
49 | PLUS@[69; 70) | 49 | L_CURLY@[57; 58) |
50 | WHITESPACE@[70; 71) | 50 | WHITESPACE@[58; 67) |
51 | INT_NUMBER@[71; 72) "3" | 51 | BIN_EXPR@[67; 72) |
52 | WHITESPACE@[72; 77) | 52 | LITERAL@[67; 68) |
53 | R_CURLY@[77; 78) | 53 | INT_NUMBER@[67; 68) "2" |
54 | WHITESPACE@[68; 69) | ||
55 | PLUS@[69; 70) | ||
56 | WHITESPACE@[70; 71) | ||
57 | LITERAL@[71; 72) | ||
58 | INT_NUMBER@[71; 72) "3" | ||
59 | WHITESPACE@[72; 77) | ||
60 | R_CURLY@[77; 78) | ||
54 | WHITESPACE@[78; 79) | 61 | WHITESPACE@[78; 79) |
55 | R_CURLY@[79; 80) | 62 | R_CURLY@[79; 80) |
56 | WHITESPACE@[80; 82) | 63 | WHITESPACE@[80; 82) |
diff --git a/crates/ra_syntax/tests/data/parser/err/0009_broken_struct_type_parameter.txt b/crates/ra_syntax/tests/data/parser/err/0009_broken_struct_type_parameter.txt index e22c061d2..26c5d395c 100644 --- a/crates/ra_syntax/tests/data/parser/err/0009_broken_struct_type_parameter.txt +++ b/crates/ra_syntax/tests/data/parser/err/0009_broken_struct_type_parameter.txt | |||
@@ -28,10 +28,24 @@ SOURCE_FILE@[0; 43) | |||
28 | ERROR@[17; 31) | 28 | ERROR@[17; 31) |
29 | L_CURLY@[17; 18) | 29 | L_CURLY@[17; 18) |
30 | WHITESPACE@[18; 23) | 30 | WHITESPACE@[18; 23) |
31 | IDENT@[23; 24) "f" | 31 | EXPR_STMT@[23; 24) |
32 | COLON@[24; 25) | 32 | PATH_EXPR@[23; 24) |
33 | PATH@[23; 24) | ||
34 | PATH_SEGMENT@[23; 24) | ||
35 | NAME_REF@[23; 24) | ||
36 | IDENT@[23; 24) "f" | ||
37 | err: `expected SEMI` | ||
38 | err: `expected expression` | ||
39 | EXPR_STMT@[24; 25) | ||
40 | ERROR@[24; 25) | ||
41 | COLON@[24; 25) | ||
42 | err: `expected SEMI` | ||
33 | WHITESPACE@[25; 26) | 43 | WHITESPACE@[25; 26) |
34 | IDENT@[26; 29) "u32" | 44 | PATH_EXPR@[26; 29) |
45 | PATH@[26; 29) | ||
46 | PATH_SEGMENT@[26; 29) | ||
47 | NAME_REF@[26; 29) | ||
48 | IDENT@[26; 29) "u32" | ||
35 | WHITESPACE@[29; 30) | 49 | WHITESPACE@[29; 30) |
36 | R_CURLY@[30; 31) | 50 | R_CURLY@[30; 31) |
37 | WHITESPACE@[31; 33) | 51 | WHITESPACE@[31; 33) |
diff --git a/crates/ra_syntax/tests/data/parser/err/0028_macro_2.0.txt b/crates/ra_syntax/tests/data/parser/err/0028_macro_2.0.txt index 440bd7f92..181ccfa25 100644 --- a/crates/ra_syntax/tests/data/parser/err/0028_macro_2.0.txt +++ b/crates/ra_syntax/tests/data/parser/err/0028_macro_2.0.txt | |||
@@ -34,22 +34,29 @@ SOURCE_FILE@[0; 349) | |||
34 | ERROR@[42; 93) | 34 | ERROR@[42; 93) |
35 | L_CURLY@[42; 43) | 35 | L_CURLY@[42; 43) |
36 | WHITESPACE@[43; 48) | 36 | WHITESPACE@[43; 48) |
37 | IDENT@[48; 51) "vec" | 37 | MACRO_CALL@[48; 91) |
38 | EXCL@[51; 52) | 38 | PATH@[48; 51) |
39 | L_BRACK@[52; 53) | 39 | PATH_SEGMENT@[48; 51) |
40 | WHITESPACE@[53; 62) | 40 | NAME_REF@[48; 51) |
41 | DOLLAR@[62; 63) | 41 | IDENT@[48; 51) "vec" |
42 | L_PAREN@[63; 64) | 42 | EXCL@[51; 52) |
43 | IDENT@[64; 78) "parse_use_tree" | 43 | TOKEN_TREE@[52; 91) |
44 | L_PAREN@[78; 79) | 44 | L_BRACK@[52; 53) |
45 | DOLLAR@[79; 80) | 45 | WHITESPACE@[53; 62) |
46 | IDENT@[80; 81) "s" | 46 | DOLLAR@[62; 63) |
47 | R_PAREN@[81; 82) | 47 | TOKEN_TREE@[63; 84) |
48 | COMMA@[82; 83) | 48 | L_PAREN@[63; 64) |
49 | R_PAREN@[83; 84) | 49 | IDENT@[64; 78) "parse_use_tree" |
50 | STAR@[84; 85) | 50 | TOKEN_TREE@[78; 82) |
51 | WHITESPACE@[85; 90) | 51 | L_PAREN@[78; 79) |
52 | R_BRACK@[90; 91) | 52 | DOLLAR@[79; 80) |
53 | IDENT@[80; 81) "s" | ||
54 | R_PAREN@[81; 82) | ||
55 | COMMA@[82; 83) | ||
56 | R_PAREN@[83; 84) | ||
57 | STAR@[84; 85) | ||
58 | WHITESPACE@[85; 90) | ||
59 | R_BRACK@[90; 91) | ||
53 | WHITESPACE@[91; 92) | 60 | WHITESPACE@[91; 92) |
54 | R_CURLY@[92; 93) | 61 | R_CURLY@[92; 93) |
55 | WHITESPACE@[93; 95) | 62 | WHITESPACE@[93; 95) |