@@ -807,41 +807,57 @@ extension Parser {
807
807
808
808
var attributeProgress = LoopProgressCondition ( )
809
809
while self . at ( . atSign) && attributeProgress. evaluate ( currentToken) {
810
- elements. append ( RawSyntax ( self . parseTypeAttribute ( ) ) )
810
+ elements. append ( self . parseTypeAttribute ( ) )
811
811
}
812
812
return RawAttributeListSyntax ( elements: elements, arena: self . arena)
813
813
}
814
814
815
815
@_spi ( RawSyntax)
816
- public mutating func parseTypeAttribute( ) -> RawAttributeSyntax {
817
- let at = self . eat ( . atSign)
818
- let ident = self . consumeIdentifier ( )
819
- if let attr = Parser . TypeAttribute ( rawValue: ident. tokenText) {
820
- // Ok, it is a valid attribute, eat it, and then process it.
821
- if case . convention = attr {
822
- let ( unexpectedBeforeLeftParen, leftParen) = self . expect ( . leftParen)
823
- let convention = self . consumeIdentifier ( )
824
- let ( unexpectedBeforeRightParen, rightParen) = self . expect ( . rightParen)
825
- return RawAttributeSyntax (
816
+ public mutating func parseTypeAttribute( ) -> RawSyntax {
817
+ guard let typeAttr = Parser . TypeAttribute ( rawValue: self . peek ( ) . tokenText) else {
818
+ return RawSyntax ( self . parseCustomAttribute ( ) )
819
+ }
820
+
821
+ switch typeAttr {
822
+ case . differentiable:
823
+ return RawSyntax ( self . parseDifferentiableAttribute ( ) )
824
+
825
+ case . convention:
826
+ let at = self . eat ( . atSign)
827
+ let ident = self . consumeIdentifier ( )
828
+ let ( unexpectedBeforeLeftParen, leftParen) = self . expect ( . leftParen)
829
+ let argument = self . consumeIdentifier ( )
830
+
831
+ let ( unexpectedBeforeRightParen, rightParen) = self . expect ( . rightParen)
832
+ return RawSyntax (
833
+ RawAttributeSyntax (
826
834
atSignToken: at,
827
835
attributeName: ident,
828
836
unexpectedBeforeLeftParen,
829
837
leftParen: leftParen,
830
- argument: RawSyntax ( convention ) ,
838
+ argument: RawSyntax ( argument ) ,
831
839
unexpectedBeforeRightParen,
832
840
rightParen: rightParen,
833
841
tokenList: nil ,
834
- arena: self . arena)
835
- }
842
+ arena: self . arena
843
+ )
844
+ )
845
+
846
+ default :
847
+ let at = self . eat ( . atSign)
848
+ let ident = self . consumeIdentifier ( )
849
+ return RawSyntax (
850
+ RawAttributeSyntax (
851
+ atSignToken: at,
852
+ attributeName: ident,
853
+ leftParen: nil ,
854
+ argument: nil ,
855
+ rightParen: nil ,
856
+ tokenList: nil ,
857
+ arena: self . arena
858
+ )
859
+ )
836
860
}
837
- return RawAttributeSyntax (
838
- atSignToken: at,
839
- attributeName: ident,
840
- leftParen: nil ,
841
- argument: nil ,
842
- rightParen: nil ,
843
- tokenList: nil ,
844
- arena: self . arena)
845
861
}
846
862
}
847
863
0 commit comments