@@ -873,143 +873,66 @@ extension Parser {
873
873
}
874
874
875
875
extension Parser {
876
- mutating func parsePackageAttribute( ) -> RawAttributeSyntax {
877
- let ( unexpectedBeforeAtSign, atSign) = self . expect ( . atSign)
878
- let ( unexpectedBeforePackageToken, packageToken) = self . expect ( . keyword( . _package) )
879
- let ( unexpectedBeforeLeftParen, leftParen) = self . expect ( . leftParen)
880
- let arguments = self . parsePackageAttributeArguments ( )
881
- let ( unexpectedBeforeRightParen, rightParen) = self . expect ( . rightParen)
882
- return RawAttributeSyntax (
883
- unexpectedBeforeAtSign,
884
- atSignToken: atSign,
885
- unexpectedBeforePackageToken,
886
- attributeName: RawTypeSyntax ( RawSimpleTypeIdentifierSyntax ( name: packageToken, genericArgumentClause: nil , arena: self . arena) ) ,
887
- unexpectedBeforeLeftParen,
888
- leftParen: leftParen,
889
- argument: . packageAttributeArguments( arguments) ,
890
- unexpectedBeforeRightParen,
891
- rightParen: rightParen,
892
- arena: self . arena
893
- )
894
- }
895
-
896
- enum PackageLocationLabel : RawTokenKindSubset {
897
- case id
898
- case path
899
- case url
900
-
901
- init ? ( lexeme: Lexer . Lexeme ) {
902
- switch lexeme {
903
- case RawTokenKindMatch ( . id) : self = . id
904
- case RawTokenKindMatch ( . path) : self = . path
905
- case RawTokenKindMatch ( . url) : self = . url
906
- default : return nil
907
- }
908
- }
909
-
910
- var rawTokenKind : RawTokenKind {
911
- switch self {
912
- case . id: return . keyword( . id)
913
- case . path: return . keyword( . path)
914
- case . url: return . keyword( . url)
915
- }
916
- }
917
- }
918
-
919
- enum PackageRequirementLabel : RawTokenKindSubset {
920
- case branch
921
- case from
922
- case revision
923
-
924
- init ? ( lexeme: Lexer . Lexeme ) {
925
- switch lexeme {
926
- case RawTokenKindMatch ( . branch) : self = . branch
927
- case RawTokenKindMatch ( . from) : self = . from
928
- case RawTokenKindMatch ( . revision) : self = . revision
929
- default : return nil
930
- }
931
- }
932
-
933
- var rawTokenKind : RawTokenKind {
934
- switch self {
935
- case . branch: return . keyword( . branch)
936
- case . from: return . keyword( . from)
937
- case . revision: return . keyword( . revision)
938
- }
939
- }
940
- }
941
-
942
876
mutating func parsePackageAttributeArguments( ) -> RawPackageAttributeArgumentsSyntax {
943
877
// Parsing package location.
944
- let locationLabel = self . consume ( ifAnyIn : PackageLocationLabel . self ) ?? missingToken ( . identifier )
878
+ let ( unexpectedBeforeLocationLabel , locationLabel) = self . expectAny ( [ . keyword ( . id ) , . keyword ( . path ) , . keyword ( . url ) ] , default : . keyword ( . id ) )
945
879
let ( unexpectedBeforeLocationColon, locationColon) = self . expect ( . colon)
946
880
let location = self . parseStringLiteral ( )
947
881
// Parsing package requirement.
948
- let ( unexpectedBeforeLocReqComma , locReqComma ) : ( RawUnexpectedNodesSyntax ? , RawTokenSyntax ? )
882
+ let ( unexpectedBeforeRequirementComma , requirementComma ) : ( RawUnexpectedNodesSyntax ? , RawTokenSyntax ? )
949
883
let ( unexpectedBeforeRequirementLabel, requirementLabel) : ( RawUnexpectedNodesSyntax ? , RawTokenSyntax ? )
950
884
let ( unexpectedBeforeRequirementColon, requirementColon) : ( RawUnexpectedNodesSyntax ? , RawTokenSyntax ? )
951
885
let requirement : RawExprSyntax ?
952
886
if locationLabel. tokenKind != . keyword( . path) {
953
- ( unexpectedBeforeLocReqComma , locReqComma ) = self . expect ( . comma)
954
- if let label = self . consume ( ifAnyIn : PackageRequirementLabel . self ) {
955
- ( unexpectedBeforeRequirementLabel, requirementLabel) = ( nil , label )
887
+ ( unexpectedBeforeRequirementComma , requirementComma ) = self . expect ( . comma)
888
+ if self . at ( any : [ . keyword ( . from ) , . keyword ( . branch ) , . keyword ( . revision ) ] ) {
889
+ ( unexpectedBeforeRequirementLabel, requirementLabel) = self . expectAny ( [ . keyword ( . from ) , . keyword ( . branch ) , . keyword ( . revision ) ] , default : . keyword ( . from ) )
956
890
( unexpectedBeforeRequirementColon, requirementColon) = self . expect ( . colon)
957
891
} else {
958
892
( unexpectedBeforeRequirementLabel, requirementLabel) = ( nil , nil )
959
893
( unexpectedBeforeRequirementColon, requirementColon) = ( nil , nil )
960
894
}
961
895
requirement = self . parseExpression ( )
962
896
} else {
963
- ( unexpectedBeforeLocReqComma , locReqComma ) = ( nil , nil )
897
+ ( unexpectedBeforeRequirementComma , requirementComma ) = ( nil , nil )
964
898
( unexpectedBeforeRequirementLabel, requirementLabel) = ( nil , nil )
965
899
( unexpectedBeforeRequirementColon, requirementColon) = ( nil , nil )
966
900
requirement = nil
967
901
}
968
- guard self . at ( . comma) else {
969
- return RawPackageAttributeArgumentsSyntax (
970
- locationLabel: locationLabel,
971
- unexpectedBeforeLocationColon,
972
- locationColon: locationColon,
973
- location: location,
974
- unexpectedBeforeLocReqComma,
975
- locReqComma: locReqComma,
976
- unexpectedBeforeRequirementLabel,
977
- requirementLabel: requirementLabel,
978
- unexpectedBeforeRequirementColon,
979
- requirementColon: requirementColon,
980
- requirement: requirement,
981
- reqProdComma: nil ,
982
- productLabel: nil ,
983
- productColon: nil ,
984
- productName: nil ,
985
- self . remainingTokensIfMaximumNestingLevelReached ( ) ,
986
- arena: self . arena
987
- )
902
+ // Parsing package requirement.
903
+ let productComma = self . consume ( if: . comma)
904
+ let ( unexpectedBeforeProductLabel, productLabel) : ( RawUnexpectedNodesSyntax ? , RawTokenSyntax ? )
905
+ let ( unexpectedBeforeProductColon, productColon) : ( RawUnexpectedNodesSyntax ? , RawTokenSyntax ? )
906
+ let productName : RawStringLiteralExprSyntax ?
907
+ if productComma != nil {
908
+ ( unexpectedBeforeProductLabel, productLabel) = self . expect ( . keyword( . product) )
909
+ ( unexpectedBeforeProductColon, productColon) = self . expect ( . colon)
910
+ productName = self . parseStringLiteral ( )
911
+ } else {
912
+ ( unexpectedBeforeProductLabel, productLabel) = ( nil , nil )
913
+ ( unexpectedBeforeProductColon, productColon) = ( nil , nil )
914
+ productName = nil
988
915
}
989
- let ( unexpectedBeforeReqProdComma, reqProdComma) = self . expect ( . comma)
990
- let ( unexpectedBeforeProductLabel, productLabel) = self . expect ( . keyword( . product) )
991
- let ( unexpectedBeforeProductColon, productColon) = self . expect ( . colon)
992
- let productName = self . parseStringLiteral ( )
916
+ // Returning @_package argument list
993
917
return RawPackageAttributeArgumentsSyntax (
918
+ unexpectedBeforeLocationLabel,
994
919
locationLabel: locationLabel,
995
920
unexpectedBeforeLocationColon,
996
921
locationColon: locationColon,
997
922
location: location,
998
- unexpectedBeforeLocReqComma ,
999
- locReqComma : locReqComma ,
923
+ unexpectedBeforeRequirementComma ,
924
+ requirementComma : requirementComma ,
1000
925
unexpectedBeforeRequirementLabel,
1001
926
requirementLabel: requirementLabel,
1002
927
unexpectedBeforeRequirementColon,
1003
928
requirementColon: requirementColon,
1004
929
requirement: requirement,
1005
- unexpectedBeforeReqProdComma,
1006
- reqProdComma: reqProdComma,
930
+ productComma: productComma,
1007
931
unexpectedBeforeProductLabel,
1008
932
productLabel: productLabel,
1009
933
unexpectedBeforeProductColon,
1010
934
productColon: productColon,
1011
935
productName: productName,
1012
- self . remainingTokensIfMaximumNestingLevelReached ( ) ,
1013
936
arena: self . arena
1014
937
)
1015
938
}
0 commit comments