File tree Expand file tree Collapse file tree 3 files changed +18
-25
lines changed
Sources/SwiftParser/Lexer Expand file tree Collapse file tree 3 files changed +18
-25
lines changed Original file line number Diff line number Diff line change @@ -649,26 +649,6 @@ extension Lexer.Cursor {
649
649
return nil
650
650
}
651
651
652
- /// If this is the opening delimiter of a raw string literal, return the number
653
- /// of `#` in the raw string delimiter.
654
- /// Assumes that the parser is currently pointing at the character after the first `#`.
655
- /// In other words, the first `#` is expected to already be consumed.
656
- mutating func legacyAdvanceIfOpeningRawStringDelimiter( ) -> Int ? {
657
- assert ( self . previous == UInt8 ( ascii: " # " ) )
658
-
659
- var tmp = self
660
- var length = 1
661
- while tmp. advance ( matching: " # " ) {
662
- length += 1
663
- }
664
-
665
- if tmp. is ( at: #"""# ) {
666
- self = tmp
667
- return length
668
- }
669
- return nil
670
- }
671
-
672
652
/// If we are positioned at the start of a multiline string delimiter, consume
673
653
/// that delimiter and return `true`, otherwise return `false`.
674
654
///
@@ -1515,8 +1495,6 @@ extension Lexer.Cursor {
1515
1495
/// Lexes a single character in a string literal, handling escape sequences
1516
1496
/// like `\n` or `\u{1234}` as a a single character.
1517
1497
mutating func lexCharacterInStringLiteral( stringLiteralKind: StringLiteralKind , delimiterLength: Int ) -> CharacterLex {
1518
- let charStart = self
1519
-
1520
1498
switch self . peek ( ) {
1521
1499
case UInt8 ( ascii: #"""# ) :
1522
1500
let quote = Unicode . Scalar ( self . advance ( ) !)
@@ -1578,8 +1556,6 @@ extension Lexer.Cursor {
1578
1556
return . error( kind)
1579
1557
}
1580
1558
default :
1581
- _ = self . advance ( )
1582
- self = charStart
1583
1559
guard let charValue = self . advanceValidatingUTF8Character ( ) else {
1584
1560
return . error( . invalidUtf8)
1585
1561
}
Original file line number Diff line number Diff line change @@ -181,7 +181,7 @@ extension Unicode.Scalar {
181
181
if encodedBytes == 1 || !Unicode. Scalar ( curByte) . isStartOfUTF8Character {
182
182
// Skip until we get the start of another character. This is guaranteed to
183
183
// at least stop at the nul at the end of the buffer.
184
- while let peeked = peek ( ) , Unicode . Scalar ( peeked) . isStartOfUTF8Character {
184
+ while let peeked = peek ( ) , ! Unicode. Scalar ( peeked) . isStartOfUTF8Character {
185
185
_ = advance ( )
186
186
}
187
187
return nil
Original file line number Diff line number Diff line change @@ -886,6 +886,23 @@ public class LexerTests: XCTestCase {
886
886
}
887
887
}
888
888
889
+ func testInvalidUtf8_3() {
890
+ let sourceBytes: [UInt8] = [0xfd, 0x41] // 0x41 == "A"
891
+
892
+ lex(sourceBytes) { lexemes in
893
+ guard lexemes.count == 2 else {
894
+ return XCTFail("Expected 2 lexemes, got \(lexemes.count)")
895
+ }
896
+ AssertRawBytesLexeme(
897
+ lexemes[0],
898
+ kind: .identifier,
899
+ leadingTrivia: [0xfd],
900
+ text: [0x41],
901
+ error: TokenDiagnostic(.invalidUtf8, byteOffset: 0)
902
+ )
903
+ }
904
+ }
905
+
889
906
func testInterpolatedString() {
890
907
AssertLexemes(
891
908
#"""
You can’t perform that action at this time.
0 commit comments