diff options
author | Aleksey Kladov <[email protected]> | 2018-09-08 07:18:42 +0100 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2018-09-08 07:18:42 +0100 |
commit | 44334f6f56bd99635f650796af0db8047e4c21c4 (patch) | |
tree | 2cee555747588449ba3cc1279b254e9b2140b83e /crates | |
parent | 127814d9a7f62c834c0893ff05e933aac4be89e9 (diff) |
fix labled expressions
Diffstat (limited to 'crates')
9 files changed, 313 insertions, 14 deletions
diff --git a/crates/libsyntax2/src/grammar/expressions/atom.rs b/crates/libsyntax2/src/grammar/expressions/atom.rs index a17c27b31..f8b50b355 100644 --- a/crates/libsyntax2/src/grammar/expressions/atom.rs +++ b/crates/libsyntax2/src/grammar/expressions/atom.rs | |||
@@ -62,16 +62,26 @@ pub(super) fn atom_expr(p: &mut Parser, r: Restrictions) -> Option<CompletedMark | |||
62 | LOOP_KW => loop_expr(p, Some(m)), | 62 | LOOP_KW => loop_expr(p, Some(m)), |
63 | FOR_KW => for_expr(p, Some(m)), | 63 | FOR_KW => for_expr(p, Some(m)), |
64 | WHILE_KW => while_expr(p, Some(m)), | 64 | WHILE_KW => while_expr(p, Some(m)), |
65 | L_CURLY => block_expr(p, Some(m)), | ||
65 | _ => { | 66 | _ => { |
67 | // test misplaced_label_err | ||
68 | // fn main() { | ||
69 | // 'loop: impl | ||
70 | // } | ||
66 | p.error("expected a loop"); | 71 | p.error("expected a loop"); |
72 | m.complete(p, ERROR); | ||
67 | return None; | 73 | return None; |
68 | } | 74 | } |
69 | } | 75 | } |
70 | } | 76 | } |
71 | 77 | ||
72 | MATCH_KW => match_expr(p), | 78 | MATCH_KW => match_expr(p), |
73 | UNSAFE_KW if la == L_CURLY => block_expr(p), | 79 | UNSAFE_KW if la == L_CURLY => { |
74 | L_CURLY => block_expr(p), | 80 | let m = p.start(); |
81 | p.bump(); | ||
82 | block_expr(p, Some(m)) | ||
83 | }, | ||
84 | L_CURLY => block_expr(p, None), | ||
75 | RETURN_KW => return_expr(p), | 85 | RETURN_KW => return_expr(p), |
76 | CONTINUE_KW => continue_expr(p), | 86 | CONTINUE_KW => continue_expr(p), |
77 | BREAK_KW => break_expr(p), | 87 | BREAK_KW => break_expr(p), |
@@ -323,11 +333,11 @@ fn match_arm(p: &mut Parser) -> BlockLike { | |||
323 | // fn foo() { | 333 | // fn foo() { |
324 | // {}; | 334 | // {}; |
325 | // unsafe {}; | 335 | // unsafe {}; |
336 | // 'label: {}; | ||
326 | // } | 337 | // } |
327 | pub(super) fn block_expr(p: &mut Parser) -> CompletedMarker { | 338 | fn block_expr(p: &mut Parser, m: Option<Marker>) -> CompletedMarker { |
328 | assert!(p.at(L_CURLY) || p.at(UNSAFE_KW) && p.nth(1) == L_CURLY); | 339 | assert!(p.at(L_CURLY)); |
329 | let m = p.start(); | 340 | let m = m.unwrap_or_else(|| p.start()); |
330 | p.eat(UNSAFE_KW); | ||
331 | block(p); | 341 | block(p); |
332 | m.complete(p, BLOCK_EXPR) | 342 | m.complete(p, BLOCK_EXPR) |
333 | } | 343 | } |
diff --git a/crates/libsyntax2/tests/data/parser/inline/0067_block_expr.rs b/crates/libsyntax2/tests/data/parser/inline/0067_block_expr.rs index ec3780a04..2fed74c5e 100644 --- a/crates/libsyntax2/tests/data/parser/inline/0067_block_expr.rs +++ b/crates/libsyntax2/tests/data/parser/inline/0067_block_expr.rs | |||
@@ -1,4 +1,5 @@ | |||
1 | fn foo() { | 1 | fn foo() { |
2 | {}; | 2 | {}; |
3 | unsafe {}; | 3 | unsafe {}; |
4 | 'label: {}; | ||
4 | } | 5 | } |
diff --git a/crates/libsyntax2/tests/data/parser/inline/0067_block_expr.txt b/crates/libsyntax2/tests/data/parser/inline/0067_block_expr.txt index 94104e746..12a1ff49a 100644 --- a/crates/libsyntax2/tests/data/parser/inline/0067_block_expr.txt +++ b/crates/libsyntax2/tests/data/parser/inline/0067_block_expr.txt | |||
@@ -1,5 +1,5 @@ | |||
1 | ROOT@[0; 36) | 1 | ROOT@[0; 52) |
2 | FN_DEF@[0; 35) | 2 | FN_DEF@[0; 51) |
3 | FN_KW@[0; 2) | 3 | FN_KW@[0; 2) |
4 | WHITESPACE@[2; 3) | 4 | WHITESPACE@[2; 3) |
5 | NAME@[3; 6) | 5 | NAME@[3; 6) |
@@ -8,7 +8,7 @@ ROOT@[0; 36) | |||
8 | L_PAREN@[6; 7) | 8 | L_PAREN@[6; 7) |
9 | R_PAREN@[7; 8) | 9 | R_PAREN@[7; 8) |
10 | WHITESPACE@[8; 9) | 10 | WHITESPACE@[8; 9) |
11 | BLOCK@[9; 35) | 11 | BLOCK@[9; 51) |
12 | L_CURLY@[9; 10) | 12 | L_CURLY@[9; 10) |
13 | WHITESPACE@[10; 15) | 13 | WHITESPACE@[10; 15) |
14 | EXPR_STMT@[15; 18) | 14 | EXPR_STMT@[15; 18) |
@@ -26,6 +26,17 @@ ROOT@[0; 36) | |||
26 | L_CURLY@[30; 31) | 26 | L_CURLY@[30; 31) |
27 | R_CURLY@[31; 32) | 27 | R_CURLY@[31; 32) |
28 | SEMI@[32; 33) | 28 | SEMI@[32; 33) |
29 | WHITESPACE@[33; 34) | 29 | WHITESPACE@[33; 38) |
30 | R_CURLY@[34; 35) | 30 | EXPR_STMT@[38; 49) |
31 | WHITESPACE@[35; 36) | 31 | BLOCK_EXPR@[38; 48) |
32 | LABEL@[38; 45) | ||
33 | LIFETIME@[38; 44) "'label" | ||
34 | COLON@[44; 45) | ||
35 | WHITESPACE@[45; 46) | ||
36 | BLOCK@[46; 48) | ||
37 | L_CURLY@[46; 47) | ||
38 | R_CURLY@[47; 48) | ||
39 | SEMI@[48; 49) | ||
40 | WHITESPACE@[49; 50) | ||
41 | R_CURLY@[50; 51) | ||
42 | WHITESPACE@[51; 52) | ||
diff --git a/crates/libsyntax2/tests/data/parser/inline/0108_misplaced_label_err.rs b/crates/libsyntax2/tests/data/parser/inline/0108_misplaced_label_err.rs new file mode 100644 index 000000000..a2164c510 --- /dev/null +++ b/crates/libsyntax2/tests/data/parser/inline/0108_misplaced_label_err.rs | |||
@@ -0,0 +1,3 @@ | |||
1 | fn main() { | ||
2 | 'loop: impl | ||
3 | } | ||
diff --git a/crates/libsyntax2/tests/data/parser/inline/0108_misplaced_label_err.txt b/crates/libsyntax2/tests/data/parser/inline/0108_misplaced_label_err.txt new file mode 100644 index 000000000..d00305b97 --- /dev/null +++ b/crates/libsyntax2/tests/data/parser/inline/0108_misplaced_label_err.txt | |||
@@ -0,0 +1,28 @@ | |||
1 | ROOT@[0; 30) | ||
2 | FN_DEF@[0; 29) | ||
3 | FN_KW@[0; 2) | ||
4 | WHITESPACE@[2; 3) | ||
5 | NAME@[3; 7) | ||
6 | IDENT@[3; 7) "main" | ||
7 | PARAM_LIST@[7; 9) | ||
8 | L_PAREN@[7; 8) | ||
9 | R_PAREN@[8; 9) | ||
10 | WHITESPACE@[9; 10) | ||
11 | BLOCK@[10; 29) | ||
12 | L_CURLY@[10; 11) | ||
13 | WHITESPACE@[11; 16) | ||
14 | EXPR_STMT@[16; 22) | ||
15 | ERROR@[16; 22) | ||
16 | LABEL@[16; 22) | ||
17 | LIFETIME@[16; 21) "'loop" | ||
18 | COLON@[21; 22) | ||
19 | err: `expected a loop` | ||
20 | err: `expected SEMI` | ||
21 | WHITESPACE@[22; 23) | ||
22 | IMPL_ITEM@[23; 27) | ||
23 | IMPL_KW@[23; 27) | ||
24 | err: `expected type` | ||
25 | err: `expected `{`` | ||
26 | WHITESPACE@[27; 28) | ||
27 | R_CURLY@[28; 29) | ||
28 | WHITESPACE@[29; 30) | ||
diff --git a/crates/libsyntax2/tests/data/parser/ok/0033_label_break.rs b/crates/libsyntax2/tests/data/parser/ok/0033_label_break.rs new file mode 100644 index 000000000..728d78137 --- /dev/null +++ b/crates/libsyntax2/tests/data/parser/ok/0033_label_break.rs | |||
@@ -0,0 +1,28 @@ | |||
1 | // format with label break value. | ||
2 | fn main() { | ||
3 | 'empty_block: {} | ||
4 | |||
5 | 'block: { | ||
6 | do_thing(); | ||
7 | if condition_not_met() { | ||
8 | break 'block; | ||
9 | } | ||
10 | do_next_thing(); | ||
11 | if condition_not_met() { | ||
12 | break 'block; | ||
13 | } | ||
14 | do_last_thing(); | ||
15 | } | ||
16 | |||
17 | let result = 'block: { | ||
18 | if foo() { | ||
19 | // comment | ||
20 | break 'block 1; | ||
21 | } | ||
22 | if bar() { | ||
23 | /* comment */ | ||
24 | break 'block 2; | ||
25 | } | ||
26 | 3 | ||
27 | }; | ||
28 | } | ||
diff --git a/crates/libsyntax2/tests/data/parser/ok/0033_label_break.txt b/crates/libsyntax2/tests/data/parser/ok/0033_label_break.txt new file mode 100644 index 000000000..6abb9234c --- /dev/null +++ b/crates/libsyntax2/tests/data/parser/ok/0033_label_break.txt | |||
@@ -0,0 +1,215 @@ | |||
1 | ROOT@[0; 506) | ||
2 | COMMENT@[0; 33) | ||
3 | WHITESPACE@[33; 34) | ||
4 | FN_DEF@[34; 505) | ||
5 | FN_KW@[34; 36) | ||
6 | WHITESPACE@[36; 37) | ||
7 | NAME@[37; 41) | ||
8 | IDENT@[37; 41) "main" | ||
9 | PARAM_LIST@[41; 43) | ||
10 | L_PAREN@[41; 42) | ||
11 | R_PAREN@[42; 43) | ||
12 | WHITESPACE@[43; 44) | ||
13 | BLOCK@[44; 505) | ||
14 | L_CURLY@[44; 45) | ||
15 | WHITESPACE@[45; 50) | ||
16 | EXPR_STMT@[50; 66) | ||
17 | BLOCK_EXPR@[50; 66) | ||
18 | LABEL@[50; 63) | ||
19 | LIFETIME@[50; 62) "'empty_block" | ||
20 | COLON@[62; 63) | ||
21 | WHITESPACE@[63; 64) | ||
22 | BLOCK@[64; 66) | ||
23 | L_CURLY@[64; 65) | ||
24 | R_CURLY@[65; 66) | ||
25 | WHITESPACE@[66; 72) | ||
26 | EXPR_STMT@[72; 295) | ||
27 | BLOCK_EXPR@[72; 295) | ||
28 | LABEL@[72; 79) | ||
29 | LIFETIME@[72; 78) "'block" | ||
30 | COLON@[78; 79) | ||
31 | WHITESPACE@[79; 80) | ||
32 | BLOCK@[80; 295) | ||
33 | L_CURLY@[80; 81) | ||
34 | WHITESPACE@[81; 90) | ||
35 | EXPR_STMT@[90; 101) | ||
36 | CALL_EXPR@[90; 100) | ||
37 | PATH_EXPR@[90; 98) | ||
38 | PATH@[90; 98) | ||
39 | PATH_SEGMENT@[90; 98) | ||
40 | NAME_REF@[90; 98) | ||
41 | IDENT@[90; 98) "do_thing" | ||
42 | ARG_LIST@[98; 100) | ||
43 | L_PAREN@[98; 99) | ||
44 | R_PAREN@[99; 100) | ||
45 | SEMI@[100; 101) | ||
46 | WHITESPACE@[101; 110) | ||
47 | EXPR_STMT@[110; 170) | ||
48 | IF_EXPR@[110; 170) | ||
49 | IF_KW@[110; 112) | ||
50 | WHITESPACE@[112; 113) | ||
51 | CONDITION@[113; 132) | ||
52 | CALL_EXPR@[113; 132) | ||
53 | PATH_EXPR@[113; 130) | ||
54 | PATH@[113; 130) | ||
55 | PATH_SEGMENT@[113; 130) | ||
56 | NAME_REF@[113; 130) | ||
57 | IDENT@[113; 130) "condition_not_met" | ||
58 | ARG_LIST@[130; 132) | ||
59 | L_PAREN@[130; 131) | ||
60 | R_PAREN@[131; 132) | ||
61 | WHITESPACE@[132; 133) | ||
62 | BLOCK@[133; 170) | ||
63 | L_CURLY@[133; 134) | ||
64 | WHITESPACE@[134; 147) | ||
65 | EXPR_STMT@[147; 160) | ||
66 | BREAK_EXPR@[147; 159) | ||
67 | BREAK_KW@[147; 152) | ||
68 | WHITESPACE@[152; 153) | ||
69 | LIFETIME@[153; 159) "'block" | ||
70 | SEMI@[159; 160) | ||
71 | WHITESPACE@[160; 169) | ||
72 | R_CURLY@[169; 170) | ||
73 | WHITESPACE@[170; 179) | ||
74 | EXPR_STMT@[179; 195) | ||
75 | CALL_EXPR@[179; 194) | ||
76 | PATH_EXPR@[179; 192) | ||
77 | PATH@[179; 192) | ||
78 | PATH_SEGMENT@[179; 192) | ||
79 | NAME_REF@[179; 192) | ||
80 | IDENT@[179; 192) "do_next_thing" | ||
81 | ARG_LIST@[192; 194) | ||
82 | L_PAREN@[192; 193) | ||
83 | R_PAREN@[193; 194) | ||
84 | SEMI@[194; 195) | ||
85 | WHITESPACE@[195; 204) | ||
86 | EXPR_STMT@[204; 264) | ||
87 | IF_EXPR@[204; 264) | ||
88 | IF_KW@[204; 206) | ||
89 | WHITESPACE@[206; 207) | ||
90 | CONDITION@[207; 226) | ||
91 | CALL_EXPR@[207; 226) | ||
92 | PATH_EXPR@[207; 224) | ||
93 | PATH@[207; 224) | ||
94 | PATH_SEGMENT@[207; 224) | ||
95 | NAME_REF@[207; 224) | ||
96 | IDENT@[207; 224) "condition_not_met" | ||
97 | ARG_LIST@[224; 226) | ||
98 | L_PAREN@[224; 225) | ||
99 | R_PAREN@[225; 226) | ||
100 | WHITESPACE@[226; 227) | ||
101 | BLOCK@[227; 264) | ||
102 | L_CURLY@[227; 228) | ||
103 | WHITESPACE@[228; 241) | ||
104 | EXPR_STMT@[241; 254) | ||
105 | BREAK_EXPR@[241; 253) | ||
106 | BREAK_KW@[241; 246) | ||
107 | WHITESPACE@[246; 247) | ||
108 | LIFETIME@[247; 253) "'block" | ||
109 | SEMI@[253; 254) | ||
110 | WHITESPACE@[254; 263) | ||
111 | R_CURLY@[263; 264) | ||
112 | WHITESPACE@[264; 273) | ||
113 | EXPR_STMT@[273; 289) | ||
114 | CALL_EXPR@[273; 288) | ||
115 | PATH_EXPR@[273; 286) | ||
116 | PATH@[273; 286) | ||
117 | PATH_SEGMENT@[273; 286) | ||
118 | NAME_REF@[273; 286) | ||
119 | IDENT@[273; 286) "do_last_thing" | ||
120 | ARG_LIST@[286; 288) | ||
121 | L_PAREN@[286; 287) | ||
122 | R_PAREN@[287; 288) | ||
123 | SEMI@[288; 289) | ||
124 | WHITESPACE@[289; 294) | ||
125 | R_CURLY@[294; 295) | ||
126 | WHITESPACE@[295; 301) | ||
127 | LET_STMT@[301; 503) | ||
128 | LET_KW@[301; 304) | ||
129 | WHITESPACE@[304; 305) | ||
130 | BIND_PAT@[305; 311) | ||
131 | NAME@[305; 311) | ||
132 | IDENT@[305; 311) "result" | ||
133 | WHITESPACE@[311; 312) | ||
134 | EQ@[312; 313) | ||
135 | WHITESPACE@[313; 314) | ||
136 | BLOCK_EXPR@[314; 502) | ||
137 | LABEL@[314; 321) | ||
138 | LIFETIME@[314; 320) "'block" | ||
139 | COLON@[320; 321) | ||
140 | WHITESPACE@[321; 322) | ||
141 | BLOCK@[322; 502) | ||
142 | L_CURLY@[322; 323) | ||
143 | WHITESPACE@[323; 332) | ||
144 | EXPR_STMT@[332; 403) | ||
145 | IF_EXPR@[332; 403) | ||
146 | IF_KW@[332; 334) | ||
147 | WHITESPACE@[334; 335) | ||
148 | CONDITION@[335; 340) | ||
149 | CALL_EXPR@[335; 340) | ||
150 | PATH_EXPR@[335; 338) | ||
151 | PATH@[335; 338) | ||
152 | PATH_SEGMENT@[335; 338) | ||
153 | NAME_REF@[335; 338) | ||
154 | IDENT@[335; 338) "foo" | ||
155 | ARG_LIST@[338; 340) | ||
156 | L_PAREN@[338; 339) | ||
157 | R_PAREN@[339; 340) | ||
158 | WHITESPACE@[340; 341) | ||
159 | BLOCK@[341; 403) | ||
160 | L_CURLY@[341; 342) | ||
161 | WHITESPACE@[342; 355) | ||
162 | COMMENT@[355; 365) | ||
163 | WHITESPACE@[365; 378) | ||
164 | EXPR_STMT@[378; 393) | ||
165 | BREAK_EXPR@[378; 392) | ||
166 | BREAK_KW@[378; 383) | ||
167 | WHITESPACE@[383; 384) | ||
168 | LIFETIME@[384; 390) "'block" | ||
169 | WHITESPACE@[390; 391) | ||
170 | LITERAL@[391; 392) | ||
171 | INT_NUMBER@[391; 392) "1" | ||
172 | SEMI@[392; 393) | ||
173 | WHITESPACE@[393; 402) | ||
174 | R_CURLY@[402; 403) | ||
175 | WHITESPACE@[403; 412) | ||
176 | EXPR_STMT@[412; 486) | ||
177 | IF_EXPR@[412; 486) | ||
178 | IF_KW@[412; 414) | ||
179 | WHITESPACE@[414; 415) | ||
180 | CONDITION@[415; 420) | ||
181 | CALL_EXPR@[415; 420) | ||
182 | PATH_EXPR@[415; 418) | ||
183 | PATH@[415; 418) | ||
184 | PATH_SEGMENT@[415; 418) | ||
185 | NAME_REF@[415; 418) | ||
186 | IDENT@[415; 418) "bar" | ||
187 | ARG_LIST@[418; 420) | ||
188 | L_PAREN@[418; 419) | ||
189 | R_PAREN@[419; 420) | ||
190 | WHITESPACE@[420; 421) | ||
191 | BLOCK@[421; 486) | ||
192 | L_CURLY@[421; 422) | ||
193 | WHITESPACE@[422; 435) | ||
194 | COMMENT@[435; 448) | ||
195 | WHITESPACE@[448; 461) | ||
196 | EXPR_STMT@[461; 476) | ||
197 | BREAK_EXPR@[461; 475) | ||
198 | BREAK_KW@[461; 466) | ||
199 | WHITESPACE@[466; 467) | ||
200 | LIFETIME@[467; 473) "'block" | ||
201 | WHITESPACE@[473; 474) | ||
202 | LITERAL@[474; 475) | ||
203 | INT_NUMBER@[474; 475) "2" | ||
204 | SEMI@[475; 476) | ||
205 | WHITESPACE@[476; 485) | ||
206 | R_CURLY@[485; 486) | ||
207 | WHITESPACE@[486; 495) | ||
208 | LITERAL@[495; 496) | ||
209 | INT_NUMBER@[495; 496) "3" | ||
210 | WHITESPACE@[496; 501) | ||
211 | R_CURLY@[501; 502) | ||
212 | SEMI@[502; 503) | ||
213 | WHITESPACE@[503; 504) | ||
214 | R_CURLY@[504; 505) | ||
215 | WHITESPACE@[505; 506) | ||
diff --git a/crates/server/src/main.rs b/crates/server/src/main.rs index baabde629..968b3b87a 100644 --- a/crates/server/src/main.rs +++ b/crates/server/src/main.rs | |||
@@ -11,7 +11,8 @@ use gen_lsp_server::{run_server, stdio_transport}; | |||
11 | use m::Result; | 11 | use m::Result; |
12 | 12 | ||
13 | fn main() -> Result<()> { | 13 | fn main() -> Result<()> { |
14 | Logger::with_env_or_str("m=error") | 14 | ::std::env::set_var("RUST_BACKTRACE", "short"); |
15 | Logger::with_env_or_str("error") | ||
15 | .duplicate_to_stderr(Duplicate::All) | 16 | .duplicate_to_stderr(Duplicate::All) |
16 | .log_to_file() | 17 | .log_to_file() |
17 | .directory("log") | 18 | .directory("log") |
diff --git a/crates/server/src/main_loop/mod.rs b/crates/server/src/main_loop/mod.rs index 52f2a8977..2ef1e2d17 100644 --- a/crates/server/src/main_loop/mod.rs +++ b/crates/server/src/main_loop/mod.rs | |||
@@ -38,7 +38,9 @@ pub fn main_loop( | |||
38 | msg_sender: &mut Sender<RawMessage>, | 38 | msg_sender: &mut Sender<RawMessage>, |
39 | ) -> Result<()> { | 39 | ) -> Result<()> { |
40 | let pool = rayon::ThreadPoolBuilder::new() | 40 | let pool = rayon::ThreadPoolBuilder::new() |
41 | .num_threads(4).build() | 41 | .num_threads(4) |
42 | .panic_handler(|_| error!("thread panicked :(")) | ||
43 | .build() | ||
42 | .unwrap(); | 44 | .unwrap(); |
43 | let (task_sender, task_receiver) = unbounded::<Task>(); | 45 | let (task_sender, task_receiver) = unbounded::<Task>(); |
44 | let (fs_sender, fs_receiver, fs_watcher) = vfs::roots_loader(); | 46 | let (fs_sender, fs_receiver, fs_watcher) = vfs::roots_loader(); |