@@ -286,13 +286,6 @@ def customized_type_info(self, type_name):
286
286
def has_user_data (self , typ ):
287
287
return self .type_info [typ ].has_user_data
288
288
289
- def apply_generics (self , typ , * generics ):
290
- needs_generics = not self .type_info [typ ].is_simple
291
- if needs_generics :
292
- return [f"<{ g } >" for g in generics ]
293
- else :
294
- return ["" for g in generics ]
295
-
296
289
297
290
class EmitVisitor (asdl .VisitorBase , TypeInfoMixin ):
298
291
"""Visit that emits lines"""
@@ -393,37 +386,33 @@ def emit_attrs(self, depth):
393
386
self .emit ("#[derive(Clone, Debug, PartialEq)]" , depth )
394
387
395
388
def emit_range (self , has_attributes , depth ):
396
- if has_attributes :
397
- self .emit ("pub range: R," , depth + 1 )
398
- else :
399
- self .emit ("pub range: OptionalRange<R>," , depth + 1 )
389
+ self .emit ("pub range: TextRange," , depth + 1 )
400
390
401
391
def visitModule (self , mod ):
402
392
self .emit_attrs (0 )
403
393
self .emit (
404
394
"""
405
395
#[derive(is_macro::Is)]
406
- pub enum Ast<R=TextRange> {
396
+ pub enum Ast {
407
397
""" ,
408
398
0 ,
409
399
)
410
400
for dfn in mod .dfns :
411
401
info = self .customized_type_info (dfn .name )
412
402
dfn = info .custom
413
403
rust_name = info .full_type_name
414
- generics = "" if self .type_info [dfn .name ].is_simple else "<R>"
415
404
if dfn .name == "mod" :
416
405
# This is exceptional rule to other enums.
417
406
# Unlike other enums, this is justified because `Mod` is only used as
418
407
# the top node of parsing result and never a child node of other nodes.
419
408
# Because it will be very rarely used in very particular applications,
420
409
# "ast_" prefix to everywhere seems less useful.
421
410
self .emit ('#[is(name = "module")]' , 1 )
422
- self .emit (f"{ rust_name } ({ rust_name } { generics } )," , 1 )
411
+ self .emit (f"{ rust_name } ({ rust_name } )," , 1 )
423
412
self .emit (
424
413
"""
425
414
}
426
- impl<R> Node for Ast<R> {
415
+ impl Node for Ast {
427
416
const NAME: &'static str = "AST";
428
417
const FIELD_NAMES: &'static [&'static str] = &[];
429
418
}
@@ -433,11 +422,10 @@ def visitModule(self, mod):
433
422
for dfn in mod .dfns :
434
423
info = self .customized_type_info (dfn .name )
435
424
rust_name = info .full_type_name
436
- generics = "" if self .type_info [dfn .name ].is_simple else "<R>"
437
425
self .emit (
438
426
f"""
439
- impl<R> From<{ rust_name } { generics } > for Ast<R> {{
440
- fn from(node: { rust_name } { generics } ) -> Self {{
427
+ impl From<{ rust_name } > for Ast {{
428
+ fn from(node: { rust_name } ) -> Self {{
441
429
Ast::{ rust_name } (node)
442
430
}}
443
431
}}
@@ -462,10 +450,9 @@ def visitSum(self, sum, type, depth):
462
450
else :
463
451
self .sum_with_constructors (sum , type , depth )
464
452
465
- (generics_applied ,) = self .apply_generics (type .name , "R" )
466
453
self .emit (
467
454
f"""
468
- impl{ generics_applied } Node for { rust_type_name (type .name )} { generics_applied } {{
455
+ impl Node for { rust_type_name (type .name )} {{
469
456
const NAME: &'static str = "{ type .name } ";
470
457
const FIELD_NAMES: &'static [&'static str] = &[];
471
458
}}
@@ -512,7 +499,7 @@ def simple_sum(self, sum, type, depth):
512
499
{ rust_name } ::{ cons .name }
513
500
}}
514
501
}}
515
- impl<R> From<{ rust_name } { cons .name } > for Ast<R> {{
502
+ impl From<{ rust_name } { cons .name } > for Ast {{
516
503
fn from(_: { rust_name } { cons .name } ) -> Self {{
517
504
{ rust_name } ::{ cons .name } .into()
518
505
}}
@@ -537,15 +524,15 @@ def sum_with_constructors(self, sum, type, depth):
537
524
538
525
self .emit_attrs (depth )
539
526
self .emit ("#[derive(is_macro::Is)]" , depth )
540
- self .emit (f"pub enum { rust_name } <R = TextRange> {{" , depth )
527
+ self .emit (f"pub enum { rust_name } {{" , depth )
541
528
needs_escape = any (rust_field_name (t .name ) in RUST_KEYWORDS for t in sum .types )
542
529
for t in sum .types :
543
530
if needs_escape :
544
531
self .emit (
545
532
f'#[is(name = "{ rust_field_name (t .name )} _{ rust_name .lower ()} ")]' ,
546
533
depth + 1 ,
547
534
)
548
- self .emit (f"{ t .name } ({ rust_name } { t .name } <R> )," , depth + 1 )
535
+ self .emit (f"{ t .name } ({ rust_name } { t .name } )," , depth + 1 )
549
536
self .emit ("}" , depth )
550
537
self .emit ("" , depth )
551
538
@@ -559,7 +546,7 @@ def sum_subtype_struct(self, sum_type_info, t, rust_name, depth):
559
546
)
560
547
self .emit_attrs (depth )
561
548
payload_name = f"{ rust_name } { t .name } "
562
- self .emit (f"pub struct { payload_name } <R = TextRange> {{" , depth )
549
+ self .emit (f"pub struct { payload_name } {{" , depth )
563
550
self .emit_range (sum_type_info .has_attributes , depth )
564
551
for f in t .fields :
565
552
self .visit (f , sum_type_info , "pub " , depth + 1 , t .name )
@@ -572,17 +559,17 @@ def sum_subtype_struct(self, sum_type_info, t, rust_name, depth):
572
559
field_names = [f'"{ f .name } "' for f in t .fields ]
573
560
self .emit (
574
561
f"""
575
- impl<R> Node for { payload_name } <R> {{
562
+ impl Node for { payload_name } {{
576
563
const NAME: &'static str = "{ t .name } ";
577
564
const FIELD_NAMES: &'static [&'static str] = &[{ ', ' .join (field_names )} ];
578
565
}}
579
- impl<R> From<{ payload_name } <R>> for { rust_name } <R> {{
580
- fn from(payload: { payload_name } <R> ) -> Self {{
566
+ impl From<{ payload_name } > for { rust_name } {{
567
+ fn from(payload: { payload_name } ) -> Self {{
581
568
{ rust_name } ::{ t .name } (payload)
582
569
}}
583
570
}}
584
- impl<R> From<{ payload_name } <R>> for Ast<R> {{
585
- fn from(payload: { payload_name } <R> ) -> Self {{
571
+ impl From<{ payload_name } > for Ast {{
572
+ fn from(payload: { payload_name } ) -> Self {{
586
573
{ rust_name } ::from(payload).into()
587
574
}}
588
575
}}
@@ -609,7 +596,7 @@ def visitField(self, field, parent, vis, depth, constructor=None):
609
596
field_type = None
610
597
typ = rust_type_name (field .type )
611
598
if field_type and not field_type .is_simple :
612
- typ = f"{ typ } <R> "
599
+ typ = f"{ typ } "
613
600
# don't box if we're doing Vec<T>, but do box if we're doing Vec<Option<Box<T>>>
614
601
if (
615
602
field_type
@@ -642,7 +629,7 @@ def visitProduct(self, product, type, depth):
642
629
type_info = self .type_info [type .name ]
643
630
product_name = type_info .full_type_name
644
631
self .emit_attrs (depth )
645
- self .emit (f"pub struct { product_name } <R = TextRange> {{" , depth )
632
+ self .emit (f"pub struct { product_name } {{" , depth )
646
633
self .emit_range (product .attributes , depth + 1 )
647
634
for f in product .fields :
648
635
self .visit (f , type_info , "pub " , depth + 1 )
@@ -652,7 +639,7 @@ def visitProduct(self, product, type, depth):
652
639
field_names = [f'"{ f .name } "' for f in product .fields ]
653
640
self .emit (
654
641
f"""
655
- impl<R> Node for { product_name } <R> {{
642
+ impl Node for { product_name } {{
656
643
const NAME: &'static str = "{ type .name } ";
657
644
const FIELD_NAMES: &'static [&'static str] = &[
658
645
{ ', ' .join (field_names )}
@@ -692,8 +679,6 @@ def visitSum(self, sum, name, depth):
692
679
self .emit_type_alias (variant_info )
693
680
self .emit_ranged_impl (variant_info )
694
681
695
- if not info .no_cfg (self .type_info ):
696
- self .emit ('#[cfg(feature = "all-nodes-with-ranges")]' , 0 )
697
682
698
683
self .emit (
699
684
f"""
@@ -716,21 +701,16 @@ def visitProduct(self, product, name, depth):
716
701
717
702
def emit_type_alias (self , info ):
718
703
return # disable
719
- generics = "" if info .is_simple else "::<TextRange>"
720
-
721
704
self .emit (
722
- f"pub type { info .full_type_name } = crate::generic::{ info .full_type_name } { generics } ;" ,
705
+ f"pub type { info .full_type_name } = crate::generic::{ info .full_type_name } ;" ,
723
706
0 ,
724
707
)
725
708
self .emit ("" , 0 )
726
709
727
710
def emit_ranged_impl (self , info ):
728
- if not info .no_cfg (self .type_info ):
729
- self .emit ('#[cfg(feature = "all-nodes-with-ranges")]' , 0 )
730
-
731
711
self .file .write (
732
712
f"""
733
- impl Ranged for crate::generic::{ info .full_type_name } ::<TextRange> {{
713
+ impl Ranged for crate::generic::{ info .full_type_name } {{
734
714
fn range(&self) -> TextRange {{
735
715
self.range
736
716
}}
0 commit comments