Skip to content

Commit 9a4c5e4

Browse files
authored
Merge pull request #1630 from whiteio/whiteio/add-syntax-node-documentation
Add documentation for syntax nodes and their children
2 parents 36b0f23 + f33f43a commit 9a4c5e4

File tree

4 files changed

+211
-18
lines changed

4 files changed

+211
-18
lines changed

CodeGeneration/Sources/SyntaxSupport/DeclNodes.swift

Lines changed: 102 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,31 @@ public let DECL_NODES: [Node] = [
209209
Node(
210210
name: "AssociatedtypeDecl",
211211
nameForDiagnostics: "associatedtype declaration",
212+
description: """
213+
An associated type declaration like the following.
214+
215+
```swift
216+
associatedtype Item
217+
```
218+
219+
An associated type declaration may contain a type initializer clause which represents a default type assignment for the associated type.
220+
221+
```swift
222+
associatedtype Item = Int
223+
```
224+
225+
An associated type declaration may be declared with an inheritance clause which specifies the required conformances.
226+
227+
```swift
228+
associatedtype Iterator: IteratorProtocol
229+
```
230+
231+
A generic where clause may be present, here is an example which shows an associated type containing an inheritance clauses and a generic where clause.
232+
233+
```swift
234+
associatedtype Iterator: IteratorProtocol where Iterator.Element == Item
235+
```
236+
""",
212237
kind: "Decl",
213238
traits: [
214239
"IdentifiedDecl",
@@ -219,37 +244,44 @@ public let DECL_NODES: [Node] = [
219244
name: "Attributes",
220245
kind: .collection(kind: "AttributeList", collectionElementName: "Attribute"),
221246
nameForDiagnostics: "attributes",
247+
description: "Attributes attached to the associated type declaration.",
222248
isOptional: true
223249
),
224250
Child(
225251
name: "Modifiers",
226252
kind: .collection(kind: "ModifierList", collectionElementName: "Modifier"),
227253
nameForDiagnostics: "modifiers",
254+
description: "Modifiers attached to the associated type declaration.",
228255
isOptional: true
229256
),
230257
Child(
231258
name: "AssociatedtypeKeyword",
232-
kind: .token(choices: [.keyword(text: "associatedtype")])
259+
kind: .token(choices: [.keyword(text: "associatedtype")]),
260+
description: "The `associatedtype` keyword for this declaration."
233261
),
234262
Child(
235263
name: "Identifier",
236-
kind: .token(choices: [.token(tokenKind: "IdentifierToken")])
264+
kind: .token(choices: [.token(tokenKind: "IdentifierToken")]),
265+
description: "The name of this associated type."
237266
),
238267
Child(
239268
name: "InheritanceClause",
240269
kind: .node(kind: "TypeInheritanceClause"),
241270
nameForDiagnostics: "inheritance clause",
271+
description: "The inheritance clause describing conformances for this associated type declaration.",
242272
isOptional: true
243273
),
244274
Child(
245275
name: "Initializer",
246276
kind: .node(kind: "TypeInitializerClause"),
277+
description: "The type initializer clause for this associated type declaration which represents a default type assignment for the associated type.",
247278
isOptional: true
248279
),
249280
Child(
250281
name: "GenericWhereClause",
251282
kind: .node(kind: "GenericWhereClause"),
252283
nameForDiagnostics: "generic where clause",
284+
description: "The `where` clause that applies to the generic parameters of this associated type declaration.",
253285
isOptional: true
254286
),
255287
]
@@ -265,6 +297,29 @@ public let DECL_NODES: [Node] = [
265297
Node(
266298
name: "ClassDecl",
267299
nameForDiagnostics: "class",
300+
description: """
301+
A class declaration like the following.
302+
303+
```swift
304+
class SomeClass {
305+
let someMember: String
306+
307+
init(someMember: String) {
308+
self.someMember = someMember
309+
}
310+
311+
func foo() {
312+
print(someMember)
313+
}
314+
315+
static func bar() -> Int {
316+
return 1
317+
}
318+
}
319+
```
320+
321+
A class declaration may be declared without any members.
322+
""",
268323
kind: "Decl",
269324
traits: [
270325
"DeclGroup",
@@ -276,43 +331,51 @@ public let DECL_NODES: [Node] = [
276331
name: "Attributes",
277332
kind: .collection(kind: "AttributeList", collectionElementName: "Attribute"),
278333
nameForDiagnostics: "attributes",
334+
description: "Attributes attached to the class declaration, such as an `@available` attribute.",
279335
isOptional: true
280336
),
281337
Child(
282338
name: "Modifiers",
283339
kind: .collection(kind: "ModifierList", collectionElementName: "Modifier"),
284340
nameForDiagnostics: "modifiers",
341+
description: "Modifiers attached to the class declaration, such as `public`.",
285342
isOptional: true
286343
),
287344
Child(
288345
name: "ClassKeyword",
289-
kind: .token(choices: [.keyword(text: "class")])
346+
kind: .token(choices: [.keyword(text: "class")]),
347+
description: "The `class` keyword for this declaration."
290348
),
291349
Child(
292350
name: "Identifier",
293-
kind: .token(choices: [.token(tokenKind: "IdentifierToken")])
351+
kind: .token(choices: [.token(tokenKind: "IdentifierToken")]),
352+
description: "The name of the class."
294353
),
295354
Child(
296355
name: "GenericParameterClause",
297356
kind: .node(kind: "GenericParameterClause"),
298357
nameForDiagnostics: "generic parameter clause",
358+
description: "The generic parameters, if any, of the class declaration.",
299359
isOptional: true
300360
),
301361
Child(
302362
name: "InheritanceClause",
303363
kind: .node(kind: "TypeInheritanceClause"),
304364
nameForDiagnostics: "inheritance clause",
365+
description: "The inheritance clause describing one or more conformances for this class declaration.",
305366
isOptional: true
306367
),
307368
Child(
308369
name: "GenericWhereClause",
309370
kind: .node(kind: "GenericWhereClause"),
310371
nameForDiagnostics: "generic where clause",
372+
description: "The `where` clause that applies to the generic parameters of this class declaration.",
311373
isOptional: true
312374
),
313375
Child(
314376
name: "MemberBlock",
315-
kind: .node(kind: "MemberDeclBlock")
377+
kind: .node(kind: "MemberDeclBlock"),
378+
description: "The members of the class declaration. As class extension declarations may declare additional members, the contents of this member block isn't guaranteed to be a complete list of members for this type."
316379
),
317380
]
318381
),
@@ -992,6 +1055,13 @@ public let DECL_NODES: [Node] = [
9921055
Node(
9931056
name: "ImportDecl",
9941057
nameForDiagnostics: "import",
1058+
description: """
1059+
An import declaration like the following.
1060+
1061+
```swift
1062+
import Foundation
1063+
```
1064+
""",
9951065
kind: "Decl",
9961066
traits: [
9971067
"Attributed"
@@ -1001,26 +1071,31 @@ public let DECL_NODES: [Node] = [
10011071
name: "Attributes",
10021072
kind: .collection(kind: "AttributeList", collectionElementName: "Attribute"),
10031073
nameForDiagnostics: "attributes",
1074+
description: "Attributes attached to the import declaration, for example `@testable`.",
10041075
isOptional: true
10051076
),
10061077
Child(
10071078
name: "Modifiers",
10081079
kind: .collection(kind: "ModifierList", collectionElementName: "Modifier"),
10091080
nameForDiagnostics: "modifiers",
1081+
description: "Modifiers attached to the import declaration. Currently, no modifiers are supported by Swift.",
10101082
isOptional: true
10111083
),
10121084
Child(
10131085
name: "ImportTok",
1014-
kind: .token(choices: [.keyword(text: "import")])
1086+
kind: .token(choices: [.keyword(text: "import")]),
1087+
description: "The `import` keyword for this declaration."
10151088
),
10161089
Child(
10171090
name: "ImportKind",
10181091
kind: .token(choices: [.keyword(text: "typealias"), .keyword(text: "struct"), .keyword(text: "class"), .keyword(text: "enum"), .keyword(text: "protocol"), .keyword(text: "var"), .keyword(text: "let"), .keyword(text: "func"), .keyword(text: "inout")]),
1092+
description: "The kind of declaration being imported. For example, a struct can be imported from a specific module.",
10191093
isOptional: true
10201094
),
10211095
Child(
10221096
name: "Path",
1023-
kind: .collection(kind: "AccessPath", collectionElementName: "PathComponent")
1097+
kind: .collection(kind: "AccessPath", collectionElementName: "PathComponent"),
1098+
description: "The path to the module, submodule or symbol being imported."
10241099
),
10251100
]
10261101
),
@@ -1715,6 +1790,15 @@ public let DECL_NODES: [Node] = [
17151790
Node(
17161791
name: "ProtocolDecl",
17171792
nameForDiagnostics: "protocol",
1793+
description: """
1794+
A protocol declaration like the following.
1795+
1796+
```swift
1797+
protocol Example {
1798+
var isValid: Bool { get }
1799+
}
1800+
```
1801+
""",
17181802
kind: "Decl",
17191803
traits: [
17201804
"DeclGroup",
@@ -1726,43 +1810,51 @@ public let DECL_NODES: [Node] = [
17261810
name: "Attributes",
17271811
kind: .collection(kind: "AttributeList", collectionElementName: "Attribute"),
17281812
nameForDiagnostics: "attributes",
1813+
description: "Attributes attached to the protocol declaration, such as an `@available` attribute.",
17291814
isOptional: true
17301815
),
17311816
Child(
17321817
name: "Modifiers",
17331818
kind: .collection(kind: "ModifierList", collectionElementName: "Modifier"),
17341819
nameForDiagnostics: "modifiers",
1820+
description: "Modifiers attached to the protocol declaration, such as `public`.",
17351821
isOptional: true
17361822
),
17371823
Child(
17381824
name: "ProtocolKeyword",
1739-
kind: .token(choices: [.keyword(text: "protocol")])
1825+
kind: .token(choices: [.keyword(text: "protocol")]),
1826+
description: "The `protocol` keyword for this declaration."
17401827
),
17411828
Child(
17421829
name: "Identifier",
1743-
kind: .token(choices: [.token(tokenKind: "IdentifierToken")])
1830+
kind: .token(choices: [.token(tokenKind: "IdentifierToken")]),
1831+
description: "The name of the protocol."
17441832
),
17451833
Child(
17461834
name: "PrimaryAssociatedTypeClause",
17471835
kind: .node(kind: "PrimaryAssociatedTypeClause"),
17481836
nameForDiagnostics: "primary associated type clause",
1837+
description: "The primary associated type for the protocol.",
17491838
isOptional: true
17501839
),
17511840
Child(
17521841
name: "InheritanceClause",
17531842
kind: .node(kind: "TypeInheritanceClause"),
17541843
nameForDiagnostics: "inheritance clause",
1844+
description: "The inheritance clause describing one or more conformances for this protocol declaration.",
17551845
isOptional: true
17561846
),
17571847
Child(
17581848
name: "GenericWhereClause",
17591849
kind: .node(kind: "GenericWhereClause"),
17601850
nameForDiagnostics: "generic where clause",
1851+
description: "The `where` clause that applies to the generic parameters of this protocol declaration.",
17611852
isOptional: true
17621853
),
17631854
Child(
17641855
name: "MemberBlock",
1765-
kind: .node(kind: "MemberDeclBlock")
1856+
kind: .node(kind: "MemberDeclBlock"),
1857+
description: "The members of the protocol declaration."
17661858
),
17671859
]
17681860
),

CodeGeneration/Sources/SyntaxSupport/ExprNodes.swift

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -905,19 +905,31 @@ public let EXPR_NODES: [Node] = [
905905
Node(
906906
name: "IsExpr",
907907
nameForDiagnostics: "'is'",
908+
description: """
909+
An `is` expression like the following.
910+
911+
```swift
912+
value is Double
913+
```
914+
915+
This node is only generated after operators are folded using the `SwiftOperators` library. Beforehand, the parser does not know the precedences of operators and thus represents `is` by an `UnresolvedIsExpr`.
916+
""",
908917
kind: "Expr",
909918
children: [
910919
Child(
911920
name: "Expression",
912-
kind: .node(kind: "Expr")
921+
kind: .node(kind: "Expr"),
922+
description: "The expression which will be checked to determine whether it can be cast to a specific type."
913923
),
914924
Child(
915925
name: "IsTok",
916-
kind: .token(choices: [.keyword(text: "is")])
926+
kind: .token(choices: [.keyword(text: "is")]),
927+
description: "The `is` keyword for this expression."
917928
),
918929
Child(
919930
name: "TypeName",
920-
kind: .node(kind: "Type")
931+
kind: .node(kind: "Type"),
932+
description: "The type against which the expression will be checked to see if the expression can be cast to it."
921933
),
922934
]
923935
),

0 commit comments

Comments
 (0)