Skip to content

Commit 81d61ee

Browse files
committed
TokenSyntax.rawText to get raw token text as SyntaxText
Declare `SyntaxText` as a SPI. and expose `tokenView.rawText`. `SyntaxText` is a byte sequence conforms to `RandomAccessCollection` and has basic query methods e.g. '==', 'hasPrefix(_:)', 'contains(_:)'. It is useful for performance critical logic because it's faster than `TokenSytnax.text` which requies intantiating `TokenKind` often with `Swift.String`.
1 parent 046a603 commit 81d61ee

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

Sources/SwiftSyntax/TokenSyntax.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,11 @@ public struct TokenSyntax: SyntaxProtocol, SyntaxHashable {
7575
return tokenKind.text
7676
}
7777

78+
@_spi(RawSyntax)
79+
public var rawText: SyntaxText {
80+
return tokenView.rawText
81+
}
82+
7883
/// The leading trivia (spaces, newlines, etc.) associated with this token.
7984
public var leadingTrivia: Trivia {
8085
get {

0 commit comments

Comments
 (0)