|
1 | 1 | #[macro_export] |
2 | | -macro_rules! error_chain { |
| 2 | +macro_rules! error_chain_processed { |
| 3 | + // Default values for `types`. |
3 | 4 | ( |
4 | | - @processed |
5 | 5 | types {} |
6 | | - links $b:tt |
7 | | - foreign_links $c:tt |
8 | | - errors $d:tt |
| 6 | + $( $rest: tt )* |
9 | 7 | ) => { |
10 | | - error_chain! { |
11 | | - @processed |
| 8 | + error_chain_processed! { |
12 | 9 | types { |
13 | 10 | Error, ErrorKind, Result; |
14 | 11 | } |
15 | | - links $b |
16 | | - foreign_links $c |
17 | | - errors $d |
| 12 | + $( $rest )* |
18 | 13 | } |
19 | 14 | }; |
20 | 15 | ( |
21 | | - @processed |
22 | 16 | types { |
23 | 17 | $error_name:ident, $error_kind_name:ident, $result_name:ident; |
24 | 18 | } |
@@ -213,69 +207,70 @@ macro_rules! error_chain { |
213 | 207 | /// Convenient wrapper around `std::Result`. |
214 | 208 | pub type $result_name<T> = ::std::result::Result<T, $error_name>; |
215 | 209 | }; |
| 210 | +} |
| 211 | + |
| 212 | +/// Internal macro used for reordering of the fields. |
| 213 | +#[doc(hidden)] |
| 214 | +#[macro_export] |
| 215 | +macro_rules! error_chain_processing { |
216 | 216 | ( |
217 | | - @processed |
218 | | - $( $block_name:ident $block_content:tt )* |
219 | | - ) => { |
220 | | - !!!!!parse error!!!!! |
221 | | - }; |
222 | | - ( |
223 | | - @processing ($a:tt, $b:tt, $c:tt, $d:tt) |
| 217 | + ($a:tt, $b:tt, $c:tt, $d:tt) |
224 | 218 | types $content:tt |
225 | 219 | $( $tail:tt )* |
226 | 220 | ) => { |
227 | | - error_chain! { |
228 | | - @processing ($content, $b, $c, $d) |
| 221 | + error_chain_processing! { |
| 222 | + ($content, $b, $c, $d) |
229 | 223 | $($tail)* |
230 | 224 | } |
231 | 225 | }; |
232 | 226 | ( |
233 | | - @processing ($a:tt, $b:tt, $c:tt, $d:tt) |
| 227 | + ($a:tt, $b:tt, $c:tt, $d:tt) |
234 | 228 | links $content:tt |
235 | 229 | $( $tail:tt )* |
236 | 230 | ) => { |
237 | | - error_chain! { |
238 | | - @processing ($a, $content, $c, $d) |
| 231 | + error_chain_processing! { |
| 232 | + ($a, $content, $c, $d) |
239 | 233 | $($tail)* |
240 | 234 | } |
241 | 235 | }; |
242 | 236 | ( |
243 | | - @processing ($a:tt, $b:tt, $c:tt, $d:tt) |
| 237 | + ($a:tt, $b:tt, $c:tt, $d:tt) |
244 | 238 | foreign_links $content:tt |
245 | 239 | $( $tail:tt )* |
246 | 240 | ) => { |
247 | | - error_chain! { |
248 | | - @processing ($a, $b, $content, $d) |
| 241 | + error_chain_processing! { |
| 242 | + ($a, $b, $content, $d) |
249 | 243 | $($tail)* |
250 | 244 | } |
251 | 245 | }; |
252 | 246 | ( |
253 | | - @processing ($a:tt, $b:tt, $c:tt, $d:tt) |
| 247 | + ($a:tt, $b:tt, $c:tt, $d:tt) |
254 | 248 | errors $content:tt |
255 | 249 | $( $tail:tt )* |
256 | 250 | ) => { |
257 | | - error_chain! { |
258 | | - @processing ($a, $b, $c, $content) |
| 251 | + error_chain_processing! { |
| 252 | + ($a, $b, $c, $content) |
259 | 253 | $($tail)* |
260 | 254 | } |
261 | 255 | }; |
262 | | - ( |
263 | | - @processing ($a:tt, $b:tt, $c:tt, $d:tt) |
264 | | - ) => { |
265 | | - error_chain! { |
266 | | - @processed |
| 256 | + ( ($a:tt, $b:tt, $c:tt, $d:tt) ) => { |
| 257 | + error_chain_processed! { |
267 | 258 | types $a |
268 | 259 | links $b |
269 | 260 | foreign_links $c |
270 | 261 | errors $d |
271 | 262 | } |
272 | 263 | }; |
273 | | - ( |
274 | | - $( $block_name:ident $block_content:tt )* |
275 | | - ) => { |
276 | | - error_chain! { |
277 | | - @processing ({}, {}, {}, {}) |
278 | | - $($block_name $block_content)* |
| 264 | +} |
| 265 | + |
| 266 | +/// This macro is used for handling of duplicated and out-of-order fields. For |
| 267 | +/// the exact rules, see `error_chain_processed`. |
| 268 | +#[macro_export] |
| 269 | +macro_rules! error_chain { |
| 270 | + ( $( $block_name:ident { $( $block_content:tt )* } )* ) => { |
| 271 | + error_chain_processing! { |
| 272 | + ({}, {}, {}, {}) |
| 273 | + $($block_name { $( $block_content )* })* |
279 | 274 | } |
280 | 275 | }; |
281 | 276 | } |
|
0 commit comments