Skip to content

Commit 7ed925d

Browse files
authored
Merge pull request #1903 from Matejkob/with-generic-parameters-trait
2 parents e71453d + 5ee3144 commit 7ed925d

File tree

10 files changed

+227
-78
lines changed

10 files changed

+227
-78
lines changed

CodeGeneration/Sources/SyntaxSupport/AttributeNodes.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -510,6 +510,7 @@ public let ATTRIBUTE_NODES: [Node] = [
510510
name: "GenericWhereClause",
511511
deprecatedName: "WhereClause",
512512
kind: .node(kind: .genericWhereClause),
513+
documentation: "A `where` clause that places additional constraints on generic parameters like `where T: Differentiable`.",
513514
isOptional: true
514515
),
515516
]

CodeGeneration/Sources/SyntaxSupport/DeclNodes.swift

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,7 @@ public let DECL_NODES: [Node] = [
243243
"DeclGroup",
244244
"IdentifiedDecl",
245245
"WithAttributes",
246+
"WithGenericParameters",
246247
"WithModifiers",
247248
],
248249
children: [
@@ -270,6 +271,7 @@ public let DECL_NODES: [Node] = [
270271
name: "GenericParameterClause",
271272
kind: .node(kind: .genericParameterClause),
272273
nameForDiagnostics: "generic parameter clause",
274+
documentation: "The parameter clause that defines the generic parameters.",
273275
isOptional: true
274276
),
275277
Child(
@@ -282,6 +284,7 @@ public let DECL_NODES: [Node] = [
282284
name: "GenericWhereClause",
283285
kind: .node(kind: .genericWhereClause),
284286
nameForDiagnostics: "generic where clause",
287+
documentation: "A `where` clause that places additional constraints on generic parameters like `where Element: Hashable`.",
285288
isOptional: true
286289
),
287290
Child(
@@ -416,6 +419,7 @@ public let DECL_NODES: [Node] = [
416419
"DeclGroup",
417420
"IdentifiedDecl",
418421
"WithAttributes",
422+
"WithGenericParameters",
419423
"WithModifiers",
420424
],
421425
children: [
@@ -837,6 +841,7 @@ public let DECL_NODES: [Node] = [
837841
"DeclGroup",
838842
"IdentifiedDecl",
839843
"WithAttributes",
844+
"WithGenericParameters",
840845
"WithModifiers",
841846
],
842847
children: [
@@ -941,6 +946,7 @@ public let DECL_NODES: [Node] = [
941946
name: "GenericWhereClause",
942947
kind: .node(kind: .genericWhereClause),
943948
nameForDiagnostics: "generic where clause",
949+
documentation: "A `where` clause that places additional constraints on generic parameters like `where Element: Hashable`.",
944950
isOptional: true
945951
),
946952
Child(
@@ -957,6 +963,7 @@ public let DECL_NODES: [Node] = [
957963
traits: [
958964
"IdentifiedDecl",
959965
"WithAttributes",
966+
"WithGenericParameters",
960967
"WithModifiers",
961968
],
962969
children: [
@@ -989,6 +996,7 @@ public let DECL_NODES: [Node] = [
989996
name: "GenericParameterClause",
990997
kind: .node(kind: .genericParameterClause),
991998
nameForDiagnostics: "generic parameter clause",
999+
documentation: "The parameter clause that defines the generic parameters.",
9921000
isOptional: true
9931001
),
9941002
Child(
@@ -1000,6 +1008,7 @@ public let DECL_NODES: [Node] = [
10001008
name: "GenericWhereClause",
10011009
kind: .node(kind: .genericWhereClause),
10021010
nameForDiagnostics: "generic where clause",
1011+
documentation: "A `where` clause that places additional constraints on generic parameters like `where Element: Hashable`.",
10031012
isOptional: true
10041013
),
10051014
Child(
@@ -1300,6 +1309,7 @@ public let DECL_NODES: [Node] = [
13001309
""",
13011310
traits: [
13021311
"WithAttributes",
1312+
"WithGenericParameters",
13031313
"WithModifiers",
13041314
],
13051315
children: [
@@ -1368,6 +1378,7 @@ public let DECL_NODES: [Node] = [
13681378
traits: [
13691379
"IdentifiedDecl",
13701380
"WithAttributes",
1381+
"WithGenericParameters",
13711382
"WithModifiers",
13721383
],
13731384
children: [
@@ -1395,6 +1406,7 @@ public let DECL_NODES: [Node] = [
13951406
name: "GenericParameterClause",
13961407
kind: .node(kind: .genericParameterClause),
13971408
nameForDiagnostics: "generic parameter clause",
1409+
documentation: "The parameter clause that defines the generic parameters.",
13981410
isOptional: true
13991411
),
14001412
Child(
@@ -1412,6 +1424,7 @@ public let DECL_NODES: [Node] = [
14121424
name: "GenericWhereClause",
14131425
kind: .node(kind: .genericWhereClause),
14141426
nameForDiagnostics: "generic where clause",
1427+
documentation: "A `where` clause that places additional constraints on generic parameters like `where Element: Hashable`.",
14151428
isOptional: true
14161429
),
14171430
]
@@ -2128,6 +2141,7 @@ public let DECL_NODES: [Node] = [
21282141
"DeclGroup",
21292142
"IdentifiedDecl",
21302143
"WithAttributes",
2144+
"WithGenericParameters",
21312145
"WithModifiers",
21322146
],
21332147
children: [
@@ -2191,6 +2205,7 @@ public let DECL_NODES: [Node] = [
21912205
nameForDiagnostics: "subscript",
21922206
traits: [
21932207
"WithAttributes",
2208+
"WithGenericParameters",
21942209
"WithModifiers",
21952210
],
21962211
children: [
@@ -2214,6 +2229,7 @@ public let DECL_NODES: [Node] = [
22142229
name: "GenericParameterClause",
22152230
kind: .node(kind: .genericParameterClause),
22162231
nameForDiagnostics: "generic parameter clause",
2232+
documentation: "The parameter clause that defines the generic parameters.",
22172233
isOptional: true
22182234
),
22192235
Child(
@@ -2230,6 +2246,7 @@ public let DECL_NODES: [Node] = [
22302246
name: "GenericWhereClause",
22312247
kind: .node(kind: .genericWhereClause),
22322248
nameForDiagnostics: "generic where clause",
2249+
documentation: "A `where` clause that places additional constraints on generic parameters like `where Element: Hashable`.",
22332250
isOptional: true
22342251
),
22352252
Child(
@@ -2295,6 +2312,7 @@ public let DECL_NODES: [Node] = [
22952312
traits: [
22962313
"IdentifiedDecl",
22972314
"WithAttributes",
2315+
"WithGenericParameters",
22982316
"WithModifiers",
22992317
],
23002318
children: [
@@ -2322,6 +2340,7 @@ public let DECL_NODES: [Node] = [
23222340
name: "GenericParameterClause",
23232341
kind: .node(kind: .genericParameterClause),
23242342
nameForDiagnostics: "generic parameter clause",
2343+
documentation: "The parameter clause that defines the generic parameters.",
23252344
isOptional: true
23262345
),
23272346
Child(
@@ -2332,6 +2351,7 @@ public let DECL_NODES: [Node] = [
23322351
name: "GenericWhereClause",
23332352
kind: .node(kind: .genericWhereClause),
23342353
nameForDiagnostics: "generic where clause",
2354+
documentation: "A `where` clause that places additional constraints on generic parameters like `where Element: Hashable`.",
23352355
isOptional: true
23362356
),
23372357
]

CodeGeneration/Sources/SyntaxSupport/GenericNodes.swift

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,27 +37,32 @@ public let GENERIC_NODES: [Node] = [
3737
kind: .genericParameterClause,
3838
base: .syntax,
3939
nameForDiagnostics: "generic parameter clause",
40+
documentation: "The parameter clause that defines the generic parameters.",
4041
parserFunction: "parseGenericParameters",
4142
children: [
4243
Child(
4344
name: "LeftAngle",
4445
deprecatedName: "LeftAngleBracket",
45-
kind: .token(choices: [.token(tokenKind: "LeftAngleToken")])
46+
kind: .token(choices: [.token(tokenKind: "LeftAngleToken")]),
47+
documentation: "The opening angle bracket (`<`) of the generic parameter clause."
4648
),
4749
Child(
4850
name: "Parameters",
4951
deprecatedName: "GenericParameterList",
50-
kind: .collection(kind: .genericParameterList, collectionElementName: "Parameter", deprecatedCollectionElementName: "GenericParameter")
52+
kind: .collection(kind: .genericParameterList, collectionElementName: "Parameter", deprecatedCollectionElementName: "GenericParameter"),
53+
documentation: "The list of generic parameters in the clause."
5154
),
5255
Child(
5356
name: "GenericWhereClause",
5457
kind: .node(kind: .genericWhereClause),
58+
documentation: "A `where` clause that places additional constraints on generic parameters like `where Element: Hashable`.",
5559
isOptional: true
5660
),
5761
Child(
5862
name: "RightAngle",
5963
deprecatedName: "RightAngleBracket",
60-
kind: .token(choices: [.token(tokenKind: "RightAngleToken")])
64+
kind: .token(choices: [.token(tokenKind: "RightAngleToken")]),
65+
documentation: "The closing angle bracket (`>`) of the generic parameter clause."
6166
),
6267
]
6368
),
@@ -164,14 +169,17 @@ public let GENERIC_NODES: [Node] = [
164169
kind: .genericWhereClause,
165170
base: .syntax,
166171
nameForDiagnostics: "'where' clause",
172+
documentation: "A `where` clause that places additional constraints on generic parameters like `where Element: Hashable`.",
167173
children: [
168174
Child(
169175
name: "WhereKeyword",
170-
kind: .token(choices: [.keyword(text: "where")])
176+
kind: .token(choices: [.keyword(text: "where")]),
177+
documentation: "The `where` keyword in the clause."
171178
),
172179
Child(
173180
name: "RequirementList",
174-
kind: .collection(kind: .genericRequirementList, collectionElementName: "Requirement")
181+
kind: .collection(kind: .genericRequirementList, collectionElementName: "Requirement"),
182+
documentation: "The list of requirements in the clause."
175183
),
176184
]
177185
),

CodeGeneration/Sources/SyntaxSupport/Traits.swift

Lines changed: 51 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,12 @@ public let TRAITS: [Trait] = [
4040
Child(name: "Attributes", kind: .node(kind: .attributeList), isOptional: true),
4141
Child(name: "Modifiers", kind: .node(kind: .modifierList), isOptional: true),
4242
Child(name: "InheritanceClause", kind: .node(kind: .typeInheritanceClause), isOptional: true),
43-
Child(name: "GenericWhereClause", kind: .node(kind: .genericWhereClause), isOptional: true),
43+
Child(
44+
name: "GenericWhereClause",
45+
kind: .node(kind: .genericWhereClause),
46+
documentation: "A `where` clause that places additional constraints on generic parameters like `where Element: Hashable`.",
47+
isOptional: true
48+
),
4449
Child(name: "MemberBlock", kind: .node(kind: .memberDeclBlock)),
4550
]
4651
),
@@ -73,6 +78,23 @@ public let TRAITS: [Trait] = [
7378
Child(name: "Identifier", kind: .token(choices: [.token(tokenKind: "IdentifierToken")]))
7479
]
7580
),
81+
Trait(
82+
traitName: "MissingNode",
83+
documentation: """
84+
Represents a layout node that is missing in the source file.
85+
86+
See the types conforming to this protocol for examples of where missing nodes can occur.
87+
""",
88+
children: [
89+
Child(
90+
name: "Placeholder",
91+
kind: .token(choices: [.token(tokenKind: "IdentifierToken")]),
92+
documentation: """
93+
A placeholder, i.e. `<#placeholder#>`, that can be inserted into the source code to represent the missing node.
94+
"""
95+
)
96+
]
97+
),
7698
Trait(
7799
traitName: "Parenthesized",
78100
children: [
@@ -92,6 +114,29 @@ public let TRAITS: [Trait] = [
92114
Child(name: "Body", kind: .node(kind: .codeBlock))
93115
]
94116
),
117+
Trait(
118+
traitName: "WithGenericParameters",
119+
documentation: """
120+
Syntax nodes that have generic parameters.
121+
122+
For example, functions or nominal types like `class` or `struct` can have generic parameters \
123+
and have a generic where clause that restricts these generic parameters.
124+
""",
125+
children: [
126+
Child(
127+
name: "GenericParameterClause",
128+
kind: .node(kind: .genericParameterClause),
129+
documentation: "The parameter clause that defines the generic parameters.",
130+
isOptional: true
131+
),
132+
Child(
133+
name: "GenericWhereClause",
134+
kind: .node(kind: .genericWhereClause),
135+
documentation: "A `where` clause that places additional constraints on generic parameters like `where Element: Hashable`.",
136+
isOptional: true
137+
),
138+
]
139+
),
95140
Trait(
96141
traitName: "WithModifiers",
97142
children: [
@@ -110,21 +155,9 @@ public let TRAITS: [Trait] = [
110155
Child(name: "TrailingComma", kind: .token(choices: [.token(tokenKind: "CommaToken")]), isOptional: true)
111156
]
112157
),
113-
Trait(
114-
traitName: "MissingNode",
115-
documentation: """
116-
Represents a layout node that is missing in the source file.
117-
118-
See the types conforming to this protocol for examples of where missing nodes can occur.
119-
""",
120-
children: [
121-
Child(
122-
name: "Placeholder",
123-
kind: .token(choices: [.token(tokenKind: "IdentifierToken")]),
124-
documentation: """
125-
A placeholder, i.e. `<#placeholder#>`, that can be inserted into the source code to represent the missing node.
126-
"""
127-
)
128-
]
129-
),
130158
]
159+
160+
//==========================================================================//
161+
// IMPORTANT: If you are tempted to add a trait here please insert in in //
162+
// alphabetical order above //
163+
//==========================================================================//

CodeGeneration/Sources/SyntaxSupport/TypeNodes.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,8 @@ public let TYPE_NODES: [Node] = [
341341
Child(
342342
name: "GenericParameterClause",
343343
deprecatedName: "GenericParameters",
344-
kind: .node(kind: .genericParameterClause)
344+
kind: .node(kind: .genericParameterClause),
345+
documentation: "The parameter clause that defines the generic parameters."
345346
),
346347
Child(
347348
name: "BaseType",

Sources/SwiftSyntax/Documentation.docc/generated/SwiftSyntax.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,13 +377,14 @@ These articles are intended for developers wishing to contribute to SwiftSyntax
377377
- <doc:SwiftSyntax/EffectSpecifiersSyntax>
378378
- <doc:SwiftSyntax/FreestandingMacroExpansionSyntax>
379379
- <doc:SwiftSyntax/IdentifiedDeclSyntax>
380+
- <doc:SwiftSyntax/MissingNodeSyntax>
380381
- <doc:SwiftSyntax/ParenthesizedSyntax>
381382
- <doc:SwiftSyntax/WithAttributesSyntax>
382383
- <doc:SwiftSyntax/WithCodeBlockSyntax>
384+
- <doc:SwiftSyntax/WithGenericParametersSyntax>
383385
- <doc:SwiftSyntax/WithModifiersSyntax>
384386
- <doc:SwiftSyntax/WithStatementsSyntax>
385387
- <doc:SwiftSyntax/WithTrailingCommaSyntax>
386-
- <doc:SwiftSyntax/MissingNodeSyntax>
387388

388389

389390

0 commit comments

Comments
 (0)