Skip to content

Commit

Permalink
return error on invalid binary/octal/hex intege (#118)
Browse files Browse the repository at this point in the history
* return error on invalid binary/octal/hex intege

* add tests, fix typo

* fix for hex-floats
  • Loading branch information
ZacLN authored Oct 8, 2017
1 parent 09db64c commit 65db793
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/lexer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down
9 changes: 9 additions & 0 deletions test/lexer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 65db793

Please sign in to comment.