Skip to content

Commit 65db855

Browse files
committed
Make all AdditionalTrailingClosures children non-optional
1 parent a342a69 commit 65db855

25 files changed

+124
-92
lines changed

CodeGeneration/Sources/SyntaxSupport/Child.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public enum ChildKind {
3232
/// The child always contains a node that matches one of the `choices`.
3333
case nodeChoices(choices: [Child])
3434
/// The child is a collection of `kind`.
35-
case collection(kind: SyntaxNodeKind, collectionElementName: String, deprecatedCollectionElementName: String? = nil)
35+
case collection(kind: SyntaxNodeKind, collectionElementName: String, defaultsToEmpty: Bool = false, deprecatedCollectionElementName: String? = nil)
3636
/// The child is a token that matches one of the given `choices`.
3737
/// If `requiresLeadingSpace` or `requiresTrailingSpace` is not `nil`, it
3838
/// overrides the default leading/trailing space behavior of the token.
@@ -91,7 +91,7 @@ public class Child {
9191
return kind
9292
case .nodeChoices:
9393
return .syntax
94-
case .collection(kind: let kind, _, _):
94+
case .collection(kind: let kind, _, _, _):
9595
return kind
9696
case .token:
9797
return .token
@@ -150,7 +150,7 @@ public class Child {
150150
/// Whether this child has syntax kind `UnexpectedNodes`.
151151
public var isUnexpectedNodes: Bool {
152152
switch kind {
153-
case .collection(kind: .unexpectedNodes, _, _):
153+
case .collection(kind: .unexpectedNodes, _, _, _):
154154
return true
155155
default:
156156
return false
@@ -165,7 +165,7 @@ public class Child {
165165
return choices.isEmpty
166166
case .node(let kind):
167167
return kind.isBase
168-
case .collection(let kind, _, _):
168+
case .collection(kind: let kind, _, _, _):
169169
return kind.isBase
170170
case .token:
171171
return false

CodeGeneration/Sources/SyntaxSupport/DeclNodes.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1450,8 +1450,7 @@ public let DECL_NODES: [Node] = [
14501450
),
14511451
Child(
14521452
name: "AdditionalTrailingClosures",
1453-
kind: .collection(kind: .multipleTrailingClosureElementList, collectionElementName: "AdditionalTrailingClosure"),
1454-
isOptional: true
1453+
kind: .collection(kind: .multipleTrailingClosureElementList, collectionElementName: "AdditionalTrailingClosure", defaultsToEmpty: true)
14551454
),
14561455
]
14571456
),

CodeGeneration/Sources/SyntaxSupport/ExprNodes.swift

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -828,9 +828,8 @@ public let EXPR_NODES: [Node] = [
828828
),
829829
Child(
830830
name: "AdditionalTrailingClosures",
831-
kind: .collection(kind: .multipleTrailingClosureElementList, collectionElementName: "AdditionalTrailingClosure"),
832-
nameForDiagnostics: "trailing closures",
833-
isOptional: true
831+
kind: .collection(kind: .multipleTrailingClosureElementList, collectionElementName: "AdditionalTrailingClosure", defaultsToEmpty: true),
832+
nameForDiagnostics: "trailing closures"
834833
),
835834
]
836835
),
@@ -1179,8 +1178,7 @@ public let EXPR_NODES: [Node] = [
11791178
),
11801179
Child(
11811180
name: "AdditionalTrailingClosures",
1182-
kind: .collection(kind: .multipleTrailingClosureElementList, collectionElementName: "AdditionalTrailingClosure"),
1183-
isOptional: true
1181+
kind: .collection(kind: .multipleTrailingClosureElementList, collectionElementName: "AdditionalTrailingClosure", defaultsToEmpty: true)
11841182
),
11851183
]
11861184
),
@@ -1583,9 +1581,8 @@ public let EXPR_NODES: [Node] = [
15831581
),
15841582
Child(
15851583
name: "AdditionalTrailingClosures",
1586-
kind: .collection(kind: .multipleTrailingClosureElementList, collectionElementName: "AdditionalTrailingClosure"),
1587-
nameForDiagnostics: "trailing closures",
1588-
isOptional: true
1584+
kind: .collection(kind: .multipleTrailingClosureElementList, collectionElementName: "AdditionalTrailingClosure", defaultsToEmpty: true),
1585+
nameForDiagnostics: "trailing closures"
15891586
),
15901587
]
15911588
),

CodeGeneration/Sources/SyntaxSupport/GrammarGenerator.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ struct GrammarGenerator {
3636
case .nodeChoices(let choices):
3737
let choicesDescriptions = choices.map { grammar(for: $0) }
3838
return "(\(choicesDescriptions.joined(separator: " | ")))\(optionality)"
39-
case .collection(let kind, _, _):
39+
case .collection(kind: let kind, _, _, _):
4040
return "``\(kind.syntaxType)``"
4141
case .token(let choices, _, _):
4242
if choices.count == 1 {

CodeGeneration/Sources/SyntaxSupport/Node.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ fileprivate extension Child {
345345
return [kind]
346346
case .nodeChoices(let choices):
347347
return choices.flatMap(\.kinds)
348-
case .collection(let kind, _, _):
348+
case .collection(kind: let kind, _, _, _):
349349
return [kind]
350350
case .token:
351351
return [.token]

CodeGeneration/Sources/SyntaxSupport/Traits.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public let TRAITS: [Trait] = [
6969
Child(name: "ArgumentList", kind: .node(kind: .labeledExprList)),
7070
Child(name: "RightParen", kind: .token(choices: [.token(.rightParen)]), isOptional: true),
7171
Child(name: "TrailingClosure", kind: .node(kind: .closureExpr), isOptional: true),
72-
Child(name: "AdditionalTrailingClosures", kind: .node(kind: .multipleTrailingClosureElementList), isOptional: true),
72+
Child(name: "AdditionalTrailingClosures", kind: .node(kind: .multipleTrailingClosureElementList)),
7373
]
7474
),
7575
Trait(

CodeGeneration/Sources/Utils/SyntaxBuildableChild.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public extension Child {
3333
buildableKind = .node(kind: kind)
3434
case .nodeChoices:
3535
buildableKind = .node(kind: .syntax)
36-
case .collection(let kind, _, _):
36+
case .collection(kind: let kind, _, _, _):
3737
buildableKind = .node(kind: kind)
3838
case .token:
3939
buildableKind = .token(self.tokenKind!)
@@ -65,6 +65,9 @@ public extension Child {
6565
return ExprSyntax("nil")
6666
}
6767
}
68+
if case .collection(_, _, defaultsToEmpty: true, _) = kind {
69+
return ExprSyntax("[]")
70+
}
6871
guard let token = token, isToken else {
6972
return type.defaultValue
7073
}

CodeGeneration/Sources/generate-swiftsyntax/templates/swiftsyntax/RenamedChildrenCompatibilityFile.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ let renamedChildrenCompatibilityFile = try! SourceFileSyntax(leadingTrivia: copy
3838
)
3939
if let childNode = SYNTAX_NODE_MAP[child.syntaxNodeKind]?.collectionNode,
4040
!child.isUnexpectedNodes,
41-
case .collection(_, let collectionElementName, let deprecatedCollectionElementName) = child.kind,
41+
case .collection(_, collectionElementName: let collectionElementName, _, deprecatedCollectionElementName: let deprecatedCollectionElementName) =
42+
child.kind,
4243
let deprecatedCollectionElementName
4344
{
4445
let childEltType = childNode.collectionElementType.syntaxBaseName

CodeGeneration/Sources/generate-swiftsyntax/templates/swiftsyntax/SyntaxNodesFile.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ func syntaxNode(emitKind: SyntaxNodeKind) -> SourceFileSyntax {
192192
// If needed, this could be added in the future, but for now withUnexpected should be sufficient.
193193
if let childNode = SYNTAX_NODE_MAP[child.syntaxNodeKind]?.collectionNode,
194194
!child.isUnexpectedNodes,
195-
case .collection(_, let childElt, _) = child.kind
195+
case .collection(_, collectionElementName: let childElt, _, _) = child.kind
196196
{
197197
let childEltType = childNode.collectionElementType.syntaxBaseName
198198

CodeGeneration/Tests/ValidateSyntaxNodes/ValidateSyntaxNodes.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,13 @@ fileprivate extension ChildKind {
5656
return kind == otherKind
5757
case (.nodeChoices(let choices), .nodeChoices(let otherChoices)):
5858
return choices.count == otherChoices.count && zip(choices, otherChoices).allSatisfy { $0.hasSameType(as: $1) }
59-
case (.collection(let kind, _, _), .collection(let otherKind, _, _)):
59+
case (.collection(kind: let kind, _, _, _), .collection(kind: let otherKind, _, _, _)):
6060
return kind == otherKind
6161
case (.token(let choices, _, _), .token(let otherChoices, _, _)):
6262
return choices == otherChoices
63-
case (.node(let kind), .collection(let otherKind, _, _)):
63+
case (.node(let kind), .collection(kind: let otherKind, _, _, _)):
6464
return kind == otherKind
65-
case (.collection(let kind, _, _), .node(let otherKind)):
65+
case (.collection(kind: let kind, _, _, _), .node(let otherKind)):
6666
return kind == otherKind
6767
default:
6868
return false

0 commit comments

Comments
 (0)