Skip to content

Commit 1303cc1

Browse files
committed
Add debug description to lexeme printing the lexeme’s content
1 parent 4f11eb0 commit 1303cc1

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
public struct Flags: OptionSet {
2727
public var rawValue: UInt8
2828

@@ -97,6 +97,10 @@ public struct Lexer {
9797
SyntaxText(baseAddress: start.advanced(by: leadingTriviaByteLength+textByteLength),
9898
count: trailingTriviaByteLength)
9999
}
100+
101+
public var debugDescription: String {
102+
return String(syntaxText: SyntaxText(baseAddress: start, count: byteLength))
103+
}
100104
}
101105
}
102106

0 commit comments

Comments
 (0)