Skip to content

Commit 58554b0

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 cb0ddcf commit 58554b0

16 files changed

+409
-206
lines changed

Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ let package = Package(
9797
),
9898
.target(
9999
name: "SwiftParser",
100-
dependencies: ["SwiftDiagnostics", "SwiftSyntax"],
100+
dependencies: ["SwiftSyntax"],
101101
exclude: [
102102
"CMakeLists.txt",
103103
"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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1584,7 +1584,7 @@ extension Parser {
15841584
wholeText: wholeText,
15851585
textRange: textRange,
15861586
presence: .present,
1587-
hasLexerError: false,
1587+
lexerError: nil,
15881588
arena: self.arena
15891589
)
15901590
}

0 commit comments

Comments
 (0)