@@ -9,25 +9,21 @@ import rustc::syntax::ast;
9
9
import rustc:: front:: attr;
10
10
import core:: tuple;
11
11
12
- export crate_attrs, mod_attrs, fn_attrs, arg_attrs,
13
- const_attrs, enum_attrs, variant_attrs, res_attrs,
14
- iface_attrs, method_attrs, impl_attrs, type_attrs;
15
- export parse_crate, parse_mod, parse_fn, parse_const,
16
- parse_enum, parse_variant, parse_res,
17
- parse_iface, parse_method, parse_impl, parse_type;
12
+ export crate_attrs, basic_attrs, fn_attrs, arg_attrs,
13
+ variant_attrs, res_attrs, method_attrs;
14
+ export parse_crate, parse_basic, parse_fn,
15
+ parse_variant, parse_res, parse_method;
18
16
19
17
type crate_attrs = {
20
18
name : option < str >
21
19
} ;
22
20
23
- type mod_attrs = {
21
+ type basic_attrs = {
24
22
brief : option < str > ,
25
23
desc : option < str >
26
24
} ;
27
25
28
26
type fn_attrs = {
29
- brief : option < str > ,
30
- desc : option < str > ,
31
27
args : [ arg_attrs ] ,
32
28
return : option < str > ,
33
29
failure : option < str >
@@ -38,43 +34,16 @@ type arg_attrs = {
38
34
desc : str
39
35
} ;
40
36
41
- type const_attrs = {
42
- brief : option < str > ,
43
- desc : option < str >
44
- } ;
45
-
46
- type enum_attrs = {
47
- brief : option < str > ,
48
- desc : option < str >
49
- } ;
50
-
51
37
type variant_attrs = {
52
38
desc : option < str >
53
39
} ;
54
40
55
41
type res_attrs = {
56
- brief : option < str > ,
57
- desc : option < str > ,
58
42
args : [ arg_attrs ]
59
43
} ;
60
44
61
- type iface_attrs = {
62
- brief : option < str > ,
63
- desc : option < str >
64
- } ;
65
-
66
- type impl_attrs = {
67
- brief : option < str > ,
68
- desc : option < str >
69
- } ;
70
-
71
45
type method_attrs = fn_attrs ;
72
46
73
- type type_attrs = {
74
- brief : option < str > ,
75
- desc : option < str >
76
- } ;
77
-
78
47
#[ cfg( test) ]
79
48
mod test {
80
49
@@ -174,40 +143,36 @@ fn parse_basic(
174
143
)
175
144
}
176
145
177
- fn parse_mod ( attrs : [ ast:: attribute ] ) -> mod_attrs {
178
- parse_basic ( attrs)
179
- }
180
-
181
146
#[ test]
182
- fn parse_mod_should_handle_undocumented_mods ( ) {
147
+ fn parse_basic_should_handle_undocumented_mods ( ) {
183
148
let source = "" ;
184
149
let attrs = test:: parse_attributes ( source) ;
185
- let attrs = parse_mod ( attrs) ;
150
+ let attrs = parse_basic ( attrs) ;
186
151
assert attrs. brief == none;
187
152
assert attrs. desc == none;
188
153
}
189
154
190
155
#[ test]
191
- fn parse_mod_should_parse_simple_doc_attributes ( ) {
156
+ fn parse_basic_should_parse_simple_doc_attributes ( ) {
192
157
let source = "#[doc = \" basic\" ]" ;
193
158
let attrs = test:: parse_attributes ( source) ;
194
- let attrs = parse_mod ( attrs) ;
159
+ let attrs = parse_basic ( attrs) ;
195
160
assert attrs. desc == some ( "basic" ) ;
196
161
}
197
162
198
163
#[ test]
199
- fn parse_mod_should_parse_the_brief_description ( ) {
164
+ fn parse_basic_should_parse_the_brief_description ( ) {
200
165
let source = "#[doc(brief = \" short\" )]" ;
201
166
let attrs = test:: parse_attributes ( source) ;
202
- let attrs = parse_mod ( attrs) ;
167
+ let attrs = parse_basic ( attrs) ;
203
168
assert attrs. brief == some ( "short" ) ;
204
169
}
205
170
206
171
#[ test]
207
- fn parse_mod_should_parse_the_long_description ( ) {
172
+ fn parse_basic_should_parse_the_long_description ( ) {
208
173
let source = "#[doc(desc = \" description\" )]" ;
209
174
let attrs = test:: parse_attributes ( source) ;
210
- let attrs = parse_mod ( attrs) ;
175
+ let attrs = parse_basic ( attrs) ;
211
176
assert attrs. desc == some ( "description" ) ;
212
177
}
213
178
@@ -246,37 +211,35 @@ fn parse_short_doc_or<T>(
246
211
}
247
212
}
248
213
249
- fn parse_fn (
250
- attrs : [ ast:: attribute ]
251
- ) -> fn_attrs {
214
+ fn parse_long_doc < T > (
215
+ attrs : [ ast:: attribute ] ,
216
+ parse_long : fn & ( doc_items : [ @ast:: meta_item ] ) -> T
217
+ ) -> T {
218
+ alt doc_meta ( attrs) {
219
+ some ( meta) {
220
+ alt attr:: get_meta_item_list ( meta) {
221
+ some ( list) {
222
+ parse_long ( list)
223
+ }
224
+ none {
225
+ parse_long( [ ] )
226
+ }
227
+ }
228
+ }
229
+ none { parse_long( [ ] ) }
230
+ }
231
+ }
252
232
253
- parse_short_doc_or (
254
- attrs,
255
- { |desc|
256
- {
257
- brief: none,
258
- desc: desc,
259
- args: [ ] ,
260
- return : none,
261
- failure: none
262
- }
263
- } ,
264
- parse_fn_long_doc
265
- )
233
+ fn parse_fn ( attrs : [ ast:: attribute ] ) -> fn_attrs {
234
+ parse_long_doc ( attrs, parse_fn_long_doc)
266
235
}
267
236
268
- fn parse_fn_long_doc (
269
- items : [ @ast:: meta_item ] ,
270
- brief : option < str > ,
271
- desc : option < str >
272
- ) -> fn_attrs {
237
+ fn parse_fn_long_doc ( items : [ @ast:: meta_item ] ) -> fn_attrs {
273
238
let return = attr:: meta_item_value_from_list ( items, "return" ) ;
274
239
let failure = attr:: meta_item_value_from_list ( items, "failure" ) ;
275
240
let args = parse_args ( items) ;
276
241
277
242
{
278
- brief: brief,
279
- desc: desc,
280
243
args: args,
281
244
return : return ,
282
245
failure: failure
@@ -304,36 +267,10 @@ fn parse_fn_should_handle_undocumented_functions() {
304
267
let source = "" ;
305
268
let attrs = test:: parse_attributes ( source) ;
306
269
let attrs = parse_fn ( attrs) ;
307
- assert attrs. brief == none;
308
- assert attrs. desc == none;
309
270
assert attrs. return == none;
310
271
assert vec:: len ( attrs. args ) == 0 u;
311
272
}
312
273
313
- #[ test]
314
- fn parse_fn_should_parse_simple_doc_attributes ( ) {
315
- let source = "#[doc = \" basic\" ]" ;
316
- let attrs = test:: parse_attributes ( source) ;
317
- let attrs = parse_fn ( attrs) ;
318
- assert attrs. desc == some ( "basic" ) ;
319
- }
320
-
321
- #[ test]
322
- fn parse_fn_should_parse_the_brief_description ( ) {
323
- let source = "#[doc(brief = \" short\" )]" ;
324
- let attrs = test:: parse_attributes ( source) ;
325
- let attrs = parse_fn ( attrs) ;
326
- assert attrs. brief == some ( "short" ) ;
327
- }
328
-
329
- #[ test]
330
- fn parse_fn_should_parse_the_long_description ( ) {
331
- let source = "#[doc(desc = \" description\" )]" ;
332
- let attrs = test:: parse_attributes ( source) ;
333
- let attrs = parse_fn ( attrs) ;
334
- assert attrs. desc == some ( "description" ) ;
335
- }
336
-
337
274
#[ test]
338
275
fn parse_fn_should_parse_the_return_value_description ( ) {
339
276
let source = "#[doc(return = \" return value\" )]" ;
@@ -359,48 +296,6 @@ fn parse_fn_should_parse_failure_conditions() {
359
296
assert attrs.failure == some(" it' s the fail") ;
360
297
}
361
298
362
- fn parse_const ( attrs : [ ast:: attribute ] ) -> const_attrs {
363
- parse_basic ( attrs)
364
- }
365
-
366
- #[ test]
367
- fn should_parse_const_short_doc ( ) {
368
- let source = "#[doc = \" description\" ]" ;
369
- let attrs = test:: parse_attributes ( source) ;
370
- let attrs = parse_const ( attrs) ;
371
- assert attrs. desc == some ( "description" ) ;
372
- }
373
-
374
- #[ test]
375
- fn should_parse_const_long_doc ( ) {
376
- let source = "#[doc(brief = \" a\" , desc = \" b\" )]" ;
377
- let attrs = test:: parse_attributes ( source) ;
378
- let attrs = parse_const ( attrs) ;
379
- assert attrs. brief == some ( "a" ) ;
380
- assert attrs. desc == some ( "b" ) ;
381
- }
382
-
383
- fn parse_enum ( attrs : [ ast:: attribute ] ) -> enum_attrs {
384
- parse_basic ( attrs)
385
- }
386
-
387
- #[ test]
388
- fn should_parse_enum_short_doc ( ) {
389
- let source = "#[doc = \" description\" ]" ;
390
- let attrs = test:: parse_attributes ( source) ;
391
- let attrs = parse_enum ( attrs) ;
392
- assert attrs. desc == some ( "description" ) ;
393
- }
394
-
395
- #[ test]
396
- fn should_parse_enum_long_doc ( ) {
397
- let source = "#[doc(brief = \" a\" , desc = \" b\" )]" ;
398
- let attrs = test:: parse_attributes ( source) ;
399
- let attrs = parse_enum ( attrs) ;
400
- assert attrs. brief == some ( "a" ) ;
401
- assert attrs. desc == some ( "b" ) ;
402
- }
403
-
404
299
fn parse_variant ( attrs : [ ast:: attribute ] ) -> variant_attrs {
405
300
parse_short_doc_or (
406
301
attrs,
@@ -446,52 +341,16 @@ fn should_parse_variant_long_doc() {
446
341
assert attrs. desc == some ( "a" ) ;
447
342
}
448
343
449
- fn parse_res (
450
- attrs : [ ast:: attribute ]
451
- ) -> res_attrs {
452
-
453
- parse_short_doc_or (
454
- attrs,
455
- { |desc|
456
- {
457
- brief: none,
458
- desc: desc,
459
- args: [ ]
460
- }
461
- } ,
462
- parse_res_long_doc
463
- )
344
+ fn parse_res ( attrs : [ ast:: attribute ] ) -> res_attrs {
345
+ parse_long_doc ( attrs, parse_res_long_doc)
464
346
}
465
347
466
- fn parse_res_long_doc (
467
- items : [ @ast:: meta_item ] ,
468
- brief : option < str > ,
469
- desc : option < str >
470
- ) -> res_attrs {
348
+ fn parse_res_long_doc ( items : [ @ast:: meta_item ] ) -> res_attrs {
471
349
{
472
- brief: brief,
473
- desc: desc,
474
350
args: parse_args ( items)
475
351
}
476
352
}
477
353
478
- #[ test]
479
- fn should_parse_resource_short_desc ( ) {
480
- let source = "#[doc = \" a\" ]" ;
481
- let attrs = test:: parse_attributes ( source) ;
482
- let attrs = parse_res ( attrs) ;
483
- assert attrs. desc == some ( "a" ) ;
484
- }
485
-
486
- #[ test]
487
- fn should_parse_resource_long_desc ( ) {
488
- let source = "#[doc(brief = \" a\" , desc = \" b\" )]" ;
489
- let attrs = test:: parse_attributes ( source) ;
490
- let attrs = parse_res ( attrs) ;
491
- assert attrs. brief == some ( "a" ) ;
492
- assert attrs. desc == some ( "b" ) ;
493
- }
494
-
495
354
#[ test]
496
355
fn shoulde_parse_resource_arg ( ) {
497
356
let source = "#[doc(args(a = \" b\" ))]" ;
@@ -501,18 +360,6 @@ fn shoulde_parse_resource_arg() {
501
360
assert attrs. args [ 0 ] . desc == "b" ;
502
361
}
503
362
504
- fn parse_iface ( attrs : [ ast:: attribute ] ) -> iface_attrs {
505
- parse_basic ( attrs)
506
- }
507
-
508
363
fn parse_method ( attrs : [ ast:: attribute ] ) -> method_attrs {
509
364
parse_fn ( attrs)
510
365
}
511
-
512
- fn parse_impl ( attrs : [ ast:: attribute ] ) -> impl_attrs {
513
- parse_basic ( attrs)
514
- }
515
-
516
- fn parse_type ( attrs : [ ast:: attribute ] ) -> type_attrs {
517
- parse_basic ( attrs)
518
- }
0 commit comments