diff --git a/Sources/SwiftParser/Lexer/Cursor.swift b/Sources/SwiftParser/Lexer/Cursor.swift index 16f5deb09b1..9717ba1a2fc 100644 --- a/Sources/SwiftParser/Lexer/Cursor.swift +++ b/Sources/SwiftParser/Lexer/Cursor.swift @@ -1772,6 +1772,8 @@ extension Lexer.Cursor { } mutating func lexInStringLiteral(stringLiteralKind: StringLiteralKind, delimiterLength: Int) -> Lexer.Result { + if self.isAtEndOfFile { return .init(.eof) } + var error: LexingDiagnostic? = nil while true { diff --git a/Sources/SwiftParser/Lexer/LexemeSequence.swift b/Sources/SwiftParser/Lexer/LexemeSequence.swift index 138e6f74ba3..266cbe4db9c 100644 --- a/Sources/SwiftParser/Lexer/LexemeSequence.swift +++ b/Sources/SwiftParser/Lexer/LexemeSequence.swift @@ -43,20 +43,7 @@ extension Lexer { mutating func advance() -> Lexer.Lexeme { defer { - if self.cursor.isAtEndOfFile { - self.nextToken = Lexeme( - tokenKind: .eof, - flags: [], - diagnostic: nil, - start: self.cursor.pointer, - leadingTriviaLength: 0, - textLength: 0, - trailingTriviaLength: 0, - cursor: self.cursor - ) - } else { - self.nextToken = self.cursor.nextToken(sourceBufferStart: self.sourceBufferStart, stateAllocator: lexerStateAllocator) - } + self.nextToken = self.cursor.nextToken(sourceBufferStart: self.sourceBufferStart, stateAllocator: lexerStateAllocator) } return self.nextToken }