|
1 | 1 | #[macro_export]
|
2 | 2 | macro_rules! error_chain {
|
3 | 3 | (
|
4 |
| - $( @processed )* |
| 4 | + @processed |
| 5 | + types {} |
| 6 | + links $b:tt |
| 7 | + foreign_links $c:tt |
| 8 | + errors $d:tt |
| 9 | + ) => { |
| 10 | + error_chain! { |
| 11 | + @processed |
| 12 | + types { |
| 13 | + Error, ErrorKind, Result; |
| 14 | + } |
| 15 | + links $b |
| 16 | + foreign_links $c |
| 17 | + errors $d |
| 18 | + } |
| 19 | + }; |
| 20 | + ( |
| 21 | + @processed |
5 | 22 | types {
|
6 | 23 | $error_name:ident, $error_kind_name:ident, $result_name:ident;
|
7 | 24 | }
|
@@ -196,119 +213,12 @@ macro_rules! error_chain {
|
196 | 213 | /// Convenient wrapper around `std::Result`.
|
197 | 214 | pub type $result_name<T> = ::std::result::Result<T, $error_name>;
|
198 | 215 | };
|
199 |
| - |
200 |
| - // Handle missing sections, or missing type names in types { } |
201 |
| - // |
202 |
| - // Macros cannot specify "zero or one repetitions" at the moment, so we allow |
203 |
| - // repeating sections. Only for the `types` section this makes no sense, which |
204 |
| - // is the reason for the three separate cases. |
205 |
| - // |
206 |
| - // Case 1: types fully specified |
207 |
| - ( |
208 |
| - $( @processed )* |
209 |
| - types { |
210 |
| - $error_name:ident, $error_kind_name:ident, $result_name:ident; |
211 |
| - } |
212 |
| - |
213 |
| - $( links { |
214 |
| - $( $link_chunks:tt ) * |
215 |
| - } ) * |
216 |
| - |
217 |
| - $( foreign_links { |
218 |
| - $( $foreign_link_chunks:tt ) * |
219 |
| - } ) * |
220 |
| - |
221 |
| - $( errors { |
222 |
| - $( $error_chunks:tt ) * |
223 |
| - } ) * |
224 |
| - ) => ( |
225 |
| - error_chain! { |
226 |
| - @processed |
227 |
| - types { |
228 |
| - $error_name, $error_kind_name, $result_name; |
229 |
| - } |
230 |
| - |
231 |
| - links { |
232 |
| - $( $( $link_chunks ) * ) * |
233 |
| - } |
234 |
| - |
235 |
| - foreign_links { |
236 |
| - $( $( $foreign_link_chunks ) * ) * |
237 |
| - } |
238 |
| - |
239 |
| - errors { |
240 |
| - $( $( $error_chunks ) * ) * |
241 |
| - } |
242 |
| - } |
243 |
| - ); |
244 |
| - // Case 2: types section present, but empty |
245 |
| - ( |
246 |
| - $( @processed )* |
247 |
| - types { } |
248 |
| - |
249 |
| - $( links { |
250 |
| - $( $link_chunks:tt ) * |
251 |
| - } ) * |
252 |
| - |
253 |
| - $( foreign_links { |
254 |
| - $( $foreign_link_chunks:tt ) * |
255 |
| - } ) * |
256 |
| - |
257 |
| - $( errors { |
258 |
| - $( $error_chunks:tt ) * |
259 |
| - } ) * |
260 |
| - ) => ( |
261 |
| - error_chain! { |
262 |
| - @processed |
263 |
| - types { |
264 |
| - Error, ErrorKind, Result; |
265 |
| - } |
266 |
| - |
267 |
| - links { |
268 |
| - $( $( $link_chunks ) * ) * |
269 |
| - } |
270 |
| - |
271 |
| - foreign_links { |
272 |
| - $( $( $foreign_link_chunks ) * ) * |
273 |
| - } |
274 |
| - |
275 |
| - errors { |
276 |
| - $( $( $error_chunks ) * ) * |
277 |
| - } |
278 |
| - } |
279 |
| - ); |
280 |
| - // Case 3: types section not present |
281 | 216 | (
|
282 |
| - $( @processed )* |
283 |
| - $( links { |
284 |
| - $( $link_chunks:tt ) * |
285 |
| - } ) * |
286 |
| - |
287 |
| - $( foreign_links { |
288 |
| - $( $foreign_link_chunks:tt ) * |
289 |
| - } ) * |
290 |
| - |
291 |
| - $( errors { |
292 |
| - $( $error_chunks:tt ) * |
293 |
| - } ) * |
294 |
| - ) => ( |
295 |
| - error_chain! { |
296 |
| - @processed |
297 |
| - types { } |
298 |
| - |
299 |
| - links { |
300 |
| - $( $( $link_chunks ) * ) * |
301 |
| - } |
302 |
| - |
303 |
| - foreign_links { |
304 |
| - $( $( $foreign_link_chunks ) * ) * |
305 |
| - } |
306 |
| - |
307 |
| - errors { |
308 |
| - $( $( $error_chunks ) * ) * |
309 |
| - } |
310 |
| - } |
311 |
| - ); |
| 217 | + @processed |
| 218 | + $( $block_name:ident $block_content:tt )* |
| 219 | + ) => { |
| 220 | + !!!!!parse error!!!!! |
| 221 | + }; |
312 | 222 | (
|
313 | 223 | @processing ($a:tt, $b:tt, $c:tt, $d:tt)
|
314 | 224 | types $content:tt
|
@@ -360,18 +270,12 @@ macro_rules! error_chain {
|
360 | 270 | errors $d
|
361 | 271 | }
|
362 | 272 | };
|
363 |
| - ( |
364 |
| - @processed |
365 |
| - $( $block_name:ident $block_content:tt )* |
366 |
| - ) => { |
367 |
| - !!!!!parse error!!!!! |
368 |
| - }; |
369 | 273 | (
|
370 | 274 | $( $block_name:ident $block_content:tt )*
|
371 | 275 | ) => {
|
372 | 276 | error_chain! {
|
373 | 277 | @processing ({}, {}, {}, {})
|
374 |
| - $($block_name $block_content)+ |
| 278 | + $($block_name $block_content)* |
375 | 279 | }
|
376 | 280 | };
|
377 | 281 | }
|
|
0 commit comments