From 65db7933c987c2337744799870efe638a8f2b1c9 Mon Sep 17 00:00:00 2001 From: ZacNugent Date: Sun, 8 Oct 2017 14:01:39 +0100 Subject: [PATCH] return error on invalid binary/octal/hex intege (#118) * return error on invalid binary/octal/hex intege * add tests, fix typo * fix for hex-floats --- src/lexer.jl | 3 +++ test/lexer.jl | 9 +++++++++ 2 files changed, 12 insertions(+) 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