Skip to content

Commit 10e8853

Browse files
committed
Fine-tune for different kinds of package dependency
1 parent 5acf2a2 commit 10e8853

File tree

15 files changed

+1502
-446
lines changed

15 files changed

+1502
-446
lines changed

CodeGeneration/Sources/SyntaxSupport/gyb_generated/AttributeNodes.swift

Lines changed: 64 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -202,10 +202,12 @@ public let ATTRIBUTE_NODES: [Node] = [
202202
children: [
203203
Child(name: "Description",
204204
kind: .nodeChoices(choices: [
205-
Child(name: "Remote",
206-
kind: .node(kind: "RemotePackageDescription")),
207-
Child(name: "Local",
208-
kind: .node(kind: "LocalPackageDescription"))
205+
Child(name: "FileSystem",
206+
kind: .node(kind: "FileSystemPackageDescription")),
207+
Child(name: "SourceControl",
208+
kind: .node(kind: "SourceControlPackageDescription")),
209+
Child(name: "Registry",
210+
kind: .node(kind: "RegistryPackageDescription"))
209211
])),
210212
Child(name: "Comma",
211213
kind: .token(choices: [.token(tokenKind: "CommaToken")]),
@@ -232,7 +234,7 @@ public let ATTRIBUTE_NODES: [Node] = [
232234
description: "The exact product name from package")
233235
]),
234236

235-
Node(name: "LocalPackageDescription",
237+
Node(name: "FileSystemPackageDescription",
236238
nameForDiagnostics: "local package description",
237239
description: "The description of a local package",
238240
kind: "Syntax",
@@ -247,35 +249,61 @@ public let ATTRIBUTE_NODES: [Node] = [
247249
description: "The package path")
248250
]),
249251

250-
Node(name: "RemotePackageDescription",
252+
Node(name: "SourceControlPackageDescription",
253+
nameForDiagnostics: "remote package description (source control)",
254+
description: "The description of a remote package using source control",
255+
kind: "Syntax",
256+
children: [
257+
Child(name: "Label",
258+
kind: .token(choices: [.keyword(text: "url")]),
259+
description: "The URL label"),
260+
Child(name: "Colon",
261+
kind: .token(choices: [.token(tokenKind: "ColonToken")])),
262+
Child(name: "URL",
263+
kind: .node(kind: "StringLiteralExpr"),
264+
description: "The Git URL of package"),
265+
Child(name: "Comma",
266+
kind: .token(choices: [.token(tokenKind: "CommaToken")]),
267+
description: "The comma between the package URL and requirement"),
268+
Child(name: "Requirement",
269+
kind: .nodeChoices(choices: [
270+
Child(name: "Labeled",
271+
kind: .node(kind: "SourceControlRequirement")),
272+
Child(name: "Range",
273+
kind: .node(kind: "Expr"))
274+
]),
275+
description: "Version requirement of the remote package")
276+
]),
277+
278+
Node(name: "RegistryPackageDescription",
251279
nameForDiagnostics: "remote package description",
252280
description: "The description of a remote package",
253281
kind: "Syntax",
254282
children: [
255-
Child(name: "LocationLabel",
256-
kind: .token(choices: [.keyword(text: "id"), .keyword(text: "url")]),
257-
description: "The location label."),
258-
Child(name: "LocationColon",
283+
Child(name: "Label",
284+
kind: .token(choices: [.keyword(text: "id")]),
285+
description: "The ID label"),
286+
Child(name: "Colon",
259287
kind: .token(choices: [.token(tokenKind: "ColonToken")])),
260-
Child(name: "Location",
288+
Child(name: "Identifier",
261289
kind: .node(kind: "StringLiteralExpr"),
262-
description: "The URL or identifier of package."),
290+
description: "The identifier of package"),
263291
Child(name: "Comma",
264292
kind: .token(choices: [.token(tokenKind: "CommaToken")]),
265-
description: "The comma between the package location and requirement"),
293+
description: "The comma between the package identifier and requirement"),
266294
Child(name: "Requirement",
267295
kind: .nodeChoices(choices: [
268296
Child(name: "Labeled",
269-
kind: .node(kind: "LabeledPackageRequirement")),
270-
Child(name: "Wildcard",
297+
kind: .node(kind: "RegistryRequirement")),
298+
Child(name: "Range",
271299
kind: .node(kind: "Expr"))
272300
]),
273-
description: "Version requirement of remote package")
301+
description: "Version requirement of the remote package")
274302
]),
275303

276-
Node(name: "LabeledPackageRequirement",
277-
nameForDiagnostics: "labeled package requirement",
278-
description: "Labeled requirement of a remote package",
304+
Node(name: "SourceControlRequirement",
305+
nameForDiagnostics: "labeled package requirement (source control)",
306+
description: "Labeled requirement of a source-control package",
279307
kind: "Syntax",
280308
children: [
281309
Child(name: "Label",
@@ -290,6 +318,23 @@ public let ATTRIBUTE_NODES: [Node] = [
290318
description: "Requirement description of remote package")
291319
]),
292320

321+
Node(name: "RegistryRequirement",
322+
nameForDiagnostics: "labeled package requirement (registry)",
323+
description: "Labeled requirement of a registry package",
324+
kind: "Syntax",
325+
children: [
326+
Child(name: "Label",
327+
kind: .token(choices: [.keyword(text: "exact"), .keyword(text: "from")]),
328+
description: "The requirement label",
329+
isOptional: true),
330+
Child(name: "Colon",
331+
kind: .token(choices: [.token(tokenKind: "ColonToken")]),
332+
isOptional: true),
333+
Child(name: "Requirement",
334+
kind: .node(kind: "StringLiteralExpr"),
335+
description: "Requirement description of remote package")
336+
]),
337+
293338
Node(name: "ObjCSelectorPiece",
294339
nameForDiagnostics: "Objective-C selector piece",
295340
description: "A piece of an Objective-C selector. Either consisting of just an identifier for a nullary selector, an identifier and a colon for a labeled argument or just a colon for an unlabeled argument",

Sources/SwiftParser/Attributes.swift

Lines changed: 55 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -879,9 +879,11 @@ extension Parser {
879879
let (unexpectedBeforeLocationColon, locationColon) = self.expect(.colon)
880880
let location = self.parseStringLiteral()
881881
let packageDescription: RawPackageAttributeArgumentsSyntax.Description
882-
if locationLabel.tokenKind == .keyword(.path) {
883-
packageDescription = .local(
884-
RawLocalPackageDescriptionSyntax(
882+
// Parsing package requirement
883+
switch locationLabel.tokenKind {
884+
case .keyword(.path):
885+
packageDescription = .fileSystem(
886+
RawFileSystemPackageDescriptionSyntax(
885887
unexpectedBeforeLocationLabel,
886888
label: locationLabel,
887889
unexpectedBeforeLocationColon,
@@ -890,16 +892,15 @@ extension Parser {
890892
arena: self.arena
891893
)
892894
)
893-
} else {
895+
case .keyword(.id):
894896
let (unexpectedBeforeRequirementComma, requirementComma) = self.expect(.comma)
895-
// Parsing package requirement
896-
let packageRequirement: RawRemotePackageDescriptionSyntax.Requirement
897-
if self.at(any: [.colon, .keyword(.from), .keyword(.exact), .keyword(.branch), .keyword(.revision)]) {
898-
let (unexpectedBeforeRequirementLabel, requirementLabel) = self.expectAny([.keyword(.from), .keyword(.exact), .keyword(.branch), .keyword(.revision)], default: .keyword(.from))
897+
let registryRequirement: RawRegistryPackageDescriptionSyntax.Requirement
898+
if self.at(any: [.colon, .keyword(.exact), .keyword(.from)]) {
899+
let (unexpectedBeforeRequirementLabel, requirementLabel) = self.expectAny([.keyword(.from), .keyword(.exact)], default: .keyword(.from))
899900
let (unexpectedBeforeRequirementColon, requirementColon) = self.expect(.colon)
900901
let requirement = self.parseStringLiteral()
901-
packageRequirement = .labeled(
902-
RawLabeledPackageRequirementSyntax(
902+
registryRequirement = .labeled(
903+
RawRegistryRequirementSyntax(
903904
unexpectedBeforeRequirementLabel,
904905
label: requirementLabel,
905906
unexpectedBeforeRequirementColon,
@@ -910,18 +911,55 @@ extension Parser {
910911
)
911912
} else {
912913
let requirement = self.parseExpression()
913-
packageRequirement = .wildcard(requirement)
914+
registryRequirement = .range(requirement)
914915
}
915-
packageDescription = .remote(
916-
RawRemotePackageDescriptionSyntax(
916+
packageDescription = .registry(
917+
RawRegistryPackageDescriptionSyntax(
917918
unexpectedBeforeLocationLabel,
918-
locationLabel: locationLabel,
919+
label: locationLabel,
919920
unexpectedBeforeLocationColon,
920-
locationColon: locationColon,
921-
location: location,
921+
colon: locationColon,
922+
identifier: location,
923+
unexpectedBeforeRequirementComma,
924+
comma: requirementComma,
925+
requirement: registryRequirement,
926+
arena: self.arena
927+
)
928+
)
929+
case .keyword(.url):
930+
// FIXME: Default to handling as source-control for now
931+
fallthrough
932+
default:
933+
let (unexpectedBeforeRequirementComma, requirementComma) = self.expect(.comma)
934+
let sourceControlRequirement: RawSourceControlPackageDescriptionSyntax.Requirement
935+
if self.at(any: [.colon, .keyword(.branch), .keyword(.exact), .keyword(.from), .keyword(.revision)]) {
936+
let (unexpectedBeforeRequirementLabel, requirementLabel) = self.expectAny([.keyword(.branch), .keyword(.exact), .keyword(.from), .keyword(.revision)], default: .keyword(.from))
937+
let (unexpectedBeforeRequirementColon, requirementColon) = self.expect(.colon)
938+
let requirement = self.parseStringLiteral()
939+
sourceControlRequirement = .labeled(
940+
RawSourceControlRequirementSyntax(
941+
unexpectedBeforeRequirementLabel,
942+
label: requirementLabel,
943+
unexpectedBeforeRequirementColon,
944+
colon: requirementColon,
945+
requirement: requirement,
946+
arena: self.arena
947+
)
948+
)
949+
} else {
950+
let requirement = self.parseExpression()
951+
sourceControlRequirement = .range(requirement)
952+
}
953+
packageDescription = .sourceControl(
954+
RawSourceControlPackageDescriptionSyntax(
955+
unexpectedBeforeLocationLabel,
956+
label: locationLabel,
957+
unexpectedBeforeLocationColon,
958+
colon: locationColon,
959+
url: location,
922960
unexpectedBeforeRequirementComma,
923961
comma: requirementComma,
924-
requirement: packageRequirement,
962+
requirement: sourceControlRequirement,
925963
arena: self.arena
926964
)
927965
)

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -354,9 +354,11 @@ allows Swift tools to parse, inspect, generate, and transform Swift source code.
354354
- <doc:SwiftSyntax/ImplementsAttributeArgumentsSyntax>
355355
- <doc:SwiftSyntax/PackageAttributeArgumentsSyntax>
356356
- <doc:SwiftSyntax/PackageProductSyntax>
357-
- <doc:SwiftSyntax/LocalPackageDescriptionSyntax>
358-
- <doc:SwiftSyntax/RemotePackageDescriptionSyntax>
359-
- <doc:SwiftSyntax/LabeledPackageRequirementSyntax>
357+
- <doc:SwiftSyntax/FileSystemPackageDescriptionSyntax>
358+
- <doc:SwiftSyntax/SourceControlPackageDescriptionSyntax>
359+
- <doc:SwiftSyntax/RegistryPackageDescriptionSyntax>
360+
- <doc:SwiftSyntax/SourceControlRequirementSyntax>
361+
- <doc:SwiftSyntax/RegistryRequirementSyntax>
360362
- <doc:SwiftSyntax/ObjCSelectorPieceSyntax>
361363
- <doc:SwiftSyntax/ObjCSelectorSyntax>
362364
- <doc:SwiftSyntax/DifferentiableAttributeArgumentsSyntax>

0 commit comments

Comments
 (0)