@@ -292,7 +292,7 @@ extension Lexer {
292
292
self . stateStack. perform ( stateTransition: stateTransition, stateAllocator: stateAllocator)
293
293
}
294
294
295
- func starts( with possiblePrefix: some Sequence < UInt8 > ) -> Bool {
295
+ func starts( with possiblePrefix: SyntaxText ) -> Bool {
296
296
return self . input. starts ( with: possiblePrefix)
297
297
}
298
298
@@ -2036,7 +2036,7 @@ extension Lexer.Cursor {
2036
2036
}
2037
2037
2038
2038
// Special case; allow '`$`'.
2039
- if quote. starts ( with: " `$` " . utf8 ) {
2039
+ if quote. starts ( with: " `$` " ) {
2040
2040
self = quote
2041
2041
let firstBacktickConsumed = self . advance ( matching: " ` " )
2042
2042
let dollarConsumed = self . advance ( matching: " $ " )
@@ -2383,7 +2383,7 @@ extension Lexer.Cursor {
2383
2383
case normal
2384
2384
case perforce
2385
2385
2386
- var introducer : String {
2386
+ var introducer : SyntaxText {
2387
2387
switch self {
2388
2388
case . perforce:
2389
2389
return " >>>> "
@@ -2392,7 +2392,7 @@ extension Lexer.Cursor {
2392
2392
}
2393
2393
}
2394
2394
2395
- var terminator : String {
2395
+ var terminator : SyntaxText {
2396
2396
switch self {
2397
2397
case . perforce:
2398
2398
return " <<<< \n "
@@ -2408,11 +2408,15 @@ extension Lexer.Cursor {
2408
2408
}
2409
2409
2410
2410
// Check to see if we have <<<<<<< or >>>>.
2411
- guard start. starts ( with: " <<<<<<< " . utf8) || start. starts ( with: " >>>> " . utf8) else {
2411
+ let kind : ConflictMarker
2412
+ if start. starts ( with: ConflictMarker . normal. introducer) {
2413
+ kind = . normal
2414
+ } else if start. starts ( with: ConflictMarker . perforce. introducer) {
2415
+ kind = . perforce
2416
+ } else {
2412
2417
return false
2413
2418
}
2414
2419
2415
- let kind = start. is ( at: " < " ) ? ConflictMarker . normal : . perforce
2416
2420
guard let end = Self . findConflictEnd ( start, markerKind: kind) else {
2417
2421
// No end of conflict marker found.
2418
2422
return false
@@ -2432,29 +2436,31 @@ extension Lexer.Cursor {
2432
2436
static func findConflictEnd( _ curPtr: Lexer . Cursor , markerKind: ConflictMarker ) -> Lexer . Cursor ? {
2433
2437
// Get a reference to the rest of the buffer minus the length of the start
2434
2438
// of the conflict marker.
2435
- let advanced = curPtr. input. baseAddress? . advanced ( by: markerKind. introducer. utf8 . count)
2439
+ let advanced = curPtr. input. baseAddress? . advanced ( by: markerKind. introducer. count)
2436
2440
var restOfBuffer = Lexer . Cursor (
2437
- input: . init( start: advanced, count: curPtr. input. count - markerKind. introducer. utf8 . count) ,
2438
- previous: curPtr. input [ markerKind. introducer. utf8 . count - 1 ]
2441
+ input: . init( start: advanced, count: curPtr. input. count - markerKind. introducer. count) ,
2442
+ previous: curPtr. input [ markerKind. introducer. count - 1 ]
2439
2443
)
2444
+ let terminator = markerKind. terminator
2445
+ let terminatorStart = terminator. first!
2440
2446
while !restOfBuffer. isAtEndOfFile {
2441
- let terminatorStart = markerKind. terminator. unicodeScalars. first!
2442
- restOfBuffer. advance ( while: { byte in byte != terminatorStart } )
2447
+ restOfBuffer. advance ( while: { $0. value != terminatorStart } )
2443
2448
2444
- guard restOfBuffer. starts ( with: markerKind . terminator. utf8 ) else {
2449
+ guard restOfBuffer. starts ( with: terminator) else {
2445
2450
_ = restOfBuffer. advance ( )
2446
2451
continue
2447
2452
}
2448
2453
2449
2454
// Must occur at start of line.
2450
2455
guard restOfBuffer. previous == " \n " || restOfBuffer. previous == " \r " else {
2456
+ _ = restOfBuffer. advance ( )
2451
2457
continue
2452
2458
}
2453
2459
2454
- let advanced = restOfBuffer. input. baseAddress? . advanced ( by: markerKind . terminator. utf8 . count)
2460
+ let advanced = restOfBuffer. input. baseAddress? . advanced ( by: terminator. count)
2455
2461
return Lexer . Cursor (
2456
- input: . init( start: advanced, count: restOfBuffer. input. count - markerKind . terminator. utf8 . count) ,
2457
- previous: restOfBuffer. input [ markerKind . terminator. utf8 . count - 1 ]
2462
+ input: . init( start: advanced, count: restOfBuffer. input. count - terminator. count) ,
2463
+ previous: restOfBuffer. input [ terminator. count - 1 ]
2458
2464
)
2459
2465
}
2460
2466
return nil
0 commit comments