Skip to content

Commit 3a8c221

Browse files
committed
Address comments
1 parent d07cffd commit 3a8c221

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

Sources/SwiftSyntax/Identifier.swift

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13-
/// An abstraction for sanitized values on a token.
13+
/// A canonicalized representation of an identifier that strips away backticks.
1414
public struct Identifier: Equatable, Hashable, Sendable {
1515
/// The sanitized `text` of a token.
1616
public var name: String {
@@ -37,17 +37,16 @@ public struct RawIdentifier: Equatable, Hashable, Sendable {
3737

3838
@_spi(RawSyntax)
3939
fileprivate init(_ raw: RawSyntaxTokenView) {
40-
let backtick = SyntaxText(StaticString(stringLiteral: "`"))
40+
let backtick = SyntaxText("`")
4141
let arena = SyntaxArena()
4242
if raw.rawText.count > 2 && raw.rawText.hasPrefix(backtick) && raw.rawText.hasSuffix(backtick) {
4343
let startIndex = raw.rawText.index(after: raw.rawText.startIndex)
4444
let endIndex = raw.rawText.index(before: raw.rawText.endIndex)
45-
46-
self.name = arena.intern(SyntaxText(rebasing: raw.rawText[startIndex..<endIndex]))
45+
self.name = SyntaxText(rebasing: raw.rawText[startIndex..<endIndex])
4746
} else {
48-
self.name = arena.intern(raw.rawText)
47+
self.name = raw.rawText
4948
}
50-
self.arena = RetainedSyntaxArena(arena)
49+
self.arena = raw.raw.arenaReference.retained
5150
}
5251

5352
public static func == (lhs: RawIdentifier, rhs: RawIdentifier) -> Bool {

Sources/SwiftSyntax/TokenSyntax.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,12 @@ public struct TokenSyntax: SyntaxProtocol, SyntaxHashable {
155155

156156
/// An identifier created from `self`.
157157
public var identifier: Identifier? {
158-
Identifier(self)
158+
switch self.tokenKind {
159+
case .identifier, .dollarIdentifier:
160+
return Identifier(self)
161+
default:
162+
return nil
163+
}
159164
}
160165

161166
/// A token by itself has no structure, so we represent its structure by an

0 commit comments

Comments
 (0)