Skip to content

Commit a87c97a

Browse files
committed
Add more documentation do Syntax nodes
1 parent ddd05ef commit a87c97a

File tree

10 files changed

+119
-39
lines changed

10 files changed

+119
-39
lines changed

CodeGeneration/Sources/SyntaxSupport/CommonNodes.swift

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@ public let COMMON_NODES: [Node] = [
6666
children: [
6767
Child(
6868
name: "leftBrace",
69-
kind: .token(choices: [.token(.leftBrace)])
69+
kind: .token(choices: [.token(.leftBrace)]),
70+
documentation: "The brace introducing the code block."
7071
),
7172
Child(
7273
name: "statements",
@@ -75,7 +76,8 @@ public let COMMON_NODES: [Node] = [
7576
),
7677
Child(
7778
name: "rightBrace",
78-
kind: .token(choices: [.token(.rightBrace)])
79+
kind: .token(choices: [.token(.rightBrace)]),
80+
documentation: "The brace closing the code block."
7981
),
8082
]
8183
),
@@ -92,11 +94,13 @@ public let COMMON_NODES: [Node] = [
9294
Child(
9395
name: "asyncSpecifier",
9496
kind: .token(choices: [.keyword(.async)]),
97+
documentation: "The `async` keyword.",
9598
isOptional: true
9699
),
97100
Child(
98101
name: "throwsSpecifier",
99102
kind: .token(choices: [.keyword(.throws)]),
103+
documentation: "The `throws` keyword.",
100104
isOptional: true
101105
),
102106
]
@@ -114,11 +118,13 @@ public let COMMON_NODES: [Node] = [
114118
Child(
115119
name: "asyncSpecifier",
116120
kind: .token(choices: [.keyword(.async), .keyword(.reasync)]),
121+
documentation: "The `async` or `reasync` keyword.",
117122
isOptional: true
118123
),
119124
Child(
120125
name: "throwsSpecifier",
121126
kind: .token(choices: [.keyword(.throws), .keyword(.rethrows)]),
127+
documentation: "The `throws` or `rethrows` keyword.",
122128
isOptional: true
123129
),
124130
]
@@ -134,6 +140,7 @@ public let COMMON_NODES: [Node] = [
134140
Child(
135141
name: "asyncSpecifier",
136142
kind: .token(choices: [.keyword(.async)]),
143+
documentation: "The `async` keyword.",
137144
isOptional: true
138145
)
139146
]

CodeGeneration/Sources/SyntaxSupport/DeclNodes.swift

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ public let DECL_NODES: [Node] = [
5353
children: [
5454
Child(
5555
name: "leftBrace",
56-
kind: .token(choices: [.token(.leftBrace)])
56+
kind: .token(choices: [.token(.leftBrace)]),
57+
documentation: "The brace introducing the accessor block."
5758
),
5859
Child(
5960
name: "accessors",
@@ -70,7 +71,8 @@ public let DECL_NODES: [Node] = [
7071
),
7172
Child(
7273
name: "rightBrace",
73-
kind: .token(choices: [.token(.rightBrace)])
74+
kind: .token(choices: [.token(.rightBrace)]),
75+
documentation: "The brace closing the accessor block."
7476
),
7577
]
7678
),
@@ -191,16 +193,19 @@ public let DECL_NODES: [Node] = [
191193
Child(
192194
name: "modifiers",
193195
kind: .collection(kind: .declModifierList, collectionElementName: "Modifier", defaultsToEmpty: true),
194-
nameForDiagnostics: "modifiers"
196+
nameForDiagnostics: "modifiers",
197+
documentation: "Modifiers like `public` that are attached to the actor declaration."
195198
),
196199
Child(
197200
name: "actorKeyword",
198-
kind: .token(choices: [.keyword(.actor)])
201+
kind: .token(choices: [.keyword(.actor)]),
202+
documentation: "The `actor` keyword."
199203
),
200204
Child(
201205
name: "name",
202206
deprecatedName: "identifier",
203-
kind: .token(choices: [.token(.identifier)])
207+
kind: .token(choices: [.token(.identifier)]),
208+
documentation: "The name of the actor. If the name matches a reserved keyword use backticks to escape it."
204209
),
205210
Child(
206211
name: "genericParameterClause",
@@ -281,7 +286,7 @@ public let DECL_NODES: [Node] = [
281286
name: "modifiers",
282287
kind: .collection(kind: .declModifierList, collectionElementName: "Modifier", defaultsToEmpty: true),
283288
nameForDiagnostics: "modifiers",
284-
documentation: "Modifiers attached to the associated type declaration."
289+
documentation: "Modifiers like `public` that are attached to the associated type declaration."
285290
),
286291
Child(
287292
name: "associatedtypeKeyword",
@@ -371,7 +376,7 @@ public let DECL_NODES: [Node] = [
371376
name: "modifiers",
372377
kind: .collection(kind: .declModifierList, collectionElementName: "Modifier", defaultsToEmpty: true),
373378
nameForDiagnostics: "modifiers",
374-
documentation: "Modifiers attached to the class declaration, such as `public`."
379+
documentation: "Modifiers like `public` that are attached to the class declaration."
375380
),
376381
Child(
377382
name: "classKeyword",
@@ -519,7 +524,7 @@ public let DECL_NODES: [Node] = [
519524
name: "modifiers",
520525
kind: .collection(kind: .declModifierList, collectionElementName: "Modifier", defaultsToEmpty: true),
521526
nameForDiagnostics: "modifiers",
522-
documentation: "Modifiers that are attached to the deinitializer."
527+
documentation: "Modifiers like `public` that are attached to the deinitializer."
523528
),
524529
Child(
525530
name: "deinitKeyword",
@@ -857,7 +862,8 @@ public let DECL_NODES: [Node] = [
857862
Child(
858863
name: "modifiers",
859864
kind: .collection(kind: .declModifierList, collectionElementName: "Modifier", defaultsToEmpty: true),
860-
nameForDiagnostics: "modifiers"
865+
nameForDiagnostics: "modifiers",
866+
documentation: "Modifiers like `public` that are attached to the extension declaration."
861867
),
862868
Child(
863869
name: "extensionKeyword",
@@ -906,7 +912,8 @@ public let DECL_NODES: [Node] = [
906912
Child(
907913
name: "modifiers",
908914
kind: .collection(kind: .declModifierList, collectionElementName: "Modifier", defaultsToEmpty: true),
909-
nameForDiagnostics: "modifiers"
915+
nameForDiagnostics: "modifiers",
916+
documentation: "Modifiers like `public` that are attached to the function declaration."
910917
),
911918
Child(
912919
name: "funcKeyword",
@@ -1142,7 +1149,7 @@ public let DECL_NODES: [Node] = [
11421149
name: "modifiers",
11431150
kind: .collection(kind: .declModifierList, collectionElementName: "Modifier", defaultsToEmpty: true),
11441151
nameForDiagnostics: "modifiers",
1145-
documentation: "Modifiers attached to the import declaration. Currently, no modifiers are supported by Swift."
1152+
documentation: "Modifiers that are attached to the import declaration. Currently, no modifiers are supported by Swift."
11461153
),
11471154
Child(
11481155
name: "importKeyword",
@@ -1256,7 +1263,7 @@ public let DECL_NODES: [Node] = [
12561263
name: "modifiers",
12571264
kind: .collection(kind: .declModifierList, collectionElementName: "Modifier", defaultsToEmpty: true),
12581265
nameForDiagnostics: "modifiers",
1259-
documentation: "Modifiers attached to the initializer"
1266+
documentation: "Modifiers that are attached to the initializer declaration."
12601267
),
12611268
Child(
12621269
name: "initKeyword",
@@ -1289,7 +1296,7 @@ public let DECL_NODES: [Node] = [
12891296
name: "genericWhereClause",
12901297
kind: .node(kind: .genericWhereClause),
12911298
nameForDiagnostics: "generic where clause",
1292-
documentation: "If the initializer had generic parameters, a where clause that can restrict those",
1299+
documentation: "If the initializer had generic parameters, a where clause that can restrict those.",
12931300
isOptional: true
12941301
),
12951302
Child(
@@ -2110,7 +2117,7 @@ public let DECL_NODES: [Node] = [
21102117
name: "modifiers",
21112118
kind: .collection(kind: .declModifierList, collectionElementName: "Modifier", defaultsToEmpty: true),
21122119
nameForDiagnostics: "modifiers",
2113-
documentation: "Modifiers that are attached to the struct declaration."
2120+
documentation: "Modifiers like `public` that are attached to the struct declaration."
21142121
),
21152122
Child(
21162123
name: "structKeyword",
@@ -2324,7 +2331,8 @@ public let DECL_NODES: [Node] = [
23242331
Child(
23252332
name: "modifiers",
23262333
kind: .collection(kind: .declModifierList, collectionElementName: "Modifier", defaultsToEmpty: true),
2327-
nameForDiagnostics: "modifiers"
2334+
nameForDiagnostics: "modifiers",
2335+
documentation: "Modifiers modifiers applied to the variable declaration."
23282336
),
23292337
Child(
23302338
name: "bindingSpecifier",

CodeGeneration/Sources/SyntaxSupport/ExprNodes.swift

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1683,37 +1683,51 @@ public let EXPR_NODES: [Node] = [
16831683

16841684
// switch-expr -> identifier? ':'? 'switch' expr '{'
16851685
// switch-case-list '}' ';'?
1686-
//
1687-
// This node represents both a 'switch' expression, as well as a 'switch'
1688-
// statement when wrapped in an ExpressionStmt node.
16891686
Node(
16901687
kind: .switchExpr,
16911688
base: .expr,
16921689
nameForDiagnostics: "'switch' statement",
1690+
documentation: """
1691+
A `switch` expression.
1692+
1693+
This node represents both a 'switch' expression.
1694+
1695+
```swift
1696+
switch self.foo {
1697+
}
1698+
```
1699+
1700+
A switch ecpression may be declared without any cases.
1701+
""",
16931702
traits: [
16941703
"Braced"
16951704
],
16961705
children: [
16971706
Child(
16981707
name: "switchKeyword",
1699-
kind: .token(choices: [.keyword(.switch)])
1708+
kind: .token(choices: [.keyword(.switch)]),
1709+
documentation: "The `switch` keyword."
17001710
),
17011711
Child(
17021712
name: "subject",
17031713
deprecatedName: "expression",
1704-
kind: .node(kind: .expr)
1714+
kind: .node(kind: .expr),
1715+
documentation: "The expression to switch over."
17051716
),
17061717
Child(
17071718
name: "leftBrace",
1708-
kind: .token(choices: [.token(.leftBrace)])
1719+
kind: .token(choices: [.token(.leftBrace)]),
1720+
documentation: "The brace introducing the switch body."
17091721
),
17101722
Child(
17111723
name: "cases",
1712-
kind: .collection(kind: .switchCaseList, collectionElementName: "Case")
1724+
kind: .collection(kind: .switchCaseList, collectionElementName: "Case"),
1725+
documentation: "The switch's body that contains all possible cases."
17131726
),
17141727
Child(
17151728
name: "rightBrace",
1716-
kind: .token(choices: [.token(.rightBrace)])
1729+
kind: .token(choices: [.token(.rightBrace)]),
1730+
documentation: "The brace closing the switch body."
17171731
),
17181732
]
17191733
),

Sources/SwiftSyntax/generated/syntaxNodes/SyntaxNodesAB.swift

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ public struct AccessorBlockSyntax: SyntaxProtocol, SyntaxHashable, _LeafSyntaxNo
7474

7575
/// - Parameters:
7676
/// - leadingTrivia: Trivia to be prepended to the leading trivia of the node’s first token. If the node is empty, there is no token to attach the trivia to and the parameter is ignored.
77+
/// - leftBrace: The brace introducing the accessor block.
78+
/// - rightBrace: The brace closing the accessor block.
7779
/// - trailingTrivia: Trivia to be appended to the trailing trivia of the node’s last token. If the node is empty, there is no token to attach the trivia to and the parameter is ignored.
7880
public init(
7981
leadingTrivia: Trivia? = nil,
@@ -128,6 +130,7 @@ public struct AccessorBlockSyntax: SyntaxProtocol, SyntaxHashable, _LeafSyntaxNo
128130
}
129131
}
130132

133+
/// The brace introducing the accessor block.
131134
public var leftBrace: TokenSyntax {
132135
get {
133136
return Syntax(self).child(at: 1)!.cast(TokenSyntax.self)
@@ -164,6 +167,7 @@ public struct AccessorBlockSyntax: SyntaxProtocol, SyntaxHashable, _LeafSyntaxNo
164167
}
165168
}
166169

170+
/// The brace closing the accessor block.
167171
public var rightBrace: TokenSyntax {
168172
get {
169173
return Syntax(self).child(at: 5)!.cast(TokenSyntax.self)
@@ -469,6 +473,8 @@ public struct AccessorEffectSpecifiersSyntax: SyntaxProtocol, SyntaxHashable, _L
469473

470474
/// - Parameters:
471475
/// - leadingTrivia: Trivia to be prepended to the leading trivia of the node’s first token. If the node is empty, there is no token to attach the trivia to and the parameter is ignored.
476+
/// - asyncSpecifier: The `async` keyword.
477+
/// - throwsSpecifier: The `throws` keyword.
472478
/// - trailingTrivia: Trivia to be appended to the trailing trivia of the node’s last token. If the node is empty, there is no token to attach the trivia to and the parameter is ignored.
473479
public init(
474480
leadingTrivia: Trivia? = nil,
@@ -517,6 +523,7 @@ public struct AccessorEffectSpecifiersSyntax: SyntaxProtocol, SyntaxHashable, _L
517523
}
518524
}
519525

526+
/// The `async` keyword.
520527
public var asyncSpecifier: TokenSyntax? {
521528
get {
522529
return Syntax(self).child(at: 1)?.cast(TokenSyntax.self)
@@ -535,6 +542,7 @@ public struct AccessorEffectSpecifiersSyntax: SyntaxProtocol, SyntaxHashable, _L
535542
}
536543
}
537544

545+
/// The `throws` keyword.
538546
public var throwsSpecifier: TokenSyntax? {
539547
get {
540548
return Syntax(self).child(at: 3)?.cast(TokenSyntax.self)
@@ -732,6 +740,9 @@ public struct ActorDeclSyntax: DeclSyntaxProtocol, SyntaxHashable, _LeafDeclSynt
732740

733741
/// - Parameters:
734742
/// - leadingTrivia: Trivia to be prepended to the leading trivia of the node’s first token. If the node is empty, there is no token to attach the trivia to and the parameter is ignored.
743+
/// - modifiers: Modifiers like `public` that are attached to the actor declaration.
744+
/// - actorKeyword: The `actor` keyword.
745+
/// - name: The name of the actor. If the name matches a reserved keyword use backticks to escape it.
735746
/// - genericParameterClause: The parameter clause that defines the generic parameters.
736747
/// - genericWhereClause: A `where` clause that places additional constraints on generic parameters like `where Element: Hashable`.
737748
/// - trailingTrivia: Trivia to be appended to the trailing trivia of the node’s last token. If the node is empty, there is no token to attach the trivia to and the parameter is ignored.
@@ -863,6 +874,7 @@ public struct ActorDeclSyntax: DeclSyntaxProtocol, SyntaxHashable, _LeafDeclSynt
863874
}
864875
}
865876

877+
/// Modifiers like `public` that are attached to the actor declaration.
866878
public var modifiers: DeclModifierListSyntax {
867879
get {
868880
return Syntax(self).child(at: 3)!.cast(DeclModifierListSyntax.self)
@@ -908,6 +920,7 @@ public struct ActorDeclSyntax: DeclSyntaxProtocol, SyntaxHashable, _LeafDeclSynt
908920
}
909921
}
910922

923+
/// The `actor` keyword.
911924
public var actorKeyword: TokenSyntax {
912925
get {
913926
return Syntax(self).child(at: 5)!.cast(TokenSyntax.self)
@@ -926,6 +939,7 @@ public struct ActorDeclSyntax: DeclSyntaxProtocol, SyntaxHashable, _LeafDeclSynt
926939
}
927940
}
928941

942+
/// The name of the actor. If the name matches a reserved keyword use backticks to escape it.
929943
public var name: TokenSyntax {
930944
get {
931945
return Syntax(self).child(at: 7)!.cast(TokenSyntax.self)
@@ -1869,7 +1883,7 @@ public struct AssociatedTypeDeclSyntax: DeclSyntaxProtocol, SyntaxHashable, _Lea
18691883
/// - Parameters:
18701884
/// - leadingTrivia: Trivia to be prepended to the leading trivia of the node’s first token. If the node is empty, there is no token to attach the trivia to and the parameter is ignored.
18711885
/// - attributes: Attributes attached to the associated type declaration.
1872-
/// - modifiers: Modifiers attached to the associated type declaration.
1886+
/// - modifiers: Modifiers like `public` that are attached to the associated type declaration.
18731887
/// - associatedtypeKeyword: The `associatedtype` keyword for this declaration.
18741888
/// - name: The name of this associated type.
18751889
/// - inheritanceClause: The inheritance clause describing conformances for this associated type declaration.
@@ -1999,7 +2013,7 @@ public struct AssociatedTypeDeclSyntax: DeclSyntaxProtocol, SyntaxHashable, _Lea
19992013
}
20002014
}
20012015

2002-
/// Modifiers attached to the associated type declaration.
2016+
/// Modifiers like `public` that are attached to the associated type declaration.
20032017
public var modifiers: DeclModifierListSyntax {
20042018
get {
20052019
return Syntax(self).child(at: 3)!.cast(DeclModifierListSyntax.self)

Sources/SwiftSyntax/generated/syntaxNodes/SyntaxNodesC.swift

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -741,7 +741,7 @@ public struct ClassDeclSyntax: DeclSyntaxProtocol, SyntaxHashable, _LeafDeclSynt
741741
/// - Parameters:
742742
/// - leadingTrivia: Trivia to be prepended to the leading trivia of the node’s first token. If the node is empty, there is no token to attach the trivia to and the parameter is ignored.
743743
/// - attributes: Attributes attached to the class declaration, such as an `@available` attribute.
744-
/// - modifiers: Modifiers attached to the class declaration, such as `public`.
744+
/// - modifiers: Modifiers like `public` that are attached to the class declaration.
745745
/// - classKeyword: The `class` keyword for this declaration.
746746
/// - name: The name of the class.
747747
/// - genericParameterClause: The generic parameters, if any, of the class declaration.
@@ -878,7 +878,7 @@ public struct ClassDeclSyntax: DeclSyntaxProtocol, SyntaxHashable, _LeafDeclSynt
878878
}
879879
}
880880

881-
/// Modifiers attached to the class declaration, such as `public`.
881+
/// Modifiers like `public` that are attached to the class declaration.
882882
public var modifiers: DeclModifierListSyntax {
883883
get {
884884
return Syntax(self).child(at: 3)!.cast(DeclModifierListSyntax.self)
@@ -3013,6 +3013,8 @@ public struct CodeBlockSyntax: SyntaxProtocol, SyntaxHashable, _LeafSyntaxNodePr
30133013

30143014
/// - Parameters:
30153015
/// - leadingTrivia: Trivia to be prepended to the leading trivia of the node’s first token. If the node is empty, there is no token to attach the trivia to and the parameter is ignored.
3016+
/// - leftBrace: The brace introducing the code block.
3017+
/// - rightBrace: The brace closing the code block.
30163018
/// - trailingTrivia: Trivia to be appended to the trailing trivia of the node’s last token. If the node is empty, there is no token to attach the trivia to and the parameter is ignored.
30173019
public init(
30183020
leadingTrivia: Trivia? = nil,
@@ -3067,6 +3069,7 @@ public struct CodeBlockSyntax: SyntaxProtocol, SyntaxHashable, _LeafSyntaxNodePr
30673069
}
30683070
}
30693071

3072+
/// The brace introducing the code block.
30703073
public var leftBrace: TokenSyntax {
30713074
get {
30723075
return Syntax(self).child(at: 1)!.cast(TokenSyntax.self)
@@ -3130,6 +3133,7 @@ public struct CodeBlockSyntax: SyntaxProtocol, SyntaxHashable, _LeafSyntaxNodePr
31303133
}
31313134
}
31323135

3136+
/// The brace closing the code block.
31333137
public var rightBrace: TokenSyntax {
31343138
get {
31353139
return Syntax(self).child(at: 5)!.cast(TokenSyntax.self)

0 commit comments

Comments
 (0)