File tree Expand file tree Collapse file tree 3 files changed +13
-5
lines changed
generate-swiftsyntax/templates/swiftsyntax Expand file tree Collapse file tree 3 files changed +13
-5
lines changed Original file line number Diff line number Diff line change @@ -39,6 +39,14 @@ public struct TokenSpec {
39
39
/// The kind of the token.
40
40
public let kind : Kind
41
41
42
+ /// The text of the token enclosed in double quotes.
43
+ ///
44
+ /// This property is used in code generation where a string representation of the token is needed.
45
+ public var quotedText : TokenSyntax ? {
46
+ guard let text = text else { return nil }
47
+ return " \" \( raw: text) \" "
48
+ }
49
+
42
50
/// The attributes that should be printed on any API for the generated keyword.
43
51
///
44
52
/// This is typically used to mark APIs as SPI when the keyword is part of an experimental language feature.
Original file line number Diff line number Diff line change @@ -62,9 +62,9 @@ let tokenKindFile = SourceFileSyntax(leadingTrivia: copyrightHeader) {
62
62
SwitchCaseSyntax ( " case . \( tokenSpec. varOrCaseName) (let assoc): " ) {
63
63
StmtSyntax ( " return String(syntaxText: assoc.defaultText) " )
64
64
}
65
- } else if let text = tokenSpec. text {
65
+ } else if let quotedText = tokenSpec. quotedText {
66
66
SwitchCaseSyntax ( " case . \( tokenSpec. varOrCaseName) : " ) {
67
- StmtSyntax ( " return # \" \( raw : text ) \" # " )
67
+ StmtSyntax ( " return # \( quotedText ) # " )
68
68
}
69
69
} else {
70
70
SwitchCaseSyntax ( " case . \( tokenSpec. varOrCaseName) (let text): " ) {
@@ -171,9 +171,9 @@ let tokenKindFile = SourceFileSyntax(leadingTrivia: copyrightHeader) {
171
171
) {
172
172
try ! SwitchExprSyntax ( " switch self " ) {
173
173
for tokenSpec in Token . allCases. map ( \. spec) {
174
- if let text = tokenSpec. text {
174
+ if let quotedText = tokenSpec. quotedText {
175
175
SwitchCaseSyntax ( " case . \( tokenSpec. varOrCaseName) : " ) {
176
- StmtSyntax ( " return # \" \( raw : text ) \" # " )
176
+ StmtSyntax ( " return # \( quotedText ) # " )
177
177
}
178
178
}
179
179
}
Original file line number Diff line number Diff line change @@ -18,7 +18,7 @@ import Utils
18
18
let tokensFile = SourceFileSyntax ( leadingTrivia: copyrightHeader) {
19
19
try ! ExtensionDeclSyntax ( " extension TokenSyntax " ) {
20
20
for tokenSpec in Token . allCases. map ( \. spec) {
21
- if let text = tokenSpec . text {
21
+ if tokenSpec . text != nil {
22
22
DeclSyntax (
23
23
"""
24
24
public static func \( tokenSpec. varOrCaseName) Token(
You can’t perform that action at this time.
0 commit comments