diff --git a/src/lexer.jl b/src/lexer.jl index ed50657..2f4eb55 100644 --- a/src/lexer.jl +++ b/src/lexer.jl @@ -628,6 +628,7 @@ function lex_digit(l::Lexer, kind) kind == Tokens.INTEGER if pc == 'x' readchar(l) + !(ishex(ppc) || ppc =='.') && return emit_error(l) accept_number(l, ishex) if accept(l, '.') accept_number(l, ishex) @@ -638,9 +639,11 @@ function lex_digit(l::Lexer, kind) accept_number(l, isdigit) end elseif pc == 'b' + !isbinary(ppc) && return emit_error(l) readchar(l) accept_number(l, isbinary) elseif pc == 'o' + !isoctal(ppc) && return emit_error(l) readchar(l) accept_number(l, isoctal) end diff --git a/test/lexer.jl b/test/lexer.jl index 0e2122e..62f4467 100644 --- a/test/lexer.jl +++ b/test/lexer.jl @@ -461,3 +461,12 @@ end @test length(collect(tokenize("`\$(#=inline ) comment=#``)`"))) == 3 @test length(collect(tokenize("`\$(\"inline ) string\"*string(``))`"))) == 3 end + + +@testset "hex/bin/octal errors" begin +@test tok("0x").kind == T.ERROR +@test tok("0b").kind == T.ERROR +@test tok("0o").kind == T.ERROR +@test tok("0x 2", 1).kind == T.ERROR +@test tok("0x.1p1").kind == T.FLOAT +end