Skip to content

Commit 47952bc

Browse files
committed
Make LexemeSequence CustomDebugStringConvertible
1 parent e7d0494 commit 47952bc

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
@@ -87,7 +87,7 @@ public struct Lexer {
8787
extension Lexer {
8888
/// A sequence of ``Lexer/Lexeme`` tokens starting from a ``Lexer/Cursor``
8989
/// that points into an input buffer.
90-
public struct LexemeSequence: IteratorProtocol, Sequence {
90+
public struct LexemeSequence: IteratorProtocol, Sequence, CustomDebugStringConvertible {
9191
fileprivate let start: Lexer.Cursor
9292
fileprivate var cursor: Lexer.Cursor
9393
fileprivate var nextToken: Lexer.Lexeme
@@ -134,6 +134,10 @@ extension Lexer {
134134
func peek() -> Lexer.Lexeme {
135135
return self.nextToken
136136
}
137+
138+
public var debugDescription: String {
139+
return self.nextToken.debugDescription + String(syntaxText: SyntaxText(baseAddress: self.cursor.input.baseAddress, count: self.cursor.input.count))
140+
}
137141
}
138142

139143
@_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)