Skip to content

Commit 9d338a6

Browse files
committed
Update @_package syntax layout
1 parent 6b47ef2 commit 9d338a6

File tree

15 files changed

+1444
-412
lines changed

15 files changed

+1444
-412
lines changed

CodeGeneration/Sources/SyntaxSupport/gyb_generated/AttributeNodes.swift

Lines changed: 58 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -199,45 +199,80 @@ public let ATTRIBUTE_NODES: [Node] = [
199199
nameForDiagnostics: "@_package arguments",
200200
description: "The arguments for the `@_package` attribute imitating `PackageDescription`",
201201
kind: "Syntax",
202+
children: [
203+
Child(name: "Description",
204+
kind: .nodeChoices(choices: [
205+
Child(name: "Remote",
206+
kind: .node(kind: "RemotePackageDescription")),
207+
Child(name: "Local",
208+
kind: .node(kind: "LocalPackageDescription"))
209+
])),
210+
Child(name: "Comma",
211+
kind: .token(choices: [.token(tokenKind: "CommaToken")]),
212+
description: "The comma between the package description and product, if it exists",
213+
isOptional: true),
214+
Child(name: "Product",
215+
kind: .node(kind: "PackageProduct"),
216+
description: "Explicit product declaration of package.",
217+
isOptional: true)
218+
]),
219+
220+
Node(name: "PackageProduct",
221+
nameForDiagnostics: "package product",
222+
description: "Explicit package product declaration",
223+
kind: "Syntax",
224+
children: [
225+
Child(name: "Label",
226+
kind: .token(choices: [.keyword(text: "product")]),
227+
description: "The product label"),
228+
Child(name: "Colon",
229+
kind: .token(choices: [.token(tokenKind: "ColonToken")])),
230+
Child(name: "Name",
231+
kind: .node(kind: "StringLiteralExpr"),
232+
description: "The exact product name from package")
233+
]),
234+
235+
Node(name: "LocalPackageDescription",
236+
nameForDiagnostics: "local package description",
237+
description: "The description of a local package",
238+
kind: "Syntax",
239+
children: [
240+
Child(name: "Label",
241+
kind: .token(choices: [.keyword(text: "path")]),
242+
description: "The path label"),
243+
Child(name: "Colon",
244+
kind: .token(choices: [.token(tokenKind: "ColonToken")])),
245+
Child(name: "Path",
246+
kind: .node(kind: "StringLiteralExpr"),
247+
description: "The package path")
248+
]),
249+
250+
Node(name: "RemotePackageDescription",
251+
nameForDiagnostics: "remote package description",
252+
description: "The description of a remote package",
253+
kind: "Syntax",
202254
children: [
203255
Child(name: "LocationLabel",
204-
kind: .token(choices: [.keyword(text: "id"), .keyword(text: "path"), .keyword(text: "url")]),
256+
kind: .token(choices: [.keyword(text: "id"), .keyword(text: "url")]),
205257
description: "The location label."),
206258
Child(name: "LocationColon",
207259
kind: .token(choices: [.token(tokenKind: "ColonToken")])),
208260
Child(name: "Location",
209261
kind: .node(kind: "StringLiteralExpr"),
210-
description: "The location/identifier of package."),
211-
Child(name: "RequirementComma",
262+
description: "The URL or identifier of package."),
263+
Child(name: "Comma",
212264
kind: .token(choices: [.token(tokenKind: "CommaToken")]),
213-
description: "The comma before the package requirement, if it exists.",
214-
isOptional: true),
265+
description: "The comma between the package location and requirement"),
215266
Child(name: "RequirementLabel",
216267
kind: .token(choices: [.keyword(text: "branch"), .keyword(text: "exact"), .keyword(text: "from"), .keyword(text: "revision")]),
217-
description: "The requirement label.",
268+
description: "The requirement label",
218269
isOptional: true),
219270
Child(name: "RequirementColon",
220271
kind: .token(choices: [.token(tokenKind: "ColonToken")]),
221272
isOptional: true),
222273
Child(name: "Requirement",
223274
kind: .node(kind: "Expr"),
224-
description: "The version requirement of package.",
225-
isOptional: true),
226-
Child(name: "ProductComma",
227-
kind: .token(choices: [.token(tokenKind: "CommaToken")]),
228-
description: "The comma before the package product, if it exists.",
229-
isOptional: true),
230-
Child(name: "ProductLabel",
231-
kind: .token(choices: [.keyword(text: "product")]),
232-
description: "The product label.",
233-
isOptional: true),
234-
Child(name: "ProductColon",
235-
kind: .token(choices: [.token(tokenKind: "ColonToken")]),
236-
isOptional: true),
237-
Child(name: "ProductName",
238-
kind: .node(kind: "StringLiteralExpr"),
239-
description: "The exact product name from package",
240-
isOptional: true)
275+
description: "Version requirement of remote package")
241276
]),
242277

243278
Node(name: "ObjCSelectorPiece",

Sources/SwiftParser/Attributes.swift

Lines changed: 70 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -874,66 +874,87 @@ extension Parser {
874874

875875
extension Parser {
876876
mutating func parsePackageAttributeArguments() -> RawPackageAttributeArgumentsSyntax {
877-
// Parsing package location.
877+
// Parsing package description
878878
let (unexpectedBeforeLocationLabel, locationLabel) = self.expectAny([.keyword(.id), .keyword(.path), .keyword(.url)], default: .keyword(.id))
879879
let (unexpectedBeforeLocationColon, locationColon) = self.expect(.colon)
880880
let location = self.parseStringLiteral()
881-
// Parsing package requirement.
882-
let (unexpectedBeforeRequirementComma, requirementComma): (RawUnexpectedNodesSyntax?, RawTokenSyntax?)
883-
let (unexpectedBeforeRequirementLabel, requirementLabel): (RawUnexpectedNodesSyntax?, RawTokenSyntax?)
884-
let (unexpectedBeforeRequirementColon, requirementColon): (RawUnexpectedNodesSyntax?, RawTokenSyntax?)
885-
let requirement: RawExprSyntax?
886-
if locationLabel.tokenKind != .keyword(.path) {
887-
(unexpectedBeforeRequirementComma, requirementComma) = self.expect(.comma)
881+
let packageDescription: RawPackageAttributeArgumentsSyntax.Description
882+
if locationLabel.tokenKind == .keyword(.path) {
883+
packageDescription = .local(
884+
RawLocalPackageDescriptionSyntax(
885+
unexpectedBeforeLocationLabel,
886+
label: locationLabel,
887+
unexpectedBeforeLocationColon,
888+
colon: locationColon,
889+
path: location,
890+
arena: self.arena
891+
)
892+
)
893+
} else {
894+
let (unexpectedBeforeRequirementComma, requirementComma) = self.expect(.comma)
888895
if self.at(any: [.colon, .keyword(.from), .keyword(.exact), .keyword(.branch), .keyword(.revision)]) {
889-
(unexpectedBeforeRequirementLabel, requirementLabel) = self.expectAny([.keyword(.from), .keyword(.exact), .keyword(.branch), .keyword(.revision)], default: .keyword(.from))
890-
(unexpectedBeforeRequirementColon, requirementColon) = self.expect(.colon)
891-
requirement = self.parseStringLiteral().as(RawExprSyntax.self)
896+
let (unexpectedBeforeRequirementLabel, requirementLabel) = self.expectAny([.keyword(.from), .keyword(.exact), .keyword(.branch), .keyword(.revision)], default: .keyword(.from))
897+
let (unexpectedBeforeRequirementColon, requirementColon) = self.expect(.colon)
898+
let requirement = self.parseStringLiteral().as(RawExprSyntax.self)!
899+
packageDescription = .remote(
900+
RawRemotePackageDescriptionSyntax(
901+
unexpectedBeforeLocationLabel,
902+
locationLabel: locationLabel,
903+
unexpectedBeforeLocationColon,
904+
locationColon: locationColon,
905+
location: location,
906+
unexpectedBeforeRequirementComma,
907+
comma: requirementComma,
908+
unexpectedBeforeRequirementLabel,
909+
requirementLabel: requirementLabel,
910+
unexpectedBeforeRequirementColon,
911+
requirementColon: requirementColon,
912+
requirement: requirement,
913+
arena: self.arena
914+
)
915+
)
892916
} else {
893-
(unexpectedBeforeRequirementLabel, requirementLabel) = (nil, nil)
894-
(unexpectedBeforeRequirementColon, requirementColon) = (nil, nil)
895-
requirement = self.parseExpression()
917+
let requirement = self.parseExpression()
918+
packageDescription = .remote(
919+
RawRemotePackageDescriptionSyntax(
920+
unexpectedBeforeLocationLabel,
921+
locationLabel: locationLabel,
922+
unexpectedBeforeLocationColon,
923+
locationColon: locationColon,
924+
location: location,
925+
unexpectedBeforeRequirementComma,
926+
comma: requirementComma,
927+
requirementLabel: nil,
928+
requirementColon: nil,
929+
requirement: requirement,
930+
arena: self.arena
931+
)
932+
)
896933
}
897-
} else {
898-
(unexpectedBeforeRequirementComma, requirementComma) = (nil, nil)
899-
(unexpectedBeforeRequirementLabel, requirementLabel) = (nil, nil)
900-
(unexpectedBeforeRequirementColon, requirementColon) = (nil, nil)
901-
requirement = nil
902934
}
903-
// Parsing package requirement.
904-
let productComma = self.consume(if: .comma)
905-
let (unexpectedBeforeProductLabel, productLabel): (RawUnexpectedNodesSyntax?, RawTokenSyntax?)
906-
let (unexpectedBeforeProductColon, productColon): (RawUnexpectedNodesSyntax?, RawTokenSyntax?)
907-
let productName: RawStringLiteralExprSyntax?
908-
if productComma != nil {
909-
(unexpectedBeforeProductLabel, productLabel) = self.expect(.keyword(.product))
910-
(unexpectedBeforeProductColon, productColon) = self.expect(.colon)
911-
productName = self.parseStringLiteral()
935+
// Parsing package product
936+
let comma = self.consume(if: .comma)
937+
let packageProduct: RawPackageProductSyntax?
938+
if comma != nil {
939+
let (unexpectedBeforeProductLabel, productLabel) = self.expect(.keyword(.product))
940+
let (unexpectedBeforeProductColon, productColon) = self.expect(.colon)
941+
let productName = self.parseStringLiteral()
942+
packageProduct = RawPackageProductSyntax(
943+
unexpectedBeforeProductLabel,
944+
label: productLabel,
945+
unexpectedBeforeProductColon,
946+
colon: productColon,
947+
name: productName,
948+
arena: self.arena
949+
)
912950
} else {
913-
(unexpectedBeforeProductLabel, productLabel) = (nil, nil)
914-
(unexpectedBeforeProductColon, productColon) = (nil, nil)
915-
productName = nil
951+
packageProduct = nil
916952
}
917953
// Returning @_package argument list
918954
return RawPackageAttributeArgumentsSyntax(
919-
unexpectedBeforeLocationLabel,
920-
locationLabel: locationLabel,
921-
unexpectedBeforeLocationColon,
922-
locationColon: locationColon,
923-
location: location,
924-
unexpectedBeforeRequirementComma,
925-
requirementComma: requirementComma,
926-
unexpectedBeforeRequirementLabel,
927-
requirementLabel: requirementLabel,
928-
unexpectedBeforeRequirementColon,
929-
requirementColon: requirementColon,
930-
requirement: requirement,
931-
productComma: productComma,
932-
unexpectedBeforeProductLabel,
933-
productLabel: productLabel,
934-
unexpectedBeforeProductColon,
935-
productColon: productColon,
936-
productName: productName,
955+
description: packageDescription,
956+
comma: comma,
957+
product: packageProduct,
937958
arena: self.arena
938959
)
939960
}

Sources/SwiftSyntax/Documentation.docc/gyb_generated/SwiftSyntax.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,9 @@ allows Swift tools to parse, inspect, generate, and transform Swift source code.
353353
- <doc:SwiftSyntax/DeclNameSyntax>
354354
- <doc:SwiftSyntax/ImplementsAttributeArgumentsSyntax>
355355
- <doc:SwiftSyntax/PackageAttributeArgumentsSyntax>
356+
- <doc:SwiftSyntax/PackageProductSyntax>
357+
- <doc:SwiftSyntax/LocalPackageDescriptionSyntax>
358+
- <doc:SwiftSyntax/RemotePackageDescriptionSyntax>
356359
- <doc:SwiftSyntax/ObjCSelectorPieceSyntax>
357360
- <doc:SwiftSyntax/ObjCSelectorSyntax>
358361
- <doc:SwiftSyntax/DifferentiableAttributeArgumentsSyntax>

0 commit comments

Comments
 (0)