3
3
#![ feature( macro_metavar_expr) ]
4
4
5
5
fn main ( ) {
6
- macro_rules! one_nested_count_and_length {
6
+ macro_rules! one_nested_count_and_len {
7
7
( $( [ $( $l: literal ) ,* ] ) ,* ) => {
8
8
[
9
9
// outer-most repetition
10
10
$(
11
11
// inner-most repetition
12
12
$(
13
- ${ ignore( $l) } ${ index( ) } , ${ length ( ) } ,
13
+ ${ ignore( $l) } ${ index( ) } , ${ len ( ) } ,
14
14
) *
15
- ${ count( $l) } , ${ index( ) } , ${ length ( ) } ,
15
+ ${ count( $l) } , ${ index( ) } , ${ len ( ) } ,
16
16
) *
17
17
${ count( $l) } ,
18
18
]
19
19
} ;
20
20
}
21
21
assert_eq ! (
22
- one_nested_count_and_length !( [ "foo" ] , [ "bar" , "baz" ] ) ,
22
+ one_nested_count_and_len !( [ "foo" ] , [ "bar" , "baz" ] ) ,
23
23
[
24
24
// # ["foo"]
25
25
26
26
// ## inner-most repetition (first iteration)
27
27
//
28
28
// `index` is 0 because this is the first inner-most iteration.
29
- // `length ` is 1 because there is only one inner-most repetition, "foo".
29
+ // `len ` is 1 because there is only one inner-most repetition, "foo".
30
30
0 , 1 ,
31
-
32
31
// ## outer-most repetition (first iteration)
33
32
//
34
33
// `count` is 1 because of "foo", i,e, `$l` has only one repetition,
35
34
// `index` is 0 because this is the first outer-most iteration.
36
- // `length ` is 2 because there are 2 outer-most repetitions, ["foo"] and ["bar", "baz"]
35
+ // `len ` is 2 because there are 2 outer-most repetitions, ["foo"] and ["bar", "baz"]
37
36
1 , 0 , 2 ,
38
-
39
37
// # ["bar", "baz"]
40
38
41
39
// ## inner-most repetition (first iteration)
42
40
//
43
41
// `index` is 0 because this is the first inner-most iteration
44
- // `length ` is 2 because there are repetitions, "bar" and "baz"
42
+ // `len ` is 2 because there are repetitions, "bar" and "baz"
45
43
0 , 2 ,
46
-
47
44
// ## inner-most repetition (second iteration)
48
45
//
49
46
// `index` is 1 because this is the second inner-most iteration
50
- // `length ` is 2 because there are repetitions, "bar" and "baz"
47
+ // `len ` is 2 because there are repetitions, "bar" and "baz"
51
48
1 , 2 ,
52
-
53
49
// ## outer-most repetition (second iteration)
54
50
//
55
51
// `count` is 2 because of "bar" and "baz", i,e, `$l` has two repetitions,
56
52
// `index` is 1 because this is the second outer-most iteration
57
- // `length ` is 2 because there are 2 outer-most repetitions, ["foo"] and ["bar", "baz"]
53
+ // `len ` is 2 because there are 2 outer-most repetitions, ["foo"] and ["bar", "baz"]
58
54
2 , 1 , 2 ,
59
-
60
55
// # last count
61
56
62
57
// Because there are a total of 3 repetitions of `$l`, "foo", "bar" and "baz"
@@ -131,7 +126,6 @@ fn main() {
131
126
& [ 2 ] [ ..] ,
132
127
// t u v w x y z
133
128
& [ 7 ] [ ..] ,
134
-
135
129
// (a b c) (d e f)
136
130
& [ 6 , 2 ] [ ..] ,
137
131
// (g h) (i j k l m)
@@ -142,15 +136,13 @@ fn main() {
142
136
& [ 5 , 3 ] [ ..] ,
143
137
// (t u v w x y z)
144
138
& [ 7 , 1 ] [ ..] ,
145
-
146
139
// [ (a b c) (d e f) ]
147
140
// [ (g h) (i j k l m) ]
148
141
// [ (n) ]
149
142
& [ 14 , 5 , 3 ] [ ..] ,
150
143
// [ (o) (p q) (r s) ]
151
144
// [ (t u v w x y z) ]
152
145
& [ 12 , 4 , 2 ] [ ..] ,
153
-
154
146
// {
155
147
// [ (a b c) (d e f) ]
156
148
// [ (g h) (i j k l m) ]
@@ -165,43 +157,43 @@ fn main() {
165
157
) ;
166
158
167
159
// Grouped from the outer-most to the inner-most
168
- macro_rules! three_nested_length {
160
+ macro_rules! three_nested_len {
169
161
( $( { $( [ $( ( $( $i: ident ) * ) ) * ] ) * } ) * ) => {
170
162
& [
171
163
$( $( $( $(
172
164
& [
173
- ${ ignore( $i) } ${ length ( 3 ) } ,
174
- ${ ignore( $i) } ${ length ( 2 ) } ,
175
- ${ ignore( $i) } ${ length ( 1 ) } ,
176
- ${ ignore( $i) } ${ length ( 0 ) } ,
165
+ ${ ignore( $i) } ${ len ( 3 ) } ,
166
+ ${ ignore( $i) } ${ len ( 2 ) } ,
167
+ ${ ignore( $i) } ${ len ( 1 ) } ,
168
+ ${ ignore( $i) } ${ len ( 0 ) } ,
177
169
] [ ..] ,
178
170
) * ) * ) * ) *
179
171
180
172
$( $( $(
181
173
& [
182
- ${ ignore( $i) } ${ length ( 2 ) } ,
183
- ${ ignore( $i) } ${ length ( 1 ) } ,
184
- ${ ignore( $i) } ${ length ( 0 ) } ,
174
+ ${ ignore( $i) } ${ len ( 2 ) } ,
175
+ ${ ignore( $i) } ${ len ( 1 ) } ,
176
+ ${ ignore( $i) } ${ len ( 0 ) } ,
185
177
] [ ..] ,
186
178
) * ) * ) *
187
179
188
180
$( $(
189
181
& [
190
- ${ ignore( $i) } ${ length ( 1 ) } ,
191
- ${ ignore( $i) } ${ length ( 0 ) } ,
182
+ ${ ignore( $i) } ${ len ( 1 ) } ,
183
+ ${ ignore( $i) } ${ len ( 0 ) } ,
192
184
] [ ..] ,
193
185
) * ) *
194
186
195
187
$(
196
188
& [
197
- ${ ignore( $i) } ${ length ( 0 ) } ,
189
+ ${ ignore( $i) } ${ len ( 0 ) } ,
198
190
] [ ..] ,
199
191
) *
200
192
] [ ..]
201
193
}
202
194
}
203
195
assert_eq ! (
204
- three_nested_length !(
196
+ three_nested_len !(
205
197
{
206
198
[ ( a b c) ( d e f) ]
207
199
[ ( g h) ( i j k l m) ]
@@ -214,45 +206,64 @@ fn main() {
214
206
) ,
215
207
& [
216
208
// a b c
217
- & [ 2 , 3 , 2 , 3 ] [ ..] , & [ 2 , 3 , 2 , 3 ] [ ..] , & [ 2 , 3 , 2 , 3 ] [ ..] ,
209
+ & [ 2 , 3 , 2 , 3 ] [ ..] ,
210
+ & [ 2 , 3 , 2 , 3 ] [ ..] ,
211
+ & [ 2 , 3 , 2 , 3 ] [ ..] ,
218
212
// d e f
219
- & [ 2 , 3 , 2 , 3 ] [ ..] , & [ 2 , 3 , 2 , 3 ] [ ..] , & [ 2 , 3 , 2 , 3 ] [ ..] ,
213
+ & [ 2 , 3 , 2 , 3 ] [ ..] ,
214
+ & [ 2 , 3 , 2 , 3 ] [ ..] ,
215
+ & [ 2 , 3 , 2 , 3 ] [ ..] ,
220
216
// g h
221
- & [ 2 , 3 , 2 , 2 ] [ ..] , & [ 2 , 3 , 2 , 2 ] [ ..] ,
217
+ & [ 2 , 3 , 2 , 2 ] [ ..] ,
218
+ & [ 2 , 3 , 2 , 2 ] [ ..] ,
222
219
// i j k l m
223
- & [ 2 , 3 , 2 , 5 ] [ ..] , & [ 2 , 3 , 2 , 5 ] [ ..] , & [ 2 , 3 , 2 , 5 ] [ ..] , & [ 2 , 3 , 2 , 5 ] [ ..] ,
220
+ & [ 2 , 3 , 2 , 5 ] [ ..] ,
221
+ & [ 2 , 3 , 2 , 5 ] [ ..] ,
222
+ & [ 2 , 3 , 2 , 5 ] [ ..] ,
223
+ & [ 2 , 3 , 2 , 5 ] [ ..] ,
224
224
& [ 2 , 3 , 2 , 5 ] [ ..] ,
225
225
// n
226
226
& [ 2 , 3 , 1 , 1 ] [ ..] ,
227
227
// o
228
228
& [ 2 , 2 , 3 , 1 ] [ ..] ,
229
229
// p q
230
- & [ 2 , 2 , 3 , 2 ] [ ..] , & [ 2 , 2 , 3 , 2 ] [ ..] ,
230
+ & [ 2 , 2 , 3 , 2 ] [ ..] ,
231
+ & [ 2 , 2 , 3 , 2 ] [ ..] ,
231
232
// r s
232
- & [ 2 , 2 , 3 , 2 ] [ ..] , & [ 2 , 2 , 3 , 2 ] [ ..] ,
233
+ & [ 2 , 2 , 3 , 2 ] [ ..] ,
234
+ & [ 2 , 2 , 3 , 2 ] [ ..] ,
233
235
// t u v w x y z
234
- & [ 2 , 2 , 1 , 7 ] [ ..] , & [ 2 , 2 , 1 , 7 ] [ ..] , & [ 2 , 2 , 1 , 7 ] [ ..] , & [ 2 , 2 , 1 , 7 ] [ ..] ,
235
- & [ 2 , 2 , 1 , 7 ] [ ..] , & [ 2 , 2 , 1 , 7 ] [ ..] , & [ 2 , 2 , 1 , 7 ] [ ..] ,
236
-
236
+ & [ 2 , 2 , 1 , 7 ] [ ..] ,
237
+ & [ 2 , 2 , 1 , 7 ] [ ..] ,
238
+ & [ 2 , 2 , 1 , 7 ] [ ..] ,
239
+ & [ 2 , 2 , 1 , 7 ] [ ..] ,
240
+ & [ 2 , 2 , 1 , 7 ] [ ..] ,
241
+ & [ 2 , 2 , 1 , 7 ] [ ..] ,
242
+ & [ 2 , 2 , 1 , 7 ] [ ..] ,
237
243
// (a b c) (d e f)
238
- & [ 2 , 3 , 2 ] [ ..] , & [ 2 , 3 , 2 ] [ ..] ,
244
+ & [ 2 , 3 , 2 ] [ ..] ,
245
+ & [ 2 , 3 , 2 ] [ ..] ,
239
246
// (g h) (i j k l m)
240
- & [ 2 , 3 , 2 ] [ ..] , & [ 2 , 3 , 2 ] [ ..] ,
247
+ & [ 2 , 3 , 2 ] [ ..] ,
248
+ & [ 2 , 3 , 2 ] [ ..] ,
241
249
// (n)
242
250
& [ 2 , 3 , 1 ] [ ..] ,
243
251
// (o) (p q) (r s)
244
- & [ 2 , 2 , 3 ] [ ..] , & [ 2 , 2 , 3 ] [ ..] , & [ 2 , 2 , 3 ] [ ..] ,
252
+ & [ 2 , 2 , 3 ] [ ..] ,
253
+ & [ 2 , 2 , 3 ] [ ..] ,
254
+ & [ 2 , 2 , 3 ] [ ..] ,
245
255
// (t u v w x y z)
246
256
& [ 2 , 2 , 1 ] [ ..] ,
247
-
248
257
// [ (a b c) (d e f) ]
249
258
// [ (g h) (i j k l m) ]
250
259
// [ (n) ]
251
- & [ 2 , 3 ] [ ..] , & [ 2 , 3 ] [ ..] , & [ 2 , 3 , ] [ ..] ,
260
+ & [ 2 , 3 ] [ ..] ,
261
+ & [ 2 , 3 ] [ ..] ,
262
+ & [ 2 , 3 , ] [ ..] ,
252
263
// [ (o) (p q) (r s) ]
253
264
// [ (t u v w x y z) ]
254
- & [ 2 , 2 ] [ ..] , & [ 2 , 2 ] [ .. ] ,
255
-
265
+ & [ 2 , 2 ] [ ..] ,
266
+ & [ 2 , 2 ] [ .. ] ,
256
267
// {
257
268
// [ (a b c) (d e f) ]
258
269
// [ (g h) (i j k l m) ]
@@ -262,10 +273,11 @@ fn main() {
262
273
// [ (o) (p q) (r s) ]
263
274
// [ (t u v w x y z) ]
264
275
// }
265
- & [ 2 ] [ ..] , & [ 2 ] [ ..]
276
+ & [ 2 ] [ ..] ,
277
+ & [ 2 ] [ ..]
266
278
] [ ..]
267
279
) ;
268
280
269
- // It is possible to say, to some degree, that count is an "amalgamation" of length (see
270
- // each length line result and compare them with the count results)
281
+ // It is possible to say, to some degree, that count is an "amalgamation" of len (see
282
+ // each len line result and compare them with the count results)
271
283
}
0 commit comments