@@ -529,13 +529,15 @@ class NonAnyType(Production): # PrimitiveType [TypeSuffix] | "ByteString" [Typ
529
529
# "USVString" TypeSuffix |
530
530
# identifier [TypeSuffix] | "sequence" "<" Type ">" [Null] | "object" [TypeSuffix] |
531
531
# "Date" [TypeSuffix] | "RegExp" [TypeSuffix] | "Error" TypeSuffix |
532
- # "DOMException" TypeSuffix | "Promise" "<" ReturnType ">" [Null] | BufferRelatedType [Nulls]
533
- # "FrozenArray" "<" Type ">" [Null]
532
+ # "DOMException" TypeSuffix | "Promise" "<" ReturnType ">" [Null] | BufferRelatedType [Nulls] |
533
+ # "FrozenArray" "<" Type ">" [Null] | "record" "<" StringType "," Type ">"
534
534
535
535
BufferRelatedTypes = frozenset (['ArrayBuffer' , 'DataView' , 'Int8Array' , 'Int16Array' , 'Int32Array' ,
536
536
'Uint8Array' , 'Uint16Array' , 'Uint32Array' , 'Uint8ClampedArray' ,
537
537
'Float32Array' , 'Float64Array' ])
538
538
539
+ StringTypes = frozenset (['ByteString' , 'DOMString' , 'USVString' ])
540
+
539
541
@classmethod
540
542
def peek (cls , tokens ):
541
543
if (PrimitiveType .peek (tokens )):
@@ -560,12 +562,21 @@ def peek(cls, tokens):
560
562
elif (token and token .isSymbol (cls .BufferRelatedTypes )):
561
563
Symbol .peek (tokens , '?' )
562
564
return tokens .popPosition (True )
565
+ elif (token and token .isSymbol ('record' )):
566
+ if (Symbol .peek (tokens , '<' )):
567
+ if (Symbol .peek (tokens , cls .StringTypes )):
568
+ if (Symbol .peek (tokens , ',' )):
569
+ if (Type .peek (tokens )):
570
+ if (Symbol .peek (tokens , '>' )):
571
+ Symbol .peek (tokens , '?' )
572
+ return tokens .popPosition (True )
563
573
return tokens .popPosition (False )
564
574
565
575
def __init__ (self , tokens ):
566
576
Production .__init__ (self , tokens )
567
577
self .sequence = None
568
578
self .promise = None
579
+ self .record = None
569
580
self ._openType = None
570
581
self ._closeType = None
571
582
self .null = False
@@ -595,6 +606,14 @@ def __init__(self, tokens):
595
606
elif (token .isSymbol (self .BufferRelatedTypes )):
596
607
self .type = Symbol (tokens , None , False )
597
608
self .null = Symbol (tokens , '?' , False ) if (Symbol .peek (tokens , '?' )) else None
609
+ elif (token .isSymbol ('record' )):
610
+ self .record = Symbol (tokens )
611
+ self ._openType = Symbol (tokens , '<' )
612
+ self .keyType = Symbol (tokens )
613
+ self ._comma = Symbol (tokens , ',' )
614
+ self .type = Type (tokens )
615
+ self ._closeType = Symbol (tokens , '>' , False )
616
+ self .null = Symbol (tokens , '?' , False ) if (Symbol .peek (tokens , '?' )) else None
598
617
else :
599
618
self .type = Symbol (tokens , None , False ) # "ByteString" | "DOMString" | "USVString" | "object" | "Date" | "RegExp"
600
619
self .suffix = TypeSuffix (tokens ) if (TypeSuffix .peek (tokens )) else None
@@ -607,6 +626,10 @@ def _unicode(self):
607
626
if (self .promise ):
608
627
output = unicode (self .promise ) + unicode (self ._openType ) + unicode (self .type ) + unicode (self ._closeType )
609
628
return output + (unicode (self .null ) if (self .null ) else '' )
629
+ if (self .record ):
630
+ output = unicode (self .record ) + unicode (self ._openType ) + unicode (self .keyType ) + unicode (self ._comma ) + unicode (self .type ) + unicode (self ._closeType )
631
+ return output + (unicode (self .null ) if (self .null ) else '' )
632
+
610
633
output = unicode (self .type )
611
634
output = output + (unicode (self .null ) if (self .null ) else '' )
612
635
return output + (unicode (self .suffix ) if (self .suffix ) else '' )
@@ -626,6 +649,15 @@ def _markup(self, generator):
626
649
generator .addText (self ._closeType )
627
650
generator .addText (self .null )
628
651
return self
652
+ if (self .record ):
653
+ self .record .markup (generator )
654
+ generator .addText (self ._openType )
655
+ self .keyType .markup (generator )
656
+ generator .addText (self ._comma )
657
+ self .type .markup (generator )
658
+ generator .addText (self ._closeType )
659
+ generator .addText (self .null )
660
+ return self
629
661
if (isinstance (self .type , basestring )):
630
662
generator .addTypeName (self .type )
631
663
if (self .suffix ):
@@ -638,7 +670,7 @@ def _markup(self, generator):
638
670
return self
639
671
640
672
def __repr__ (self ):
641
- output = '[NonAnyType: ' + ('[sequence] ' if (self .sequence ) else '' ) + ('[Promise] ' if (self .promise ) else '' )
673
+ output = '[NonAnyType: ' + ('[sequence] ' if (self .sequence ) else '' ) + ('[Promise] ' if (self .promise ) else '' ) + ( '[record] [StringType: ' + repr ( self . keyType ) + '] ' if ( self . record ) else '' )
642
674
output += repr (self .type ) + ('[null]' if (self .null ) else '' )
643
675
return output + (repr (self .suffix ) if (self .suffix ) else '' ) + ']'
644
676
0 commit comments