Skip to content

Commit 5412040

Browse files
authored
Merge pull request #2016 from ahoppen/ahoppen/node-documentation
Add some documentation for nodes that have unintuitive behavior on first sight
2 parents b061ee5 + 4a89803 commit 5412040

File tree

7 files changed

+42
-54
lines changed

7 files changed

+42
-54
lines changed

CodeGeneration/Sources/SyntaxSupport/AttributeNodes.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,20 @@ public let ATTRIBUTE_NODES: [Node] = [
1616
kind: .attributeList,
1717
base: .syntaxCollection,
1818
nameForDiagnostics: "attributes",
19+
documentation: """
20+
A list of attributes that can be attached to a declaration.
21+
22+
An element in this collection can either be an attribute itself or an ``IfConfigDeclSyntax``
23+
that contains attributes. This is because attributes can be added conditional on compilcation
24+
conditions, for example.
25+
26+
```swift
27+
#if !DISABLE_DEPRECATIONS
28+
@available(*, deprecated)
29+
#endif
30+
func myFunction() {}
31+
```
32+
""",
1933
elementChoices: [.attribute, .ifConfigDecl]
2034
),
2135

CodeGeneration/Sources/SyntaxSupport/AvailabilityNodes.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,13 @@ public let AVAILABILITY_NODES: [Node] = [
125125
name: "Version",
126126
kind: .node(kind: .versionTuple),
127127
nameForDiagnostics: "version",
128+
documentation: """
129+
The version of this platform.
130+
131+
This parameter is optional because a custom platform alias can be specified using the `-define-availability`
132+
argument to the Swift compiler. For example, when passing `-define-availability "_iOS8Aligned:macOS 10.10, iOS 8.0"`
133+
to the Swift compiler, then `@available(_iOS8Aligned, *)` is interpreted as `@available(macOS 10.10, iOS 8.0, *)`.
134+
""",
128135
isOptional: true
129136
),
130137
]

CodeGeneration/Sources/generate-swiftsyntax/templates/swiftsyntaxbuilder/BuildableCollectionNodesFile.swift

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,8 @@ let buildableCollectionNodesFile = SourceFileSyntax(leadingTrivia: copyrightHead
2222
for node in SYNTAX_NODES.compactMap(\.collectionNode) {
2323
let elementType = node.collectionElementType
2424

25-
let docComment =
26-
node.documentation.isEmpty
27-
? [.docLineComment("/// `\(node.kind.syntaxType)` represents a collection of `\(elementType.syntaxBaseName)`")]
28-
: node.documentation
29-
// Generate collection node struct
3025
try! ExtensionDeclSyntax(
3126
"""
32-
\(docComment)
3327
extension \(raw: node.type.syntaxBaseName): ExpressibleByArrayLiteral
3428
"""
3529
) {

Sources/SwiftSyntax/Documentation.docc/Glossary.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ To avoid ongoing repetition of common long terms, SwiftSyntax uses a couple of a
1313

1414
**Expr** Abbreviation for *Expression*
1515

16+
**IfConfig** Abbrevation for *If Configuration*. Refers to `#if` clauses in the source code.
17+
1618
**Layout Node** A layout node can have an arbitrary number of children and provides structure to the syntax tree. All ``Syntax`` nodes that aren’t ``TokenSyntax`` are layout nodes. For example a ``StructDeclSyntax`` consists of, among others, of the `struct` keyword, the name and the `memberBlock`. The latter is again a layout node that contains multiple children. Layout nodes never represent any source code in the syntax tree by themselves. All source code within the syntax tree is represented by *tokens*.
1719

1820
**Node** A *layout node* or *token*

Sources/SwiftSyntax/generated/SyntaxCollections.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,19 @@ public struct ArrayElementListSyntax: SyntaxCollection, SyntaxHashable {
5656
public static let syntaxKind = SyntaxKind.arrayElementList
5757
}
5858

59+
/// A list of attributes that can be attached to a declaration.
60+
///
61+
/// An element in this collection can either be an attribute itself or an ``IfConfigDeclSyntax``
62+
/// that contains attributes. This is because attributes can be added conditional on compilcation
63+
/// conditions, for example.
64+
///
65+
/// ```swift
66+
/// #if !DISABLE_DEPRECATIONS
67+
/// @available(*, deprecated)
68+
/// #endif
69+
/// func myFunction() {}
70+
/// ```
71+
///
5972
/// ### Children
6073
///
6174
/// (``AttributeSyntax`` | ``IfConfigDeclSyntax``) `*`

Sources/SwiftSyntax/generated/syntaxNodes/SyntaxNodes.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14481,6 +14481,7 @@ public struct PlatformVersionSyntax: SyntaxProtocol, SyntaxHashable {
1448114481
/// - Parameters:
1448214482
/// - 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.
1448314483
/// - platform: The name of the OS on which the availability should be restricted or 'swift' if the availability should be restricted based on a Swift version.
14484+
/// - version: The version of this platform.
1448414485
/// - 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.
1448514486
public init(
1448614487
leadingTrivia: Trivia? = nil,
@@ -14549,6 +14550,11 @@ public struct PlatformVersionSyntax: SyntaxProtocol, SyntaxHashable {
1454914550
}
1455014551
}
1455114552

14553+
/// The version of this platform.
14554+
///
14555+
/// This parameter is optional because a custom platform alias can be specified using the `-define-availability`
14556+
/// argument to the Swift compiler. For example, when passing `-define-availability "_iOS8Aligned:macOS 10.10, iOS 8.0"`
14557+
/// to the Swift compiler, then `@available(_iOS8Aligned, *)` is interpreted as `@available(macOS 10.10, iOS 8.0, *)`.
1455214558
public var version: VersionTupleSyntax? {
1455314559
get {
1455414560
return data.child(at: 3, parent: Syntax(self)).map(VersionTupleSyntax.init)

0 commit comments

Comments
 (0)