@@ -21,16 +21,40 @@ public struct TokenSpec {
21
21
case other
22
22
}
23
23
24
+ /// The name of the token, suitable for use in variable or enum case names.
24
25
public let varOrCaseName : TokenSyntax
25
26
26
- /// If `true`, this is for an experimental language feature, and any public
27
- /// API generated should be SPI.
27
+ /// Indicates if the token is part of an experimental language feature.
28
+ ///
29
+ /// If `true`, this keyword is for an experimental language feature, and any public
30
+ /// API generated should be marked as SPI
28
31
public let isExperimental : Bool
29
32
33
+ /// The name of the token that can be shown in diagnostics.
30
34
public let nameForDiagnostics : String
35
+
36
+ /// The actual text of the token, if available.
31
37
public let text : String ?
38
+
39
+ /// The kind of the token.
32
40
public let kind : Kind
33
41
42
+ /// The attributes that should be printed on any API for the generated keyword.
43
+ ///
44
+ /// This is typically used to mark APIs as SPI when the keyword is part of an experimental language feature.
45
+ public var apiAttributes : AttributeListSyntax {
46
+ guard isExperimental else { return " " }
47
+ return AttributeListSyntax ( " @_spi(ExperimentalLanguageFeatures) " ) . with ( \. trailingTrivia, . newline)
48
+ }
49
+
50
+ /// Initializes a new `TokenSpec` instance.
51
+ ///
52
+ /// - Parameters:
53
+ /// - name: A name of the token.
54
+ /// - isExperimental: Indicates if the token is part of an experimental language feature.
55
+ /// - nameForDiagnostics: A name of the token that can be shown in diagnostics.
56
+ /// - text: An actual text of the token, if available.
57
+ /// - kind: A kind of the token.
34
58
fileprivate init (
35
59
name: String ,
36
60
isExperimental: Bool = false ,
@@ -45,13 +69,11 @@ public struct TokenSpec {
45
69
self . kind = kind
46
70
}
47
71
48
- /// Retrieve the attributes that should be printed on any API for the
49
- /// generated token.
50
- public var apiAttributes : AttributeListSyntax {
51
- guard isExperimental else { return " " }
52
- return AttributeListSyntax ( " @_spi(ExperimentalLanguageFeatures) " ) . with ( \. trailingTrivia, . newline)
53
- }
54
-
72
+ /// Creates a new `TokenSpec` instance representing a punctuation token.
73
+ ///
74
+ /// - Parameters:
75
+ /// - name: A name of the token.
76
+ /// - text: An actual text of the punctuation token.
55
77
static func punctuator( name: String , text: String ) -> TokenSpec {
56
78
return TokenSpec (
57
79
name: name,
@@ -61,6 +83,11 @@ public struct TokenSpec {
61
83
)
62
84
}
63
85
86
+ /// Creates a new `TokenSpec` instance representing a pound keyword token.
87
+ ///
88
+ /// - Parameters:
89
+ /// - name: A name of the token.
90
+ /// - text: An actual text of the pound keyword token.
64
91
static func poundKeyword( name: String , text: String ) -> TokenSpec {
65
92
return TokenSpec (
66
93
name: name,
@@ -70,8 +97,14 @@ public struct TokenSpec {
70
97
)
71
98
}
72
99
100
+ /// Creates a new `TokenSpec` instance representing an other token.
101
+ ///
102
+ /// - Parameters:
103
+ /// - name: A name of the token.
104
+ /// - nameForDiagnostics: A name of the token that can be shown in diagnostics.
105
+ /// - text: An actual text of the token, if available.
73
106
static func other( name: String , nameForDiagnostics: String , text: String ? = nil ) -> TokenSpec {
74
- TokenSpec (
107
+ return TokenSpec (
75
108
name: name,
76
109
nameForDiagnostics: nameForDiagnostics,
77
110
text: text,
0 commit comments