5
5
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
6
6
*/
7
7
8
- use proc_macro2:: { Ident , TokenStream } ;
8
+ use proc_macro2:: { Ident , Span , TokenStream } ;
9
9
use quote:: quote;
10
10
use std:: collections:: { HashMap , HashSet } ;
11
11
12
12
use crate :: util:: { KvParser , ListParser } ;
13
13
use crate :: ParseResult ;
14
14
15
+ pub struct FieldExport {
16
+ pub export_type : ExportType ,
17
+ pub span : Span ,
18
+ }
19
+
20
+ impl FieldExport {
21
+ pub ( crate ) fn new_from_kv ( parser : & mut KvParser ) -> ParseResult < Self > {
22
+ let span = parser. span ( ) ;
23
+ let export_type = ExportType :: new_from_kv ( parser) ?;
24
+ Ok ( Self { export_type, span } )
25
+ }
26
+
27
+ pub fn to_export_hint ( & self ) -> Option < TokenStream > {
28
+ self . export_type . to_export_hint ( )
29
+ }
30
+ }
31
+
15
32
/// Store info from `#[export]` attribute.
16
- pub enum FieldExport {
33
+ pub enum ExportType {
17
34
/// ### GDScript annotations
18
35
/// - `@export`
19
36
///
@@ -121,7 +138,7 @@ pub enum FieldExport {
121
138
ColorNoAlpha ,
122
139
}
123
140
124
- impl FieldExport {
141
+ impl ExportType {
125
142
/// Parse an `#[export(...)]` attribute.
126
143
///
127
144
/// The translation from GDScript annotations to rust attributes is given by:
@@ -253,10 +270,10 @@ impl FieldExport {
253
270
return Ok ( Self :: ColorNoAlpha ) ;
254
271
}
255
272
256
- Ok ( FieldExport :: Default )
273
+ Ok ( Self :: Default )
257
274
}
258
275
259
- fn new_range_list ( mut parser : ListParser ) -> ParseResult < FieldExport > {
276
+ fn new_range_list ( mut parser : ListParser ) -> ParseResult < Self > {
260
277
const FLAG_OPTIONS : [ & str ; 7 ] = [
261
278
"or_greater" ,
262
279
"or_less" ,
@@ -299,7 +316,7 @@ impl FieldExport {
299
316
300
317
parser. finish ( ) ?;
301
318
302
- Ok ( FieldExport :: Range {
319
+ Ok ( Self :: Range {
303
320
min,
304
321
max,
305
322
step,
@@ -374,12 +391,12 @@ macro_rules! quote_export_func {
374
391
}
375
392
}
376
393
377
- impl FieldExport {
394
+ impl ExportType {
378
395
pub fn to_export_hint ( & self ) -> Option < TokenStream > {
379
396
match self {
380
- FieldExport :: Default => None ,
397
+ Self :: Default => None ,
381
398
382
- FieldExport :: Range {
399
+ Self :: Range {
383
400
min,
384
401
max,
385
402
step,
@@ -416,70 +433,70 @@ impl FieldExport {
416
433
} )
417
434
}
418
435
419
- FieldExport :: Enum { variants } => {
436
+ Self :: Enum { variants } => {
420
437
let variants = variants. iter ( ) . map ( ValueWithKey :: to_tuple_expression) ;
421
438
422
439
quote_export_func ! {
423
440
export_enum( & [ #( #variants) , * ] )
424
441
}
425
442
}
426
443
427
- FieldExport :: ExpEasing {
444
+ Self :: ExpEasing {
428
445
attenuation,
429
446
positive_only,
430
447
} => quote_export_func ! {
431
448
export_exp_easing( #attenuation, #positive_only)
432
449
} ,
433
450
434
- FieldExport :: Flags { bits } => {
451
+ Self :: Flags { bits } => {
435
452
let bits = bits. iter ( ) . map ( ValueWithKey :: to_tuple_expression) ;
436
453
437
454
quote_export_func ! {
438
455
export_flags( & [ #( #bits) , * ] )
439
456
}
440
457
}
441
458
442
- FieldExport :: Layers {
459
+ Self :: Layers {
443
460
dimension : LayerDimension :: _2d,
444
461
kind : LayerKind :: Physics ,
445
462
} => quote_export_func ! { export_flags_2d_physics( ) } ,
446
463
447
- FieldExport :: Layers {
464
+ Self :: Layers {
448
465
dimension : LayerDimension :: _2d,
449
466
kind : LayerKind :: Render ,
450
467
} => quote_export_func ! { export_flags_2d_render( ) } ,
451
468
452
- FieldExport :: Layers {
469
+ Self :: Layers {
453
470
dimension : LayerDimension :: _2d,
454
471
kind : LayerKind :: Navigation ,
455
472
} => quote_export_func ! { export_flags_2d_navigation( ) } ,
456
473
457
- FieldExport :: Layers {
474
+ Self :: Layers {
458
475
dimension : LayerDimension :: _3d,
459
476
kind : LayerKind :: Physics ,
460
477
} => quote_export_func ! { export_flags_3d_physics( ) } ,
461
478
462
- FieldExport :: Layers {
479
+ Self :: Layers {
463
480
dimension : LayerDimension :: _3d,
464
481
kind : LayerKind :: Render ,
465
482
} => quote_export_func ! { export_flags_3d_render( ) } ,
466
483
467
- FieldExport :: Layers {
484
+ Self :: Layers {
468
485
dimension : LayerDimension :: _3d,
469
486
kind : LayerKind :: Navigation ,
470
487
} => quote_export_func ! { export_flags_3d_navigation( ) } ,
471
488
472
- FieldExport :: File {
489
+ Self :: File {
473
490
global : false ,
474
491
kind : FileKind :: Dir ,
475
492
} => quote_export_func ! { export_dir( ) } ,
476
493
477
- FieldExport :: File {
494
+ Self :: File {
478
495
global : true ,
479
496
kind : FileKind :: Dir ,
480
497
} => quote_export_func ! { export_global_dir( ) } ,
481
498
482
- FieldExport :: File {
499
+ Self :: File {
483
500
global,
484
501
kind : FileKind :: File { filter } ,
485
502
} => {
@@ -488,12 +505,12 @@ impl FieldExport {
488
505
quote_export_func ! { export_file_inner( #global, #filter) }
489
506
}
490
507
491
- FieldExport :: Multiline => quote_export_func ! { export_multiline( ) } ,
508
+ Self :: Multiline => quote_export_func ! { export_multiline( ) } ,
492
509
493
- FieldExport :: PlaceholderText { placeholder } => quote_export_func ! {
510
+ Self :: PlaceholderText { placeholder } => quote_export_func ! {
494
511
export_placeholder( #placeholder)
495
512
} ,
496
- FieldExport :: ColorNoAlpha => quote_export_func ! { export_color_no_alpha( ) } ,
513
+ Self :: ColorNoAlpha => quote_export_func ! { export_color_no_alpha( ) } ,
497
514
}
498
515
}
499
516
}
0 commit comments