Skip to content

Commit 0dbff53

Browse files
author
Kristoffer Carlsson
authored
require a number after 'p' for hex floats to lex as a float (#52)
1 parent 8516156 commit 0dbff53

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

src/tokenize.jl

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -766,15 +766,17 @@ function lex_xor(l::Lexer)
766766
end
767767

768768
function accept_number(l::Lexer, f::F) where {F}
769+
lexed_number = false
769770
while true
770771
pc, ppc = dpeekchar(l)
771772
if pc == '_' && !f(ppc)
772-
return
773+
return lexed_number
773774
elseif f(pc) || pc == '_'
774775
readchar(l)
775776
else
776-
return
777+
return lexed_number
777778
end
779+
lexed_number = true
778780
end
779781
end
780782

@@ -864,7 +866,9 @@ function lex_digit(l::Lexer, kind)
864866
if accept(l, "pP")
865867
kind = K"Float"
866868
accept(l, "+-−")
867-
accept_number(l, isdigit)
869+
if !accept_number(l, isdigit)
870+
return emit_error(l, K"ErrorInvalidNumericConstant")
871+
end
868872
elseif isfloat
869873
return emit_error(l, K"ErrorInvalidNumericConstant")
870874
end

test/tokenize.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -589,6 +589,7 @@ end
589589
@test kind.(collect(tokenize("3.2e2.2"))) == [K"ErrorInvalidNumericConstant", K"Integer", K"EndMarker"]
590590
@test kind.(collect(tokenize("3e2.2"))) == [K"ErrorInvalidNumericConstant", K"Integer", K"EndMarker"]
591591
@test kind.(collect(tokenize("0b101__101"))) == [K"BinInt", K"Identifier", K"EndMarker"]
592+
@test tok("0x1p").kind == K"ErrorInvalidNumericConstant"
592593
end
593594

594595
@testset "floating points" begin

0 commit comments

Comments
 (0)