Skip to content

Commit

Permalink
Make all AttributeListSyntax children non-optional
Browse files Browse the repository at this point in the history
  • Loading branch information
ahoppen committed Aug 9, 2023
1 parent d1f9b4b commit ad6817e
Show file tree
Hide file tree
Showing 32 changed files with 428 additions and 430 deletions.
5 changes: 2 additions & 3 deletions CodeGeneration/Sources/SyntaxSupport/CommonNodes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,8 @@ public let COMMON_NODES: [Node] = [
children: [
Child(
name: "Attributes",
kind: .collection(kind: .attributeList, collectionElementName: "Attribute"),
documentation: "If there were standalone attributes without a declaration to attach them to, the ``MissingDeclSyntax`` will contain these.",
isOptional: true
kind: .collection(kind: .attributeList, collectionElementName: "Attribute", defaultsToEmpty: true),
documentation: "If there were standalone attributes without a declaration to attach them to, the ``MissingDeclSyntax`` will contain these."
),
Child(
name: "Modifiers",
Expand Down
105 changes: 42 additions & 63 deletions CodeGeneration/Sources/SyntaxSupport/DeclNodes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,8 @@ public let DECL_NODES: [Node] = [
children: [
Child(
name: "Attributes",
kind: .collection(kind: .attributeList, collectionElementName: "Attribute"),
nameForDiagnostics: "attributes",
isOptional: true
kind: .collection(kind: .attributeList, collectionElementName: "Attribute", defaultsToEmpty: true),
nameForDiagnostics: "attributes"
),
Child(
name: "Modifier",
Expand Down Expand Up @@ -186,9 +185,8 @@ public let DECL_NODES: [Node] = [
children: [
Child(
name: "Attributes",
kind: .collection(kind: .attributeList, collectionElementName: "Attribute"),
nameForDiagnostics: "attributes",
isOptional: true
kind: .collection(kind: .attributeList, collectionElementName: "Attribute", defaultsToEmpty: true),
nameForDiagnostics: "attributes"
),
Child(
name: "Modifiers",
Expand Down Expand Up @@ -275,10 +273,9 @@ public let DECL_NODES: [Node] = [
children: [
Child(
name: "Attributes",
kind: .collection(kind: .attributeList, collectionElementName: "Attribute"),
kind: .collection(kind: .attributeList, collectionElementName: "Attribute", defaultsToEmpty: true),
nameForDiagnostics: "attributes",
documentation: "Attributes attached to the associated type declaration.",
isOptional: true
documentation: "Attributes attached to the associated type declaration."
),
Child(
name: "Modifiers",
Expand Down Expand Up @@ -366,10 +363,9 @@ public let DECL_NODES: [Node] = [
children: [
Child(
name: "Attributes",
kind: .collection(kind: .attributeList, collectionElementName: "Attribute"),
kind: .collection(kind: .attributeList, collectionElementName: "Attribute", defaultsToEmpty: true),
nameForDiagnostics: "attributes",
documentation: "Attributes attached to the class declaration, such as an `@available` attribute.",
isOptional: true
documentation: "Attributes attached to the class declaration, such as an `@available` attribute."
),
Child(
name: "Modifiers",
Expand Down Expand Up @@ -515,10 +511,9 @@ public let DECL_NODES: [Node] = [
children: [
Child(
name: "Attributes",
kind: .collection(kind: .attributeList, collectionElementName: "Attribute"),
kind: .collection(kind: .attributeList, collectionElementName: "Attribute", defaultsToEmpty: true),
nameForDiagnostics: "attributes",
documentation: "Attributes that are attached to the deinitializer.",
isOptional: true
documentation: "Attributes that are attached to the deinitializer."
),
Child(
name: "Modifiers",
Expand Down Expand Up @@ -584,9 +579,8 @@ public let DECL_NODES: [Node] = [
children: [
Child(
name: "Attributes",
kind: .collection(kind: .attributeList, collectionElementName: "Attribute"),
documentation: "If there were attributes before the editor placeholder, the ``EditorPlaceholderDeclSyntax`` will contain these.",
isOptional: true
kind: .collection(kind: .attributeList, collectionElementName: "Attribute", defaultsToEmpty: true),
documentation: "If there were attributes before the editor placeholder, the ``EditorPlaceholderDeclSyntax`` will contain these."
),
Child(
name: "Modifiers",
Expand Down Expand Up @@ -702,10 +696,9 @@ public let DECL_NODES: [Node] = [
children: [
Child(
name: "Attributes",
kind: .collection(kind: .attributeList, collectionElementName: "Attribute"),
kind: .collection(kind: .attributeList, collectionElementName: "Attribute", defaultsToEmpty: true),
nameForDiagnostics: "attributes",
documentation: "The attributes applied to the case declaration.",
isOptional: true
documentation: "The attributes applied to the case declaration."
),
Child(
name: "Modifiers",
Expand Down Expand Up @@ -788,10 +781,9 @@ public let DECL_NODES: [Node] = [
children: [
Child(
name: "Attributes",
kind: .collection(kind: .attributeList, collectionElementName: "Attribute"),
kind: .collection(kind: .attributeList, collectionElementName: "Attribute", defaultsToEmpty: true),
nameForDiagnostics: "attributes",
documentation: "The attributes applied to the enum declaration.",
isOptional: true
documentation: "The attributes applied to the enum declaration."
),
Child(
name: "Modifiers",
Expand Down Expand Up @@ -859,9 +851,8 @@ public let DECL_NODES: [Node] = [
children: [
Child(
name: "Attributes",
kind: .collection(kind: .attributeList, collectionElementName: "Attribute"),
nameForDiagnostics: "attributes",
isOptional: true
kind: .collection(kind: .attributeList, collectionElementName: "Attribute", defaultsToEmpty: true),
nameForDiagnostics: "attributes"
),
Child(
name: "Modifiers",
Expand Down Expand Up @@ -909,9 +900,8 @@ public let DECL_NODES: [Node] = [
children: [
Child(
name: "Attributes",
kind: .collection(kind: .attributeList, collectionElementName: "Attribute"),
nameForDiagnostics: "attributes",
isOptional: true
kind: .collection(kind: .attributeList, collectionElementName: "Attribute", defaultsToEmpty: true),
nameForDiagnostics: "attributes"
),
Child(
name: "Modifiers",
Expand Down Expand Up @@ -978,9 +968,8 @@ public let DECL_NODES: [Node] = [
children: [
Child(
name: "Attributes",
kind: .collection(kind: .attributeList, collectionElementName: "Attribute"),
nameForDiagnostics: "attributes",
isOptional: true
kind: .collection(kind: .attributeList, collectionElementName: "Attribute", defaultsToEmpty: true),
nameForDiagnostics: "attributes"
),
Child(
name: "Modifiers",
Expand Down Expand Up @@ -1145,10 +1134,9 @@ public let DECL_NODES: [Node] = [
children: [
Child(
name: "Attributes",
kind: .collection(kind: .attributeList, collectionElementName: "Attribute"),
kind: .collection(kind: .attributeList, collectionElementName: "Attribute", defaultsToEmpty: true),
nameForDiagnostics: "attributes",
documentation: "Attributes attached to the import declaration, for example `@testable`.",
isOptional: true
documentation: "Attributes attached to the import declaration, for example `@testable`."
),
Child(
name: "Modifiers",
Expand Down Expand Up @@ -1260,10 +1248,9 @@ public let DECL_NODES: [Node] = [
children: [
Child(
name: "Attributes",
kind: .collection(kind: .attributeList, collectionElementName: "Attribute"),
kind: .collection(kind: .attributeList, collectionElementName: "Attribute", defaultsToEmpty: true),
nameForDiagnostics: "attributes",
documentation: "Attributes that are attached to the initializer.",
isOptional: true
documentation: "Attributes that are attached to the initializer."
),
Child(
name: "Modifiers",
Expand Down Expand Up @@ -1328,9 +1315,8 @@ public let DECL_NODES: [Node] = [
children: [
Child(
name: "Attributes",
kind: .collection(kind: .attributeList, collectionElementName: "Attribute"),
nameForDiagnostics: "attributes",
isOptional: true
kind: .collection(kind: .attributeList, collectionElementName: "Attribute", defaultsToEmpty: true),
nameForDiagnostics: "attributes"
),
Child(
name: "Modifiers",
Expand Down Expand Up @@ -1387,9 +1373,8 @@ public let DECL_NODES: [Node] = [
children: [
Child(
name: "Attributes",
kind: .collection(kind: .attributeList, collectionElementName: "Attribute"),
nameForDiagnostics: "attributes",
isOptional: true
kind: .collection(kind: .attributeList, collectionElementName: "Attribute", defaultsToEmpty: true),
nameForDiagnostics: "attributes"
),
Child(
name: "Modifiers",
Expand Down Expand Up @@ -1827,10 +1812,9 @@ public let DECL_NODES: [Node] = [
children: [
Child(
name: "Attributes",
kind: .collection(kind: .attributeList, collectionElementName: "Attribute"),
kind: .collection(kind: .attributeList, collectionElementName: "Attribute", defaultsToEmpty: true),
nameForDiagnostics: "attributes",
documentation: "The attributes applied to the 'precedencegroup' declaration.",
isOptional: true
documentation: "The attributes applied to the 'precedencegroup' declaration."
),
Child(
name: "Modifiers",
Expand Down Expand Up @@ -1943,10 +1927,9 @@ public let DECL_NODES: [Node] = [
children: [
Child(
name: "Attributes",
kind: .collection(kind: .attributeList, collectionElementName: "Attribute"),
kind: .collection(kind: .attributeList, collectionElementName: "Attribute", defaultsToEmpty: true),
nameForDiagnostics: "attributes",
documentation: "Attributes attached to the protocol declaration, such as an `@available` attribute.",
isOptional: true
documentation: "Attributes attached to the protocol declaration, such as an `@available` attribute."
),
Child(
name: "Modifiers",
Expand Down Expand Up @@ -2114,10 +2097,9 @@ public let DECL_NODES: [Node] = [
children: [
Child(
name: "Attributes",
kind: .collection(kind: .attributeList, collectionElementName: "Attribute"),
kind: .collection(kind: .attributeList, collectionElementName: "Attribute", defaultsToEmpty: true),
nameForDiagnostics: "attributes",
documentation: "Attributes that are attached to the struct declaration.",
isOptional: true
documentation: "Attributes that are attached to the struct declaration."
),
Child(
name: "Modifiers",
Expand Down Expand Up @@ -2178,9 +2160,8 @@ public let DECL_NODES: [Node] = [
children: [
Child(
name: "Attributes",
kind: .collection(kind: .attributeList, collectionElementName: "Attribute"),
nameForDiagnostics: "attributes",
isOptional: true
kind: .collection(kind: .attributeList, collectionElementName: "Attribute", defaultsToEmpty: true),
nameForDiagnostics: "attributes"
),
Child(
name: "Modifiers",
Expand Down Expand Up @@ -2277,9 +2258,8 @@ public let DECL_NODES: [Node] = [
children: [
Child(
name: "Attributes",
kind: .collection(kind: .attributeList, collectionElementName: "Attribute"),
nameForDiagnostics: "attributes",
isOptional: true
kind: .collection(kind: .attributeList, collectionElementName: "Attribute", defaultsToEmpty: true),
nameForDiagnostics: "attributes"
),
Child(
name: "Modifiers",
Expand Down Expand Up @@ -2333,9 +2313,8 @@ public let DECL_NODES: [Node] = [
children: [
Child(
name: "Attributes",
kind: .collection(kind: .attributeList, collectionElementName: "Attribute"),
nameForDiagnostics: "attributes",
isOptional: true
kind: .collection(kind: .attributeList, collectionElementName: "Attribute", defaultsToEmpty: true),
nameForDiagnostics: "attributes"
),
Child(
name: "Modifiers",
Expand Down
10 changes: 4 additions & 6 deletions CodeGeneration/Sources/SyntaxSupport/ExprNodes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -373,9 +373,8 @@ public let EXPR_NODES: [Node] = [
children: [
Child(
name: "Attributes",
kind: .collection(kind: .attributeList, collectionElementName: "Attribute"),
nameForDiagnostics: "attributes",
isOptional: true
kind: .collection(kind: .attributeList, collectionElementName: "Attribute", defaultsToEmpty: true),
nameForDiagnostics: "attributes"
),
Child(
name: "Modifiers",
Expand Down Expand Up @@ -525,9 +524,8 @@ public let EXPR_NODES: [Node] = [
children: [
Child(
name: "Attributes",
kind: .collection(kind: .attributeList, collectionElementName: "Attribute"),
nameForDiagnostics: "attributes",
isOptional: true
kind: .collection(kind: .attributeList, collectionElementName: "Attribute", defaultsToEmpty: true),
nameForDiagnostics: "attributes"
),
Child(
name: "Capture",
Expand Down
3 changes: 1 addition & 2 deletions CodeGeneration/Sources/SyntaxSupport/GenericNodes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,7 @@ public let GENERIC_NODES: [Node] = [
children: [
Child(
name: "Attributes",
kind: .collection(kind: .attributeList, collectionElementName: "Attribute"),
isOptional: true
kind: .collection(kind: .attributeList, collectionElementName: "Attribute", defaultsToEmpty: true)
),
Child(
name: "EachKeyword",
Expand Down
4 changes: 2 additions & 2 deletions CodeGeneration/Sources/SyntaxSupport/Traits.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public let TRAITS: [Trait] = [
Trait(
traitName: "DeclGroup",
children: [
Child(name: "Attributes", kind: .node(kind: .attributeList), isOptional: true),
Child(name: "Attributes", kind: .node(kind: .attributeList)),
Child(name: "Modifiers", kind: .node(kind: .declModifierList)),
Child(name: "InheritanceClause", kind: .node(kind: .inheritanceClause), isOptional: true),
Child(
Expand Down Expand Up @@ -105,7 +105,7 @@ public let TRAITS: [Trait] = [
Trait(
traitName: "WithAttributes",
children: [
Child(name: "Attributes", kind: .node(kind: .attributeList), isOptional: true)
Child(name: "Attributes", kind: .node(kind: .attributeList))
]
),
Trait(
Expand Down
3 changes: 1 addition & 2 deletions CodeGeneration/Sources/SyntaxSupport/TypeNodes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,7 @@ public let TYPE_NODES: [Node] = [
),
Child(
name: "Attributes",
kind: .collection(kind: .attributeList, collectionElementName: "Attribute"),
isOptional: true
kind: .collection(kind: .attributeList, collectionElementName: "Attribute", defaultsToEmpty: true)
),
Child(
name: "BaseType",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,15 @@ let parserEntryFile = SourceFileSyntax(leadingTrivia: copyrightHeader) {
// The missing item is not necessary to be a declaration,
// which is just a placeholder here
return RawCodeBlockItemSyntax(
item: .decl(RawDeclSyntax(RawMissingDeclSyntax(attributes: nil, modifiers: self.emptyCollection(RawDeclModifierListSyntax.self), arena: self.arena))),
item: .decl(
RawDeclSyntax(
RawMissingDeclSyntax(
attributes: self.emptyCollection(RawAttributeListSyntax.self),
modifiers: self.emptyCollection(RawDeclModifierListSyntax.self),
arena: self.arena
)
)
),
semicolon: nil,
arena: self.arena
)
Expand Down
4 changes: 2 additions & 2 deletions Sources/SwiftParser/Attributes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
@_spi(RawSyntax) import SwiftSyntax

extension Parser {
mutating func parseAttributeList() -> RawAttributeListSyntax? {
mutating func parseAttributeList() -> RawAttributeListSyntax {
guard self.at(.atSign, .poundIf) else {
return nil
return self.emptyCollection(RawAttributeListSyntax.self)
}

var elements = [RawAttributeListSyntax.Element]()
Expand Down
7 changes: 3 additions & 4 deletions Sources/SwiftParser/CollectionNodes+Parsable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ extension AccessorDeclListSyntax: SyntaxParseable {
return parser.parseAccessorList() ?? RawAccessorDeclListSyntax(elements: [], arena: parser.arena)
} makeMissing: { remainingTokens, arena in
return RawAccessorDeclSyntax(
attributes: nil,
attributes: RawAttributeListSyntax(elements: [], arena: arena),
modifier: nil,
accessorSpecifier: RawTokenSyntax(missing: .keyword, text: "get", arena: arena),
parameters: nil,
Expand All @@ -73,8 +73,7 @@ extension AccessorDeclListSyntax: SyntaxParseable {
extension AttributeListSyntax: SyntaxParseable {
public static func parse(from parser: inout Parser) -> Self {
return parse(from: &parser) { parser in
let node = parser.parseAttributeList() ?? RawAttributeListSyntax(elements: [], arena: parser.arena)
return RawSyntax(node)
return RawSyntax(parser.parseAttributeList())
} makeMissing: { remainingTokens, arena in
return RawAttributeSyntax(
atSign: RawTokenSyntax(missing: .atSign, arena: arena),
Expand Down Expand Up @@ -106,7 +105,7 @@ extension MemberBlockItemListSyntax: SyntaxParseable {
return RawSyntax(parser.parseMemberDeclList())
} makeMissing: { remainingTokens, arena in
let missingDecl = RawMissingDeclSyntax(
attributes: nil,
attributes: RawAttributeListSyntax(elements: [], arena: arena),
modifiers: RawDeclModifierListSyntax(elements: [], arena: arena),
placeholder: RawTokenSyntax(missing: .identifier, text: "<#declaration#>", arena: arena),
RawUnexpectedNodesSyntax(remainingTokens, arena: arena),
Expand Down
Loading

0 comments on commit ad6817e

Please sign in to comment.