Skip to content

Commit 7d98ad0

Browse files
committed
Remove Keyword suffix from Pound*
1 parent c808498 commit 7d98ad0

35 files changed

+460
-358
lines changed

CodeGeneration/Sources/SyntaxSupport/Classification.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public let SYNTAX_CLASSIFICATIONS: [SyntaxClassification] = [
5656
SyntaxClassification(name: "None", description: "The token should not receive syntax coloring."),
5757
SyntaxClassification(name: "ObjectLiteral", description: "An image, color, etc. literal."),
5858
SyntaxClassification(name: "OperatorIdentifier", description: "An identifier referring to an operator."),
59-
SyntaxClassification(name: "PoundDirectiveKeyword", description: "A `#` keyword like `#warning`."),
59+
SyntaxClassification(name: "PoundDirective", description: "A `#` token like `#warning`."),
6060
SyntaxClassification(name: "RegexLiteral", description: "A regex literal, including multiline regex literals."),
6161
SyntaxClassification(name: "StringInterpolationAnchor", description: "The opening and closing parenthesis of string interpolation."),
6262
SyntaxClassification(name: "StringLiteral", description: "A string literal including multiline string literals."),

CodeGeneration/Sources/SyntaxSupport/TokenSpec.swift

Lines changed: 14 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,12 @@ public class TokenSpec {
1818
public let unprefixedKind: String
1919
public let text: String?
2020
public let classification: SyntaxClassification?
21-
public let isKeyword: Bool
2221
public let requiresLeadingSpace: Bool
2322
public let requiresTrailingSpace: Bool
2423
public let associatedValueClass: String?
2524

2625
public var swiftKind: String {
27-
let name = lowercaseFirstWord(name: self.name)
28-
29-
if isKeyword {
30-
return name + "Keyword"
31-
} else {
32-
return name
33-
}
26+
return lowercaseFirstWord(name: self.name)
3427
}
3528

3629
init(
@@ -40,7 +33,6 @@ public class TokenSpec {
4033
unprefixedKind: String? = nil,
4134
text: String? = nil,
4235
classification: String = "None",
43-
isKeyword: Bool = false,
4436
requiresLeadingSpace: Bool = false,
4537
requiresTrailingSpace: Bool = false,
4638
associatedValueClass: String? = nil
@@ -55,20 +47,19 @@ public class TokenSpec {
5547
}
5648
self.text = text
5749
self.classification = classificationByName(classification)
58-
self.isKeyword = isKeyword
5950
self.requiresLeadingSpace = requiresLeadingSpace
6051
self.requiresTrailingSpace = requiresTrailingSpace
6152
self.associatedValueClass = associatedValueClass
6253
}
6354
}
6455

65-
public class PoundKeywordSpec: TokenSpec {
56+
public class PoundSpec: TokenSpec {
6657
init(
6758
name: String,
6859
kind: String,
6960
nameForDiagnostics: String? = nil,
7061
text: String,
71-
classification: String = "Keyword"
62+
classification: String = "None"
7263
) {
7364
super.init(
7465
name: name,
@@ -77,13 +68,12 @@ public class PoundKeywordSpec: TokenSpec {
7768
unprefixedKind: kind,
7869
text: text,
7970
classification: classification,
80-
isKeyword: true,
8171
requiresTrailingSpace: true
8272
)
8373
}
8474
}
8575

86-
public class PoundObjectLiteralSpec: PoundKeywordSpec {
76+
public class PoundObjectLiteralSpec: PoundSpec {
8777
let `protocol`: String
8878

8979
init(
@@ -105,14 +95,14 @@ public class PoundObjectLiteralSpec: PoundKeywordSpec {
10595
}
10696
}
10797

108-
public class PoundConfigSpec: PoundKeywordSpec {}
98+
public class PoundConfigSpec: PoundSpec {}
10999

110-
public class PoundDirectiveKeywordSpec: PoundKeywordSpec {
100+
public class PoundDirectiveSpec: PoundSpec {
111101
init(
112102
name: String,
113103
kind: String,
114104
text: String,
115-
classification: String = "PoundDirectiveKeyword"
105+
classification: String = "PoundDirective"
116106
) {
117107
super.init(
118108
name: name,
@@ -123,12 +113,12 @@ public class PoundDirectiveKeywordSpec: PoundKeywordSpec {
123113
}
124114
}
125115

126-
public class PoundConditionalDirectiveKeywordSpec: PoundDirectiveKeywordSpec {
116+
public class PoundConditionalDirectiveSpec: PoundDirectiveSpec {
127117
override init(
128118
name: String,
129119
kind: String,
130120
text: String,
131-
classification: String = "PoundDirectiveKeyword"
121+
classification: String = "PoundDirective"
132122
) {
133123
super.init(
134124
name: name,
@@ -155,7 +145,6 @@ public class PunctuatorSpec: TokenSpec {
155145
unprefixedKind: nil,
156146
text: text,
157147
classification: classification,
158-
isKeyword: false,
159148
requiresLeadingSpace: requiresLeadingSpace,
160149
requiresTrailingSpace: requiresTrailingSpace
161150
)
@@ -201,11 +190,11 @@ public let SYNTAX_TOKENS: [TokenSpec] = [
201190
PunctuatorSpec(name: "PostfixQuestionMark", kind: "question_postfix", text: "?"),
202191
PunctuatorSpec(name: "Pound", kind: "pound", text: "#"),
203192
PoundConfigSpec(name: "PoundAvailable", kind: "pound_available", text: "#available"),
204-
PoundConditionalDirectiveKeywordSpec(name: "PoundElse", kind: "pound_else", text: "#else"),
205-
PoundConditionalDirectiveKeywordSpec(name: "PoundElseif", kind: "pound_elseif", text: "#elseif"),
206-
PoundConditionalDirectiveKeywordSpec(name: "PoundEndif", kind: "pound_endif", text: "#endif"),
207-
PoundConditionalDirectiveKeywordSpec(name: "PoundIf", kind: "pound_if", text: "#if"),
208-
PoundDirectiveKeywordSpec(name: "PoundSourceLocation", kind: "pound_sourceLocation", text: "#sourceLocation"),
193+
PoundConditionalDirectiveSpec(name: "PoundElse", kind: "pound_else", text: "#else"),
194+
PoundConditionalDirectiveSpec(name: "PoundElseif", kind: "pound_elseif", text: "#elseif"),
195+
PoundConditionalDirectiveSpec(name: "PoundEndif", kind: "pound_endif", text: "#endif"),
196+
PoundConditionalDirectiveSpec(name: "PoundIf", kind: "pound_if", text: "#if"),
197+
PoundDirectiveSpec(name: "PoundSourceLocation", kind: "pound_sourceLocation", text: "#sourceLocation"),
209198
PoundConfigSpec(name: "PoundUnavailable", kind: "pound_unavailable", text: "#unavailable"),
210199
PunctuatorSpec(name: "PrefixAmpersand", kind: "amp_prefix", text: "&"),
211200
MiscSpec(name: "PrefixOperator", kind: "oper_prefix", nameForDiagnostics: "prefix operator", classification: "OperatorIdentifier"),

CodeGeneration/Sources/Utils/SyntaxBuildableChild.swift

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,6 @@ public extension Child {
7171
guard let token = token, isToken else {
7272
return type.defaultValue.map { InitializerClauseSyntax(value: $0) }
7373
}
74-
if token.isKeyword {
75-
return InitializerClauseSyntax(value: ExprSyntax(".\(raw: token.swiftKind)()"))
76-
}
7774
if token.name == "EOF" {
7875
return InitializerClauseSyntax(value: ExprSyntax(".eof()"))
7976
}

CodeGeneration/Sources/Utils/SyntaxBuildableType.swift

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,7 @@ public struct SyntaxBuildableType: Hashable {
6363
if isOptional {
6464
return ExprSyntax(NilLiteralExprSyntax())
6565
} else if let token = token {
66-
if token.isKeyword {
67-
return ExprSyntax(".\(raw: token.swiftKind)()")
68-
} else if token.text != nil {
66+
if token.text != nil {
6967
return ExprSyntax(".\(raw: lowercaseFirstWord(name: token.name))Token()")
7068
}
7169
} else if case .token("EOFToken") = kind {

CodeGeneration/Sources/generate-swiftsyntax/templates/swiftparser/IsLexerClassifiedFile.swift

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,6 @@ let isLexerClassifiedFile = SourceFileSyntax(leadingTrivia: copyrightHeader) {
6262
StmtSyntax("return false")
6363
}
6464

65-
for token in SYNTAX_TOKENS where token.isKeyword {
66-
SwitchCaseSyntax("case .\(raw: token.swiftKind):") {
67-
StmtSyntax("return true")
68-
}
69-
}
70-
7165
SwitchCaseSyntax("case .keyword(let keyword):") {
7266
StmtSyntax("return keyword.isLexerClassified")
7367
}

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

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,24 +18,7 @@ import Utils
1818
let tokensFile = SourceFileSyntax(leadingTrivia: copyrightHeader) {
1919
try! ExtensionDeclSyntax("extension TokenSyntax") {
2020
for token in SYNTAX_TOKENS {
21-
if token.isKeyword {
22-
DeclSyntax(
23-
"""
24-
public static func \(raw: token.swiftKind)(
25-
leadingTrivia: Trivia = [],
26-
trailingTrivia: Trivia = [],
27-
presence: SourcePresence = .present
28-
) -> TokenSyntax {
29-
return TokenSyntax(
30-
.\(raw: token.swiftKind),
31-
leadingTrivia: leadingTrivia,
32-
trailingTrivia: trailingTrivia,
33-
presence: presence
34-
)
35-
}
36-
"""
37-
)
38-
} else if let text = token.text {
21+
if let text = token.text {
3922
DeclSyntax(
4023
"""
4124
public static func \(raw: token.swiftKind)Token(

Sources/SwiftBasicFormat/BasicFormat.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -192,9 +192,9 @@ open class BasicFormat: SyntaxRewriter {
192192
(.multilineStringQuote, .stringSegment), // segment starting a multi-line string literal
193193
(.stringSegment, .multilineStringQuote), // ending a multi-line string literal that has a string interpolation segment at its end
194194
(.rightParen, .multilineStringQuote), // ending a multi-line string literal that has a string interpolation segment at its end
195-
(_, .poundElseKeyword),
196-
(_, .poundElseifKeyword),
197-
(_, .poundEndifKeyword),
195+
(_, .poundElse),
196+
(_, .poundElseif),
197+
(_, .poundEndif),
198198
(_, .rightBrace):
199199
return true
200200
default:
@@ -235,7 +235,7 @@ open class BasicFormat: SyntaxRewriter {
235235
(.postfixQuestionMark, .leftParen), // init?() or myOptionalClosure?()
236236
(.postfixQuestionMark, .period), // someOptional?.someProperty
237237
(.pound, _),
238-
(.poundUnavailableKeyword, .leftParen), // #unavailable(...)
238+
(.poundUnavailable, .leftParen), // #unavailable(...)
239239
(.prefixAmpersand, _),
240240
(.prefixOperator, _),
241241
(.rawStringDelimiter, .leftParen), // opening raw string delimiter should never be separate by a space

Sources/SwiftIDEUtils/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
add_swift_host_library(SwiftIDEUtils
1010
generated/SyntaxClassification.swift
11+
12+
SwiftIDEUtilsCompatibility.swift
1113
Syntax+Classifications.swift
1214
SyntaxClassifier.swift
1315
)
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2014 - 2023 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
// This file provides compatiblity aliases to keep dependents of SwiftSyntax building.
14+
// All users of the declarations in this file should transition away from them ASAP.
15+
16+
public extension SyntaxClassification {
17+
/// A `#` keyword like `#warning`.
18+
@available(*, deprecated, renamed: "poundDirective")
19+
static var poundDirectiveKeyword: SyntaxClassification {
20+
return .poundDirective
21+
}
22+
}
23+
24+
//==========================================================================//
25+
// IMPORTANT: If you are tempted to add a compatiblity layer code here //
26+
// please insert it in alphabetical order above //
27+
//==========================================================================//

Sources/SwiftIDEUtils/generated/SyntaxClassification.swift

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ public enum SyntaxClassification {
4545
case objectLiteral
4646
/// An identifier referring to an operator.
4747
case operatorIdentifier
48-
/// A `#` keyword like `#warning`.
49-
case poundDirectiveKeyword
48+
/// A `#` token like `#warning`.
49+
case poundDirective
5050
/// A regex literal, including multiline regex literals.
5151
case regexLiteral
5252
/// The opening and closing parenthesis of string interpolation.
@@ -156,20 +156,20 @@ extension RawTokenKind {
156156
return .none
157157
case .pound:
158158
return .none
159-
case .poundAvailableKeyword:
160-
return .keyword
161-
case .poundElseKeyword:
162-
return .poundDirectiveKeyword
163-
case .poundElseifKeyword:
164-
return .poundDirectiveKeyword
165-
case .poundEndifKeyword:
166-
return .poundDirectiveKeyword
167-
case .poundIfKeyword:
168-
return .poundDirectiveKeyword
169-
case .poundSourceLocationKeyword:
170-
return .poundDirectiveKeyword
171-
case .poundUnavailableKeyword:
172-
return .keyword
159+
case .poundAvailable:
160+
return .none
161+
case .poundElse:
162+
return .poundDirective
163+
case .poundElseif:
164+
return .poundDirective
165+
case .poundEndif:
166+
return .poundDirective
167+
case .poundIf:
168+
return .poundDirective
169+
case .poundSourceLocation:
170+
return .poundDirective
171+
case .poundUnavailable:
172+
return .none
173173
case .prefixAmpersand:
174174
return .none
175175
case .prefixOperator:

Sources/SwiftParser/Attributes.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
extension Parser {
1616
mutating func parseAttributeList() -> RawAttributeListSyntax? {
17-
guard self.at(.atSign, .poundIfKeyword) else {
17+
guard self.at(.atSign, .poundIf) else {
1818
return nil
1919
}
2020

@@ -23,7 +23,7 @@ extension Parser {
2323
repeat {
2424
let attribute = self.parseAttribute()
2525
elements.append(attribute)
26-
} while self.at(.atSign, .poundIfKeyword) && loopProgress.evaluate(currentToken)
26+
} while self.at(.atSign, .poundIf) && loopProgress.evaluate(currentToken)
2727
return RawAttributeListSyntax(elements: elements, arena: self.arena)
2828
}
2929
}
@@ -213,7 +213,7 @@ extension Parser {
213213
}
214214

215215
mutating func parseAttribute() -> RawAttributeListSyntax.Element {
216-
if self.at(.poundIfKeyword) {
216+
if self.at(.poundIf) {
217217
return .ifConfigDecl(
218218
self.parsePoundIfDirective { (parser, _) -> RawAttributeListSyntax.Element in
219219
return parser.parseAttribute()

Sources/SwiftParser/Declarations.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ extension TokenConsumer {
5353
allowInitDecl: Bool = true,
5454
allowRecovery: Bool = false
5555
) -> Bool {
56-
if self.at(.poundIfKeyword) {
56+
if self.at(.poundIf) {
5757
return true
5858
}
5959

@@ -85,12 +85,12 @@ extension TokenConsumer {
8585
}
8686

8787
if hasAttribute {
88-
if subparser.at(.rightBrace) || subparser.at(.eof) || subparser.at(.poundEndifKeyword) {
88+
if subparser.at(.rightBrace) || subparser.at(.eof) || subparser.at(.poundEndif) {
8989
return true
9090
}
9191
}
9292

93-
if subparser.at(.poundIfKeyword) {
93+
if subparser.at(.poundIf) {
9494
var attrLookahead = subparser.lookahead()
9595
return attrLookahead.consumeIfConfigOfAttributes()
9696
}
@@ -196,7 +196,7 @@ extension Parser {
196196
mutating func parseDeclaration(inMemberDeclList: Bool = false) -> RawDeclSyntax {
197197
// If we are at a `#if` of attributes, the `#if` directive should be
198198
// parsed when we're parsing the attributes.
199-
if self.at(.poundIfKeyword) && !self.withLookahead({ $0.consumeIfConfigOfAttributes() }) {
199+
if self.at(.poundIf) && !self.withLookahead({ $0.consumeIfConfigOfAttributes() }) {
200200
let directive = self.parsePoundIfDirective { (parser, _) in
201201
let parsedDecl = parser.parseDeclaration()
202202
let semicolon = parser.consume(if: .semicolon)
@@ -744,7 +744,7 @@ extension Parser {
744744
}
745745

746746
let decl: RawDeclSyntax
747-
if self.at(.poundSourceLocationKeyword) {
747+
if self.at(.poundSourceLocation) {
748748
decl = RawDeclSyntax(self.parsePoundSourceLocationDirective())
749749
} else {
750750
decl = self.parseDeclaration(inMemberDeclList: true)

0 commit comments

Comments
 (0)