Skip to content

Commit 80cd97b

Browse files
committed
Refactor the lexer to store lexer errors in the tokens instead of having a diagnosticsHandler
Instead of marking a token as having an error and relying on re-lexing to emit a diagnostic, store the type of error and the offset at which it occurred in the token itself. This is a more sound design IMO and will continue to work even if we introduce state into the lexer (e.g. whether we are currently in a string literal or inside a conflict marker range).
1 parent 99d72b4 commit 80cd97b

16 files changed

+340
-156
lines changed

Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ let package = Package(
102102
),
103103
.target(
104104
name: "SwiftParser",
105-
dependencies: ["SwiftDiagnostics", "SwiftSyntax"],
105+
dependencies: ["SwiftSyntax"],
106106
exclude: [
107107
"CMakeLists.txt",
108108
"README.md",

Sources/SwiftParser/Declarations.swift

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1222,9 +1222,8 @@ extension Parser {
12221222
(buffer: UnsafeBufferPointer<UInt8>) -> Bool in
12231223
var cursor = Lexer.Cursor(input: buffer, previous: 0)
12241224
guard buffer[0] == UInt8(ascii: "/") else { return false }
1225-
1226-
switch (cursor.lexOperatorIdentifier(cursor, cursor)) {
1227-
case (.unknown, _):
1225+
switch cursor.lexOperatorIdentifier(cursor, cursor).tokenKind {
1226+
case .unknown:
12281227
return false
12291228

12301229
default:

Sources/SwiftParser/Expressions.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1540,7 +1540,8 @@ extension Parser {
15401540
wholeText: wholeText,
15411541
textRange: textRange,
15421542
presence: .present,
1543-
hasLexerError: false,
1543+
lexerError: nil,
1544+
lexerErrorOffset: 0,
15441545
arena: self.arena
15451546
)
15461547
}

0 commit comments

Comments
 (0)