Skip to content

Commit 15d8496

Browse files
committed
Add utility property for adding backticks
1 parent 5bc624d commit 15d8496

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

Sources/SwiftSyntaxBuilderGeneration/String+Extensions.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,5 @@ import Foundation
1414

1515
extension StringProtocol {
1616
var withFirstCharacterLowercased: String { prefix(1).lowercased() + dropFirst() }
17+
var backticked: String { "`\(self)`" }
1718
}

Sources/SwiftSyntaxBuilderGeneration/Templates/TokensFile.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@ let tokensFile = SourceFile {
3535
// We need to use `CodeBlock` here to ensure there is braces around.
3636

3737
let accessor = CodeBlock {
38-
FunctionCallExpr(MemberAccessExpr(base: "TokenSyntax", name: "\(token.swiftKind)"))
38+
FunctionCallExpr(MemberAccessExpr(base: "TokenSyntax", name: token.swiftKind))
3939
}
4040

41-
createTokenSyntaxPatternBinding("`\(token.name.withFirstCharacterLowercased)`", accessor: accessor)
41+
createTokenSyntaxPatternBinding(token.name.withFirstCharacterLowercased.backticked, accessor: accessor)
4242
}
4343
} else if let text = token.text {
4444
VariableDecl(
@@ -51,7 +51,7 @@ let tokensFile = SourceFile {
5151
FunctionCallExpr(MemberAccessExpr(base: "TokenSyntax", name: "\(token.swiftKind)Token"))
5252
}
5353

54-
createTokenSyntaxPatternBinding("`\(token.name.withFirstCharacterLowercased)`", accessor: accessor)
54+
createTokenSyntaxPatternBinding(token.name.withFirstCharacterLowercased.backticked, accessor: accessor)
5555
}
5656
}
5757
// TokenSyntax with custom text already has a static constructor function defined in SwiftSyntax.

0 commit comments

Comments
 (0)