Skip to content

Add syntax trait covering genericParameterClause and genericWhereClause #1903

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,7 @@ public let ATTRIBUTE_NODES: [Node] = [
name: "GenericWhereClause",
deprecatedName: "WhereClause",
kind: .node(kind: .genericWhereClause),
documentation: "A `where` clause that places additional constraints on generic parameters like `where T: Differentiable`.",
isOptional: true
),
]
Expand Down
20 changes: 20 additions & 0 deletions CodeGeneration/Sources/SyntaxSupport/DeclNodes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ public let DECL_NODES: [Node] = [
"DeclGroup",
"IdentifiedDecl",
"WithAttributes",
"WithGenericParameters",
"WithModifiers",
],
children: [
Expand Down Expand Up @@ -270,6 +271,7 @@ public let DECL_NODES: [Node] = [
name: "GenericParameterClause",
kind: .node(kind: .genericParameterClause),
nameForDiagnostics: "generic parameter clause",
documentation: "The parameter clause that defines the generic parameters.",
isOptional: true
),
Child(
Expand All @@ -282,6 +284,7 @@ public let DECL_NODES: [Node] = [
name: "GenericWhereClause",
kind: .node(kind: .genericWhereClause),
nameForDiagnostics: "generic where clause",
documentation: "A `where` clause that places additional constraints on generic parameters like `where Element: Hashable`.",
isOptional: true
),
Child(
Expand Down Expand Up @@ -416,6 +419,7 @@ public let DECL_NODES: [Node] = [
"DeclGroup",
"IdentifiedDecl",
"WithAttributes",
"WithGenericParameters",
"WithModifiers",
],
children: [
Expand Down Expand Up @@ -837,6 +841,7 @@ public let DECL_NODES: [Node] = [
"DeclGroup",
"IdentifiedDecl",
"WithAttributes",
"WithGenericParameters",
"WithModifiers",
],
children: [
Expand Down Expand Up @@ -941,6 +946,7 @@ public let DECL_NODES: [Node] = [
name: "GenericWhereClause",
kind: .node(kind: .genericWhereClause),
nameForDiagnostics: "generic where clause",
documentation: "A `where` clause that places additional constraints on generic parameters like `where Element: Hashable`.",
isOptional: true
),
Child(
Expand All @@ -957,6 +963,7 @@ public let DECL_NODES: [Node] = [
traits: [
"IdentifiedDecl",
"WithAttributes",
"WithGenericParameters",
"WithModifiers",
],
children: [
Expand Down Expand Up @@ -989,6 +996,7 @@ public let DECL_NODES: [Node] = [
name: "GenericParameterClause",
kind: .node(kind: .genericParameterClause),
nameForDiagnostics: "generic parameter clause",
documentation: "The parameter clause that defines the generic parameters.",
isOptional: true
),
Child(
Expand All @@ -1000,6 +1008,7 @@ public let DECL_NODES: [Node] = [
name: "GenericWhereClause",
kind: .node(kind: .genericWhereClause),
nameForDiagnostics: "generic where clause",
documentation: "A `where` clause that places additional constraints on generic parameters like `where Element: Hashable`.",
isOptional: true
),
Child(
Expand Down Expand Up @@ -1300,6 +1309,7 @@ public let DECL_NODES: [Node] = [
""",
traits: [
"WithAttributes",
"WithGenericParameters",
"WithModifiers",
],
children: [
Expand Down Expand Up @@ -1368,6 +1378,7 @@ public let DECL_NODES: [Node] = [
traits: [
"IdentifiedDecl",
"WithAttributes",
"WithGenericParameters",
"WithModifiers",
],
children: [
Expand Down Expand Up @@ -1395,6 +1406,7 @@ public let DECL_NODES: [Node] = [
name: "GenericParameterClause",
kind: .node(kind: .genericParameterClause),
nameForDiagnostics: "generic parameter clause",
documentation: "The parameter clause that defines the generic parameters.",
isOptional: true
),
Child(
Expand All @@ -1412,6 +1424,7 @@ public let DECL_NODES: [Node] = [
name: "GenericWhereClause",
kind: .node(kind: .genericWhereClause),
nameForDiagnostics: "generic where clause",
documentation: "A `where` clause that places additional constraints on generic parameters like `where Element: Hashable`.",
isOptional: true
),
]
Expand Down Expand Up @@ -2128,6 +2141,7 @@ public let DECL_NODES: [Node] = [
"DeclGroup",
"IdentifiedDecl",
"WithAttributes",
"WithGenericParameters",
"WithModifiers",
],
children: [
Expand Down Expand Up @@ -2191,6 +2205,7 @@ public let DECL_NODES: [Node] = [
nameForDiagnostics: "subscript",
traits: [
"WithAttributes",
"WithGenericParameters",
"WithModifiers",
],
children: [
Expand All @@ -2214,6 +2229,7 @@ public let DECL_NODES: [Node] = [
name: "GenericParameterClause",
kind: .node(kind: .genericParameterClause),
nameForDiagnostics: "generic parameter clause",
documentation: "The parameter clause that defines the generic parameters.",
isOptional: true
),
Child(
Expand All @@ -2230,6 +2246,7 @@ public let DECL_NODES: [Node] = [
name: "GenericWhereClause",
kind: .node(kind: .genericWhereClause),
nameForDiagnostics: "generic where clause",
documentation: "A `where` clause that places additional constraints on generic parameters like `where Element: Hashable`.",
isOptional: true
),
Child(
Expand Down Expand Up @@ -2295,6 +2312,7 @@ public let DECL_NODES: [Node] = [
traits: [
"IdentifiedDecl",
"WithAttributes",
"WithGenericParameters",
"WithModifiers",
],
children: [
Expand Down Expand Up @@ -2322,6 +2340,7 @@ public let DECL_NODES: [Node] = [
name: "GenericParameterClause",
kind: .node(kind: .genericParameterClause),
nameForDiagnostics: "generic parameter clause",
documentation: "The parameter clause that defines the generic parameters.",
isOptional: true
),
Child(
Expand All @@ -2332,6 +2351,7 @@ public let DECL_NODES: [Node] = [
name: "GenericWhereClause",
kind: .node(kind: .genericWhereClause),
nameForDiagnostics: "generic where clause",
documentation: "A `where` clause that places additional constraints on generic parameters like `where Element: Hashable`.",
isOptional: true
),
]
Expand Down
18 changes: 13 additions & 5 deletions CodeGeneration/Sources/SyntaxSupport/GenericNodes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,27 +37,32 @@ public let GENERIC_NODES: [Node] = [
kind: .genericParameterClause,
base: .syntax,
nameForDiagnostics: "generic parameter clause",
documentation: "The parameter clause that defines the generic parameters.",
parserFunction: "parseGenericParameters",
children: [
Child(
name: "LeftAngle",
deprecatedName: "LeftAngleBracket",
kind: .token(choices: [.token(tokenKind: "LeftAngleToken")])
kind: .token(choices: [.token(tokenKind: "LeftAngleToken")]),
documentation: "The opening angle bracket (`<`) of the generic parameter clause."
),
Child(
name: "Parameters",
deprecatedName: "GenericParameterList",
kind: .collection(kind: .genericParameterList, collectionElementName: "Parameter", deprecatedCollectionElementName: "GenericParameter")
kind: .collection(kind: .genericParameterList, collectionElementName: "Parameter", deprecatedCollectionElementName: "GenericParameter"),
documentation: "The list of generic parameters in the clause."
),
Child(
name: "GenericWhereClause",
kind: .node(kind: .genericWhereClause),
documentation: "A `where` clause that places additional constraints on generic parameters like `where Element: Hashable`.",
isOptional: true
),
Child(
name: "RightAngle",
deprecatedName: "RightAngleBracket",
kind: .token(choices: [.token(tokenKind: "RightAngleToken")])
kind: .token(choices: [.token(tokenKind: "RightAngleToken")]),
documentation: "The closing angle bracket (`>`) of the generic parameter clause."
),
]
),
Expand Down Expand Up @@ -164,14 +169,17 @@ public let GENERIC_NODES: [Node] = [
kind: .genericWhereClause,
base: .syntax,
nameForDiagnostics: "'where' clause",
documentation: "A `where` clause that places additional constraints on generic parameters like `where Element: Hashable`.",
children: [
Child(
name: "WhereKeyword",
kind: .token(choices: [.keyword(text: "where")])
kind: .token(choices: [.keyword(text: "where")]),
documentation: "The `where` keyword in the clause."
),
Child(
name: "RequirementList",
kind: .collection(kind: .genericRequirementList, collectionElementName: "Requirement")
kind: .collection(kind: .genericRequirementList, collectionElementName: "Requirement"),
documentation: "The list of requirements in the clause."
),
]
),
Expand Down
69 changes: 51 additions & 18 deletions CodeGeneration/Sources/SyntaxSupport/Traits.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,12 @@ public let TRAITS: [Trait] = [
Child(name: "Attributes", kind: .node(kind: .attributeList), isOptional: true),
Child(name: "Modifiers", kind: .node(kind: .modifierList), isOptional: true),
Child(name: "InheritanceClause", kind: .node(kind: .typeInheritanceClause), isOptional: true),
Child(name: "GenericWhereClause", kind: .node(kind: .genericWhereClause), isOptional: true),
Child(
name: "GenericWhereClause",
kind: .node(kind: .genericWhereClause),
documentation: "A `where` clause that places additional constraints on generic parameters like `where Element: Hashable`.",
isOptional: true
),
Child(name: "MemberBlock", kind: .node(kind: .memberDeclBlock)),
]
),
Expand Down Expand Up @@ -73,6 +78,23 @@ public let TRAITS: [Trait] = [
Child(name: "Identifier", kind: .token(choices: [.token(tokenKind: "IdentifierToken")]))
]
),
Trait(
traitName: "MissingNode",
documentation: """
Represents a layout node that is missing in the source file.

See the types conforming to this protocol for examples of where missing nodes can occur.
""",
children: [
Child(
name: "Placeholder",
kind: .token(choices: [.token(tokenKind: "IdentifierToken")]),
documentation: """
A placeholder, i.e. `<#placeholder#>`, that can be inserted into the source code to represent the missing node.
"""
)
]
),
Trait(
traitName: "Parenthesized",
children: [
Expand All @@ -92,6 +114,29 @@ public let TRAITS: [Trait] = [
Child(name: "Body", kind: .node(kind: .codeBlock))
]
),
Trait(
traitName: "WithGenericParameters",
documentation: """
Syntax nodes that have generic parameters.

For example, functions or nominal types like `class` or `struct` can have generic parameters \
and have a generic where clause that restricts these generic parameters.
""",
children: [
Child(
name: "GenericParameterClause",
kind: .node(kind: .genericParameterClause),
documentation: "The parameter clause that defines the generic parameters.",
isOptional: true
),
Child(
name: "GenericWhereClause",
kind: .node(kind: .genericWhereClause),
documentation: "A `where` clause that places additional constraints on generic parameters like `where Element: Hashable`.",
isOptional: true
),
]
),
Trait(
traitName: "WithModifiers",
children: [
Expand All @@ -110,21 +155,9 @@ public let TRAITS: [Trait] = [
Child(name: "TrailingComma", kind: .token(choices: [.token(tokenKind: "CommaToken")]), isOptional: true)
]
),
Trait(
traitName: "MissingNode",
documentation: """
Represents a layout node that is missing in the source file.

See the types conforming to this protocol for examples of where missing nodes can occur.
""",
children: [
Child(
name: "Placeholder",
kind: .token(choices: [.token(tokenKind: "IdentifierToken")]),
documentation: """
A placeholder, i.e. `<#placeholder#>`, that can be inserted into the source code to represent the missing node.
"""
)
]
),
]

//==========================================================================//
// IMPORTANT: If you are tempted to add a trait here please insert in in //
// alphabetical order above //
//==========================================================================//
3 changes: 2 additions & 1 deletion CodeGeneration/Sources/SyntaxSupport/TypeNodes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,8 @@ public let TYPE_NODES: [Node] = [
Child(
name: "GenericParameterClause",
deprecatedName: "GenericParameters",
kind: .node(kind: .genericParameterClause)
kind: .node(kind: .genericParameterClause),
documentation: "The parameter clause that defines the generic parameters."
),
Child(
name: "BaseType",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -377,13 +377,14 @@ These articles are intended for developers wishing to contribute to SwiftSyntax
- <doc:SwiftSyntax/EffectSpecifiersSyntax>
- <doc:SwiftSyntax/FreestandingMacroExpansionSyntax>
- <doc:SwiftSyntax/IdentifiedDeclSyntax>
- <doc:SwiftSyntax/MissingNodeSyntax>
- <doc:SwiftSyntax/ParenthesizedSyntax>
- <doc:SwiftSyntax/WithAttributesSyntax>
- <doc:SwiftSyntax/WithCodeBlockSyntax>
- <doc:SwiftSyntax/WithGenericParametersSyntax>
- <doc:SwiftSyntax/WithModifiersSyntax>
- <doc:SwiftSyntax/WithStatementsSyntax>
- <doc:SwiftSyntax/WithTrailingCommaSyntax>
- <doc:SwiftSyntax/MissingNodeSyntax>



Expand Down
Loading