Skip to content

Commit 4294feb

Browse files
authored
Merge pull request #1998 from StevenWong12/rename_syntax_classification
Rename some `SyntaxClassification`
2 parents c3f46ad + d7caad1 commit 4294feb

File tree

4 files changed

+86
-78
lines changed

4 files changed

+86
-78
lines changed

Sources/SwiftIDEUtils/SwiftIDEUtilsCompatibility.swift

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,34 @@
1515

1616
public extension SyntaxClassification {
1717
/// A `#` keyword like `#warning`.
18-
@available(*, deprecated, renamed: "poundDirective")
19-
static var poundDirectiveKeyword: SyntaxClassification {
20-
return .poundDirective
18+
@available(*, deprecated, renamed: "ifConfigDirective")
19+
static var poundDirective: SyntaxClassification {
20+
return .ifConfigDirective
21+
}
22+
23+
@available(*, deprecated, renamed: "ifConfigDirective")
24+
static var buildConfigId: SyntaxClassification {
25+
return .ifConfigDirective
26+
}
27+
28+
@available(*, deprecated, message: "String interpolation anchors are now classified as .none")
29+
static var stringInterpolationAnchor: SyntaxClassification {
30+
return .none
31+
}
32+
33+
@available(*, deprecated, renamed: "type")
34+
static var typeIdentifier: SyntaxClassification {
35+
return .type
36+
}
37+
38+
@available(*, deprecated, renamed: "operator")
39+
static var operatorIdentifier: SyntaxClassification {
40+
return .operator
41+
}
42+
43+
@available(*, deprecated, renamed: "floatLiteral")
44+
static var floatingLiteral: SyntaxClassification {
45+
return .floatLiteral
2146
}
2247
}
2348

Sources/SwiftIDEUtils/SyntaxClassification.swift

Lines changed: 18 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ public enum SyntaxClassification {
1717
case attribute
1818
/// A block comment starting with `/**` and ending with `*/.
1919
case blockComment
20-
/// A build configuration directive like `#if`, `#elseif`, `#else`.
21-
case buildConfigId
2220
/// A doc block comment starting with `/**` and ending with `*/.
2321
case docBlockComment
2422
/// A doc line comment starting with `///`.
@@ -31,6 +29,8 @@ public enum SyntaxClassification {
3129
case floatLiteral
3230
/// A generic identifier.
3331
case identifier
32+
/// A directive starting with `#if`, `#elseif`or `#else`.
33+
case ifConfigDirective
3434
/// An integer literal.
3535
case integerLiteral
3636
/// A Swift keyword, including contextual keywords.
@@ -40,22 +40,13 @@ public enum SyntaxClassification {
4040
/// The token should not receive syntax coloring.
4141
case none
4242
/// An identifier referring to an operator.
43-
case operatorIdentifier
44-
/// A `#` token like `#warning`.
45-
case poundDirective
43+
case `operator`
4644
/// A regex literal, including multiline regex literals.
4745
case regexLiteral
48-
/// The opening and closing parenthesis of string interpolation.
49-
case stringInterpolationAnchor
5046
/// A string literal including multiline string literals.
5147
case stringLiteral
5248
/// An identifier referring to a type.
53-
case typeIdentifier
54-
55-
@available(*, deprecated, renamed: "floatLiteral")
56-
public static var floatingLiteral: Self {
57-
return .floatLiteral
58-
}
49+
case type
5950
}
6051

6152
extension SyntaxClassification {
@@ -76,26 +67,22 @@ extension SyntaxClassification {
7667
return (.keyword, false)
7768
case \DeclModifierSyntax.name:
7869
return (.attribute, false)
79-
case \ExpressionSegmentSyntax.leftParen:
80-
return (.stringInterpolationAnchor, true)
81-
case \ExpressionSegmentSyntax.rightParen:
82-
return (.stringInterpolationAnchor, true)
8370
case \IfConfigClauseSyntax.poundKeyword:
84-
return (.buildConfigId, false)
71+
return (.ifConfigDirective, false)
8572
case \IfConfigClauseSyntax.condition:
86-
return (.buildConfigId, false)
73+
return (.ifConfigDirective, false)
8774
case \IfConfigDeclSyntax.poundEndif:
88-
return (.buildConfigId, false)
75+
return (.ifConfigDirective, false)
8976
case \MemberTypeIdentifierSyntax.name:
90-
return (.typeIdentifier, false)
77+
return (.type, false)
9178
case \OperatorDeclSyntax.name:
92-
return (.operatorIdentifier, false)
79+
return (.operator, false)
9380
case \PrecedenceGroupAssociativitySyntax.associativityLabel:
9481
return (.keyword, false)
9582
case \PrecedenceGroupRelationSyntax.higherThanOrLowerThanLabel:
9683
return (.keyword, false)
9784
case \SimpleTypeIdentifierSyntax.name:
98-
return (.typeIdentifier, false)
85+
return (.type, false)
9986
default:
10087
return nil
10188
}
@@ -114,7 +101,7 @@ extension RawTokenKind {
114101
case .backtick:
115102
return .none
116103
case .binaryOperator:
117-
return .operatorIdentifier
104+
return .operator
118105
case .colon:
119106
return .none
120107
case .comma:
@@ -152,29 +139,29 @@ extension RawTokenKind {
152139
case .period:
153140
return .none
154141
case .postfixOperator:
155-
return .operatorIdentifier
142+
return .operator
156143
case .postfixQuestionMark:
157144
return .none
158145
case .pound:
159146
return .none
160147
case .poundAvailable:
161148
return .none
162149
case .poundElse:
163-
return .poundDirective
150+
return .ifConfigDirective
164151
case .poundElseif:
165-
return .poundDirective
152+
return .ifConfigDirective
166153
case .poundEndif:
167-
return .poundDirective
154+
return .ifConfigDirective
168155
case .poundIf:
169-
return .poundDirective
156+
return .ifConfigDirective
170157
case .poundSourceLocation:
171-
return .poundDirective
158+
return .keyword
172159
case .poundUnavailable:
173160
return .none
174161
case .prefixAmpersand:
175162
return .none
176163
case .prefixOperator:
177-
return .operatorIdentifier
164+
return .operator
178165
case .rawStringPoundDelimiter:
179166
return .none
180167
case .regexLiteralPattern:

Sources/lit-test-helper/ClassifiedSyntaxTreePrinter.swift

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,14 @@ extension SyntaxClassification {
1919
case .none: return ""
2020
case .keyword: return "kw"
2121
case .identifier: return "id"
22-
case .typeIdentifier: return "type"
22+
case .type: return "type"
2323
case .dollarIdentifier: return "dollar"
24-
case .operatorIdentifier: return "op"
24+
case .operator: return "op"
2525
case .integerLiteral: return "int"
2626
case .floatLiteral: return "float"
2727
case .stringLiteral: return "str"
28-
case .stringInterpolationAnchor: return "anchor"
2928
case .regexLiteral: return "regex"
30-
case .poundDirective: return "#kw"
31-
case .buildConfigId: return "#id"
29+
case .ifConfigDirective: return "#kw"
3230
case .attribute: return "attr-builtin"
3331
case .editorPlaceholder: return "placeholder"
3432
case .lineComment: return "comment-line"

Tests/SwiftIDEUtilsTest/ClassificationTests.swift

Lines changed: 37 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public class ClassificationTests: XCTestCase {
9090
expected: [
9191
ClassificationSpec(source: "let", kind: .keyword),
9292
ClassificationSpec(source: "x", kind: .identifier),
93-
ClassificationSpec(source: "Int", kind: .typeIdentifier),
93+
ClassificationSpec(source: "Int", kind: .type),
9494
]
9595
)
9696
}
@@ -103,11 +103,11 @@ public class ClassificationTests: XCTestCase {
103103
expected: [
104104
ClassificationSpec(source: "let", kind: .keyword),
105105
ClassificationSpec(source: "x", kind: .identifier),
106-
ClassificationSpec(source: "Int", kind: .typeIdentifier),
106+
ClassificationSpec(source: "Int", kind: .type),
107107
ClassificationSpec(source: "4", kind: .integerLiteral),
108-
ClassificationSpec(source: "+", kind: .operatorIdentifier),
108+
ClassificationSpec(source: "+", kind: .operator),
109109
ClassificationSpec(source: "5", kind: .integerLiteral),
110-
ClassificationSpec(source: "/", kind: .operatorIdentifier),
110+
ClassificationSpec(source: "/", kind: .operator),
111111
ClassificationSpec(source: "6", kind: .integerLiteral),
112112
]
113113
)
@@ -117,7 +117,7 @@ public class ClassificationTests: XCTestCase {
117117
expected: [
118118
ClassificationSpec(source: "infix", kind: .keyword),
119119
ClassificationSpec(source: "operator", kind: .keyword),
120-
ClassificationSpec(source: "*--*", kind: .operatorIdentifier),
120+
ClassificationSpec(source: "*--*", kind: .operator),
121121
]
122122
)
123123
}
@@ -131,13 +131,13 @@ public class ClassificationTests: XCTestCase {
131131
ClassificationSpec(source: "func", kind: .keyword),
132132
ClassificationSpec(source: "foo", kind: .identifier),
133133
ClassificationSpec(source: "x", kind: .identifier),
134-
ClassificationSpec(source: "Int", kind: .typeIdentifier),
134+
ClassificationSpec(source: "Int", kind: .type),
135135
ClassificationSpec(source: "y", kind: .identifier),
136-
ClassificationSpec(source: "Int", kind: .typeIdentifier),
137-
ClassificationSpec(source: "Int", kind: .typeIdentifier),
136+
ClassificationSpec(source: "Int", kind: .type),
137+
ClassificationSpec(source: "Int", kind: .type),
138138
ClassificationSpec(source: "return", kind: .keyword),
139139
ClassificationSpec(source: "x", kind: .identifier),
140-
ClassificationSpec(source: "+", kind: .operatorIdentifier),
140+
ClassificationSpec(source: "+", kind: .operator),
141141
ClassificationSpec(source: "y", kind: .identifier),
142142
]
143143
)
@@ -219,18 +219,18 @@ public class ClassificationTests: XCTestCase {
219219
#endif
220220
""",
221221
expected: [
222-
ClassificationSpec(source: "#if", kind: .poundDirective),
223-
ClassificationSpec(source: "os", kind: .buildConfigId),
224-
ClassificationSpec(source: "macOS", kind: .buildConfigId),
222+
ClassificationSpec(source: "#if", kind: .ifConfigDirective),
223+
ClassificationSpec(source: "os", kind: .ifConfigDirective),
224+
ClassificationSpec(source: "macOS", kind: .ifConfigDirective),
225225
ClassificationSpec(source: "var", kind: .keyword),
226226
ClassificationSpec(source: "x", kind: .identifier),
227-
ClassificationSpec(source: "Int", kind: .typeIdentifier),
228-
ClassificationSpec(source: "#elseif", kind: .poundDirective),
227+
ClassificationSpec(source: "Int", kind: .type),
228+
ClassificationSpec(source: "#elseif", kind: .ifConfigDirective),
229229
ClassificationSpec(source: "var", kind: .keyword),
230230
ClassificationSpec(source: "x", kind: .identifier),
231-
ClassificationSpec(source: "Float", kind: .typeIdentifier),
232-
ClassificationSpec(source: "#else", kind: .poundDirective),
233-
ClassificationSpec(source: "#endif", kind: .poundDirective),
231+
ClassificationSpec(source: "Float", kind: .type),
232+
ClassificationSpec(source: "#else", kind: .ifConfigDirective),
233+
ClassificationSpec(source: "#endif", kind: .ifConfigDirective),
234234
]
235235
)
236236
}
@@ -242,10 +242,10 @@ public class ClassificationTests: XCTestCase {
242242
#else
243243
""",
244244
expected: [
245-
ClassificationSpec(source: "#if", kind: .poundDirective),
246-
ClassificationSpec(source: "!", kind: .operatorIdentifier),
247-
ClassificationSpec(source: "CONF", kind: .buildConfigId),
248-
ClassificationSpec(source: "#else", kind: .poundDirective),
245+
ClassificationSpec(source: "#if", kind: .ifConfigDirective),
246+
ClassificationSpec(source: "!", kind: .operator),
247+
ClassificationSpec(source: "CONF", kind: .ifConfigDirective),
248+
ClassificationSpec(source: "#else", kind: .ifConfigDirective),
249249
]
250250
)
251251
}
@@ -269,7 +269,7 @@ public class ClassificationTests: XCTestCase {
269269
assertClassification(
270270
#"#sourceLocation(file: "x", line: 1)"#,
271271
expected: [
272-
ClassificationSpec(source: "#sourceLocation", kind: .poundDirective),
272+
ClassificationSpec(source: "#sourceLocation", kind: .keyword),
273273
ClassificationSpec(source: "file", kind: .keyword),
274274
ClassificationSpec(source: #""x""#, kind: .stringLiteral),
275275
ClassificationSpec(source: "line", kind: .keyword),
@@ -330,7 +330,7 @@ public class ClassificationTests: XCTestCase {
330330
ClassificationSpec(source: "OSX", kind: .keyword),
331331
ClassificationSpec(source: "10", kind: .integerLiteral),
332332
ClassificationSpec(source: "10", kind: .integerLiteral),
333-
ClassificationSpec(source: "*", kind: .operatorIdentifier),
333+
ClassificationSpec(source: "*", kind: .operator),
334334
]
335335
)
336336
}
@@ -345,7 +345,7 @@ public class ClassificationTests: XCTestCase {
345345
ClassificationSpec(source: "@IBOutlet", kind: .attribute),
346346
ClassificationSpec(source: "var", kind: .keyword),
347347
ClassificationSpec(source: "foo", kind: .identifier),
348-
ClassificationSpec(source: "String", kind: .typeIdentifier),
348+
ClassificationSpec(source: "String", kind: .type),
349349
]
350350
)
351351
}
@@ -363,8 +363,8 @@ public class ClassificationTests: XCTestCase {
363363
ClassificationSpec(source: "indirect", kind: .keyword),
364364
ClassificationSpec(source: "case", kind: .keyword),
365365
ClassificationSpec(source: "cons", kind: .identifier),
366-
ClassificationSpec(source: "T", kind: .typeIdentifier),
367-
ClassificationSpec(source: "List", kind: .typeIdentifier),
366+
ClassificationSpec(source: "T", kind: .type),
367+
ClassificationSpec(source: "List", kind: .type),
368368
]
369369
)
370370
}
@@ -410,7 +410,7 @@ public class ClassificationTests: XCTestCase {
410410
expected: [
411411
ClassificationSpec(source: "infix", kind: .keyword),
412412
ClassificationSpec(source: "operator", kind: .keyword),
413-
ClassificationSpec(source: "*-*", kind: .operatorIdentifier),
413+
ClassificationSpec(source: "*-*", kind: .operator),
414414
ClassificationSpec(source: "FunnyPrecedence", kind: .identifier),
415415
]
416416
)
@@ -441,7 +441,7 @@ public class ClassificationTests: XCTestCase {
441441
expected: [
442442
ClassificationSpec(source: "protocol", kind: .keyword),
443443
ClassificationSpec(source: "Prot2", kind: .identifier),
444-
ClassificationSpec(source: "Prot", kind: .typeIdentifier),
444+
ClassificationSpec(source: "Prot", kind: .type),
445445
]
446446
)
447447
}
@@ -453,13 +453,13 @@ public class ClassificationTests: XCTestCase {
453453
ClassificationSpec(source: "func", kind: .keyword),
454454
ClassificationSpec(source: "genFn", kind: .identifier),
455455
ClassificationSpec(source: "T", kind: .identifier),
456-
ClassificationSpec(source: "Prot", kind: .typeIdentifier),
457-
ClassificationSpec(source: "T", kind: .typeIdentifier),
458-
ClassificationSpec(source: "Int", kind: .typeIdentifier),
456+
ClassificationSpec(source: "Prot", kind: .type),
457+
ClassificationSpec(source: "T", kind: .type),
458+
ClassificationSpec(source: "Int", kind: .type),
459459
ClassificationSpec(source: "where", kind: .keyword),
460-
ClassificationSpec(source: "T", kind: .typeIdentifier),
461-
ClassificationSpec(source: "Blarg", kind: .typeIdentifier),
462-
ClassificationSpec(source: "Prot2", kind: .typeIdentifier),
460+
ClassificationSpec(source: "T", kind: .type),
461+
ClassificationSpec(source: "Blarg", kind: .type),
462+
ClassificationSpec(source: "Prot2", kind: .type),
463463
]
464464
)
465465
}
@@ -469,9 +469,7 @@ public class ClassificationTests: XCTestCase {
469469
#""This is string \(1) interpolation""#,
470470
expected: [
471471
ClassificationSpec(source: #""This is string "#, kind: .stringLiteral),
472-
ClassificationSpec(source: "(", kind: .stringInterpolationAnchor),
473472
ClassificationSpec(source: "1", kind: .integerLiteral),
474-
ClassificationSpec(source: ")", kind: .stringInterpolationAnchor),
475473
ClassificationSpec(source: #" interpolation""#, kind: .stringLiteral),
476474
]
477475
)
@@ -531,12 +529,12 @@ public class ClassificationTests: XCTestCase {
531529
ClassificationSpec(source: "func", kind: .keyword),
532530
ClassificationSpec(source: "keywordInCaseAndLocalArgLabel", kind: .identifier),
533531
ClassificationSpec(source: "for", kind: .identifier),
534-
ClassificationSpec(source: "Int", kind: .typeIdentifier),
532+
ClassificationSpec(source: "Int", kind: .type),
535533
ClassificationSpec(source: "for", kind: .identifier),
536534
ClassificationSpec(source: "in", kind: .identifier),
537-
ClassificationSpec(source: "Int", kind: .typeIdentifier),
535+
ClassificationSpec(source: "Int", kind: .type),
538536
ClassificationSpec(source: "class", kind: .identifier),
539-
ClassificationSpec(source: "Int", kind: .typeIdentifier),
537+
ClassificationSpec(source: "Int", kind: .type),
540538
]
541539
)
542540
}

0 commit comments

Comments
 (0)