Skip to content

Commit cb6532d

Browse files
committed
Added TokenSyntax identifier property
This acts as a convenience property to convert a TokenSyntax to an Identifier
1 parent 8f4cb4c commit cb6532d

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

Sources/SwiftSyntax/Identifier.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
//===----------------------------------------------------------------------===//
1212

1313
/// An abstraction for sanitized values on a token.
14-
public struct Identifier {
14+
public struct Identifier: Equatable {
1515
/// The sanitized `text` of a token.
1616
public let name: String
1717

Sources/SwiftSyntax/TokenSyntax.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,11 @@ public struct TokenSyntax: SyntaxProtocol, SyntaxHashable {
153153
}
154154
}
155155

156+
/// An identifier created from `self`.
157+
public var identifier: Identifier {
158+
Identifier(self)
159+
}
160+
156161
/// A token by itself has no structure, so we represent its structure by an
157162
/// empty layout node.
158163
///

Tests/SwiftSyntaxTest/IdentifierTests.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,9 @@ class IdentifierTests: XCTestCase {
2424
let multiBacktickedToken = TokenSyntax(stringLiteral: "```backtickedtoken```")
2525
XCTAssertEqual(Identifier(multiBacktickedToken).name, "backtickedtoken")
2626
}
27+
28+
public func testTokenSyntaxIdentifier() {
29+
let tokenSyntax = TokenSyntax(stringLiteral: "sometoken")
30+
XCTAssertEqual(tokenSyntax.identifier, Identifier(tokenSyntax))
31+
}
2732
}

0 commit comments

Comments
 (0)