Skip to content

Commit 391cb70

Browse files
committed
Fix lexing of hexadecimal floating literals
1 parent 6c287ff commit 391cb70

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

Sources/SwiftParser/Lexer.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1439,7 +1439,7 @@ extension Lexer.Cursor {
14391439
return .integerLiteral
14401440
}
14411441

1442-
self.advance(while: { $0.isDigit || $0 == Unicode.Scalar("_") })
1442+
self.advance(while: { $0.isHexDigit || $0 == Unicode.Scalar("_") })
14431443

14441444
if !self.isAtEndOfFile, self.peek() != UInt8(ascii: "p") && self.peek() != UInt8(ascii: "P") {
14451445
if !Unicode.Scalar(PtrOnDot!.peek(at: 1)).isDigit {

Tests/SwiftParserTest/LexerTests.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ public class LexerTests: XCTestCase {
130130
0xff.0p2
131131
-0xff.0p2
132132
+0xff.0p2
133+
0x1.921fb4p1
133134
"""
134135
data.withUTF8 { buf in
135136
let lexemes = Lexer.lex(buf)
@@ -146,6 +147,7 @@ public class LexerTests: XCTestCase {
146147
lexeme(.floatingLiteral, "0xff.0p2"),
147148
lexeme(.prefixOperator, "\n+", leading: 1),
148149
lexeme(.floatingLiteral, "0xff.0p2"),
150+
lexeme(.floatingLiteral, "\n0x1.921fb4p1", leading: 1),
149151
lexeme(.eof, ""),
150152
])
151153
}

0 commit comments

Comments
 (0)