Skip to content

Commit c9b63d1

Browse files
committed
Make LexemeSequence CustomDebugStringConvertible
1 parent 1303cc1 commit c9b63d1

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

Sources/SwiftParser/Lexer.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ public struct Lexer {
107107
extension Lexer {
108108
/// A sequence of ``Lexer/Lexeme`` tokens starting from a ``Lexer/Cursor``
109109
/// that points into an input buffer.
110-
public struct LexemeSequence: IteratorProtocol, Sequence {
110+
public struct LexemeSequence: IteratorProtocol, Sequence, CustomDebugStringConvertible {
111111
fileprivate let start: Lexer.Cursor
112112
fileprivate var cursor: Lexer.Cursor
113113
fileprivate var nextToken: Lexer.Lexeme
@@ -154,6 +154,10 @@ extension Lexer {
154154
func peek() -> Lexer.Lexeme {
155155
return self.nextToken
156156
}
157+
158+
public var debugDescription: String {
159+
return self.nextToken.debugDescription + String(syntaxText: SyntaxText(baseAddress: self.cursor.input.baseAddress, count: self.cursor.input.count))
160+
}
157161
}
158162

159163
@_spi(RawSyntax)

Sources/SwiftParser/SwiftParser.docc/FixingBugs.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Guide to write test cases in the parser’s test suite and how to debug failures
44

55
The general approach to fixing bugs in the parser is to first write an automated test case that reproduces the test case in isolation. This allows you to invoke the parser with minimal dependencies and allows you to set breakpoints inside of it.
66

7-
Once you’ve written a test case (see below), set a breakpoint in `Parser.parseSourceFile` and navigate the debugger to the place where the parser behaves unexpectedly. While the debugger is stopped at an instance function in <doc:SwiftParser/Parser>, `po self.currentToken` can show you the next token that will be parsed.
7+
Once you’ve written a test case (see below), set a breakpoint in `Parser.parseSourceFile` and navigate the debugger to the place where the parser behaves unexpectedly. While the debugger is stopped at an instance function in <doc:SwiftParser/Parser>, `po self.currentToken` can show you the next token that will be parsed. `po self.lexemes` can show the next tokens that will be parsed.
88

99
## Round-Trip Failure or Parser Crash
1010

0 commit comments

Comments
 (0)