Skip to content

Commit e7d0494

Browse files
committed
Add debug description to lexeme printing the lexeme’s content
1 parent 104a4c3 commit e7d0494

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

Sources/SwiftParser/Lexer.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public struct Lexer {
2222
/// A lexeme is the fundamental output unit of lexical analysis. Each lexeme
2323
/// represents a fully identified, meaningful part of the input text that
2424
/// will can be consumed by a ``Parser``.
25-
public struct Lexeme {
25+
public struct Lexeme: CustomDebugStringConvertible {
2626
@_spi(RawSyntax)
2727
public var tokenKind: RawTokenKind
2828
public var isAtStartOfLine: Bool
@@ -77,6 +77,10 @@ public struct Lexer {
7777
SyntaxText(baseAddress: start.advanced(by: leadingTriviaByteLength+textByteLength),
7878
count: trailingTriviaByteLength)
7979
}
80+
81+
public var debugDescription: String {
82+
return String(syntaxText: SyntaxText(baseAddress: start, count: byteLength))
83+
}
8084
}
8185
}
8286

0 commit comments

Comments
 (0)