@@ -214,6 +214,8 @@ extension Lexer {
214214 public struct Cursor : Equatable {
215215 var input : UnsafeBufferPointer < UInt8 >
216216 var previous : UInt8
217+ /// If we have already lexed a token, the kind of the previously lexed token
218+ var previousTokenKind : RawTokenKind ?
217219
218220 @_spi ( LexerDiagnostics)
219221 public init ( input: UnsafeBufferPointer < UInt8 > , previous: UInt8 ) {
@@ -338,6 +340,10 @@ extension Lexer.Cursor {
338340}
339341
340342extension 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
341347 fileprivate mutating func backUp( by offset: Int ) {
342348 assert ( !self . isAtStartOfFile)
343349 self . previous = self . input. baseAddress!. advanced ( by: - ( offset + 1 ) ) . pointee
@@ -796,6 +802,9 @@ extension Lexer.Cursor {
796802 if newlineInLeadingTrivia == . present {
797803 flags. insert ( . isAtStartOfLine)
798804 }
805+
806+ self . previousTokenKind = kind
807+
799808 return . init(
800809 tokenKind: kind,
801810 flags: flags,
@@ -1393,7 +1402,15 @@ extension Lexer.Cursor {
13931402 if !self . isAtEndOfFile, self . peek ( ) == UInt8 ( ascii: " . " ) {
13941403 // NextToken is the soon to be previous token
13951404 // 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.
13971414 return ( . integerLiteral, [ ] )
13981415 }
13991416 } else {
0 commit comments