Skip to content

Commit c648e85

Browse files
committed
Make lexUnknown peek-based
1 parent c5e4ef3 commit c648e85

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

Sources/SwiftParser/Lexer/Cursor.swift

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -790,7 +790,8 @@ extension Lexer.Cursor {
790790
return result
791791
}
792792

793-
let unknownClassification = self.lexUnknown(tokenStart: start)
793+
let unknownClassification = start.lexUnknown()
794+
self = start
794795
assert(unknownClassification == .lexemeContents, "Invalid UTF-8 sequence should be eaten by lexTrivia as LeadingTrivia")
795796
return Lexer.Result(.unknown)
796797
}
@@ -919,7 +920,9 @@ extension Lexer.Cursor {
919920
break
920921
}
921922

922-
if self.lexUnknown(tokenStart: start) == .trivia {
923+
// `lexUnknown` expects that the first character has not been consumed yet.
924+
self = start
925+
if self.lexUnknown() == .trivia {
923926
continue
924927
} else {
925928
break
@@ -2010,9 +2013,9 @@ extension Lexer.Cursor {
20102013
/// Assuming the cursor is positioned at neighter a valid identifier nor a
20112014
/// valid operator start, advance the cursor by what can be considered a
20122015
/// lexeme.
2013-
mutating func lexUnknown(tokenStart: Lexer.Cursor) -> UnknownCharactersClassification {
2014-
assert(tokenStart.peekScalar()?.isValidIdentifierStartCodePoint == false && tokenStart.peekScalar()?.isOperatorStartCodePoint == false)
2015-
var tmp = tokenStart
2016+
mutating func lexUnknown() -> UnknownCharactersClassification {
2017+
assert(self.peekScalar()?.isValidIdentifierStartCodePoint == false && self.peekScalar()?.isOperatorStartCodePoint == false)
2018+
var tmp = self
20162019
if tmp.advance(if: { Unicode.Scalar($0).isValidIdentifierContinuationCodePoint }) {
20172020
// If this is a valid identifier continuation, but not a valid identifier
20182021
// start, attempt to recover by eating more continuation characters.

0 commit comments

Comments
 (0)