Skip to content

Replace string-based keyword references with Keyword enum in CodeGeneration #2056

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
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
54 changes: 27 additions & 27 deletions CodeGeneration/Sources/SyntaxSupport/AttributeNodes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ public let ATTRIBUTE_NODES: [Node] = [
Child(
name: "availabilityLabel",
deprecatedName: "label",
kind: .token(choices: [.keyword(text: "availability")]),
kind: .token(choices: [.keyword(.availability)]),
nameForDiagnostics: "label",
documentation: "The label of the argument"
),
Expand Down Expand Up @@ -241,7 +241,7 @@ public let ATTRIBUTE_NODES: [Node] = [
children: [
Child(
name: "beforeLabel",
kind: .token(choices: [.keyword(text: "before")]),
kind: .token(choices: [.keyword(.before)]),
documentation: "The \"before\" label."
),
Child(
Expand Down Expand Up @@ -277,7 +277,7 @@ public let ATTRIBUTE_NODES: [Node] = [
),
Child(
name: "cTypeLabel",
kind: .token(choices: [.keyword(text: "cType")]),
kind: .token(choices: [.keyword(.cType)]),
isOptional: true
),
Child(
Expand All @@ -302,7 +302,7 @@ public let ATTRIBUTE_NODES: [Node] = [
children: [
Child(
name: "witnessMethodLabel",
kind: .token(choices: [.keyword(text: "witness_method")])
kind: .token(choices: [.keyword(.witness_method)])
),
Child(
name: "colon",
Expand Down Expand Up @@ -330,7 +330,7 @@ public let ATTRIBUTE_NODES: [Node] = [
children: [
Child(
name: "ofLabel",
kind: .token(choices: [.keyword(text: "of")]),
kind: .token(choices: [.keyword(.of)]),
documentation: "The \"of\" label."
),
Child(
Expand All @@ -352,7 +352,7 @@ public let ATTRIBUTE_NODES: [Node] = [
Child(
name: "accessorSpecifier",
deprecatedName: "accessorKind",
kind: .token(choices: [.keyword(text: "get"), .keyword(text: "set")]),
kind: .token(choices: [.keyword(.get), .keyword(.set)]),
documentation: "The accessor name.",
isOptional: true
),
Expand Down Expand Up @@ -392,7 +392,7 @@ public let ATTRIBUTE_NODES: [Node] = [
Child(
name: "argument",
deprecatedName: "parameter",
kind: .token(choices: [.token(.identifier), .token(.integerLiteral), .keyword(text: "self")])
kind: .token(choices: [.token(.identifier), .token(.integerLiteral), .keyword(.self)])
),
Child(
name: "trailingComma",
Expand All @@ -412,7 +412,7 @@ public let ATTRIBUTE_NODES: [Node] = [
children: [
Child(
name: "wrtLabel",
kind: .token(choices: [.keyword(text: "wrt")]),
kind: .token(choices: [.keyword(.wrt)]),
documentation: "The \"wrt\" label."
),
Child(
Expand Down Expand Up @@ -478,7 +478,7 @@ public let ATTRIBUTE_NODES: [Node] = [
Child(
name: "kindSpecifier",
deprecatedName: "diffKind",
kind: .token(choices: [.keyword(text: "_forward"), .keyword(text: "reverse"), .keyword(text: "_linear")]),
kind: .token(choices: [.keyword(._forward), .keyword(.reverse), .keyword(._linear)]),
isOptional: true
),
Child(
Expand Down Expand Up @@ -521,7 +521,7 @@ public let ATTRIBUTE_NODES: [Node] = [
children: [
Child(
name: "label",
kind: .token(choices: [.keyword(text: "visibility"), .keyword(text: "metadata")]),
kind: .token(choices: [.keyword(.visibility), .keyword(.metadata)]),
nameForDiagnostics: "label"
),
Child(
Expand All @@ -535,11 +535,11 @@ public let ATTRIBUTE_NODES: [Node] = [
name: "token",
kind: .token(choices: [
.token(.identifier),
.keyword(text: "private"),
.keyword(text: "fileprivate"),
.keyword(text: "internal"),
.keyword(text: "public"),
.keyword(text: "open"),
.keyword(.private),
.keyword(.fileprivate),
.keyword(.internal),
.keyword(.public),
.keyword(.open),
])
), // Keywords can be: public, internal, private, fileprivate, open
Child(
Expand Down Expand Up @@ -573,7 +573,7 @@ public let ATTRIBUTE_NODES: [Node] = [
children: [
Child(
name: "forLabel",
kind: .token(choices: [.keyword(text: "for")], requiresTrailingSpace: false)
kind: .token(choices: [.keyword(.for)], requiresTrailingSpace: false)
),
Child(
name: "colon",
Expand Down Expand Up @@ -662,13 +662,13 @@ public let ATTRIBUTE_NODES: [Node] = [
Child(
name: "label",
kind: .token(choices: [
.keyword(text: "target"),
.keyword(text: "availability"),
.keyword(text: "exported"),
.keyword(text: "kind"),
.keyword(text: "spi"),
.keyword(text: "spiModule"),
.keyword(text: "available"),
.keyword(.target),
.keyword(.availability),
.keyword(.exported),
.keyword(.kind),
.keyword(.spi),
.keyword(.spiModule),
.keyword(.available),
]),
nameForDiagnostics: "label",
documentation: "The label of the argument"
Expand Down Expand Up @@ -755,7 +755,7 @@ public let ATTRIBUTE_NODES: [Node] = [
children: [
Child(
name: "moduleLabel",
kind: .token(choices: [.keyword(text: "module")])
kind: .token(choices: [.keyword(.module)])
),
Child(
name: "colon",
Expand Down Expand Up @@ -803,7 +803,7 @@ public let ATTRIBUTE_NODES: [Node] = [
Child(
name: "targetLabel",
deprecatedName: "label",
kind: .token(choices: [.keyword(text: "target")]),
kind: .token(choices: [.keyword(.target)]),
nameForDiagnostics: "label",
documentation: "The label of the argument"
),
Expand Down Expand Up @@ -836,7 +836,7 @@ public let ATTRIBUTE_NODES: [Node] = [
children: [
Child(
name: "messageLabel",
kind: .token(choices: [.keyword(text: "message")])
kind: .token(choices: [.keyword(.message)])
),
Child(
name: "colon",
Expand All @@ -857,7 +857,7 @@ public let ATTRIBUTE_NODES: [Node] = [
children: [
Child(
name: "sourceFileLabel",
kind: .token(choices: [.keyword(text: "sourceFile")])
kind: .token(choices: [.keyword(.sourceFile)])
),
Child(
name: "colon",
Expand Down
10 changes: 5 additions & 5 deletions CodeGeneration/Sources/SyntaxSupport/AvailabilityNodes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,11 @@ public let AVAILABILITY_NODES: [Node] = [
Child(
name: "label",
kind: .token(choices: [
.keyword(text: "message"),
.keyword(text: "renamed"),
.keyword(text: "introduced"),
.keyword(text: "obsoleted"),
.keyword(text: "deprecated"),
.keyword(.message),
.keyword(.renamed),
.keyword(.introduced),
.keyword(.obsoleted),
.keyword(.deprecated),
]),
nameForDiagnostics: "label",
documentation: "The label of the argument"
Expand Down
2 changes: 1 addition & 1 deletion CodeGeneration/Sources/SyntaxSupport/Child.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import SwiftSyntax
/// The kind of token a node can contain. Either a token of a specific kind or a
/// keyword with the given text.
public enum TokenChoice: Equatable {
case keyword(text: String)
case keyword(Keyword)
case token(Token)

public var isKeyword: Bool {
Expand Down
14 changes: 7 additions & 7 deletions CodeGeneration/Sources/SyntaxSupport/CommonNodes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,12 @@ public let COMMON_NODES: [Node] = [
children: [
Child(
name: "asyncSpecifier",
kind: .token(choices: [.keyword(text: "async")]),
kind: .token(choices: [.keyword(.async)]),
isOptional: true
),
Child(
name: "throwsSpecifier",
kind: .token(choices: [.keyword(text: "throws")]),
kind: .token(choices: [.keyword(.throws)]),
isOptional: true
),
]
Expand All @@ -113,12 +113,12 @@ public let COMMON_NODES: [Node] = [
children: [
Child(
name: "asyncSpecifier",
kind: .token(choices: [.keyword(text: "async"), .keyword(text: "reasync")]),
kind: .token(choices: [.keyword(.async), .keyword(.reasync)]),
isOptional: true
),
Child(
name: "throwsSpecifier",
kind: .token(choices: [.keyword(text: "throws"), .keyword(text: "rethrows")]),
kind: .token(choices: [.keyword(.throws), .keyword(.rethrows)]),
isOptional: true
),
]
Expand All @@ -133,7 +133,7 @@ public let COMMON_NODES: [Node] = [
children: [
Child(
name: "asyncSpecifier",
kind: .token(choices: [.keyword(text: "async")]),
kind: .token(choices: [.keyword(.async)]),
isOptional: true
)
]
Expand Down Expand Up @@ -316,12 +316,12 @@ public let COMMON_NODES: [Node] = [
children: [
Child(
name: "asyncSpecifier",
kind: .token(choices: [.keyword(text: "async")]),
kind: .token(choices: [.keyword(.async)]),
isOptional: true
),
Child(
name: "throwsSpecifier",
kind: .token(choices: [.keyword(text: "throws")]),
kind: .token(choices: [.keyword(.throws)]),
isOptional: true
),
]
Expand Down
Loading