@@ -214,6 +214,8 @@ extension Lexer {
214
214
public struct Cursor : Equatable {
215
215
var input : UnsafeBufferPointer < UInt8 >
216
216
var previous : UInt8
217
+ /// If we have already lexed a token, the kind of the previously lexed token
218
+ var previousTokenKind : RawTokenKind ?
217
219
218
220
@_spi ( LexerDiagnostics)
219
221
public init ( input: UnsafeBufferPointer < UInt8 > , previous: UInt8 ) {
@@ -338,6 +340,10 @@ extension Lexer.Cursor {
338
340
}
339
341
340
342
extension Lexer . Cursor {
343
+ /// Revert the lexer by `offset` bytes. This should only be used by `resetForSplit`.
344
+ /// This must not back up by more bytes than the last token because that would
345
+ /// require us to also update `previousTokenKind`, which we don't do in this
346
+ /// function
341
347
fileprivate mutating func backUp( by offset: Int ) {
342
348
assert ( !self . isAtStartOfFile)
343
349
self . previous = self . input. baseAddress!. advanced ( by: - ( offset + 1 ) ) . pointee
@@ -796,6 +802,9 @@ extension Lexer.Cursor {
796
802
if newlineInLeadingTrivia == . present {
797
803
flags. insert ( . isAtStartOfLine)
798
804
}
805
+
806
+ self . previousTokenKind = kind
807
+
799
808
return . init(
800
809
tokenKind: kind,
801
810
flags: flags,
@@ -1393,7 +1402,15 @@ extension Lexer.Cursor {
1393
1402
if !self . isAtEndOfFile, self . peek ( ) == UInt8 ( ascii: " . " ) {
1394
1403
// NextToken is the soon to be previous token
1395
1404
// Therefore: x.0.1 is sub-tuple access, not x.float_literal
1396
- if self . input. count > 1 , !Unicode. Scalar ( self . peek ( at: 1 ) ) . isDigit || TokStart . previous == UInt8 ( ascii: " . " ) {
1405
+ if self . input. count <= 1 {
1406
+ // If there are no more digits following the '.', we don't have a float
1407
+ // literal.
1408
+ return ( . integerLiteral, [ ] )
1409
+ } else if !Unicode. Scalar ( self . peek ( at: 1 ) ) . isDigit {
1410
+ // ".a" is a member access and certainly not a float literal
1411
+ return ( . integerLiteral, [ ] )
1412
+ } else if self . previousTokenKind == . period {
1413
+ // Lex x.0.1 as sub-tuple access, not x.float_literal.
1397
1414
return ( . integerLiteral, [ ] )
1398
1415
}
1399
1416
} else {
0 commit comments