From 9d6bd7f097db83a196e41930978ca771768e46dd Mon Sep 17 00:00:00 2001 From: Ilya Rezvov Date: Fri, 19 Jan 2018 11:06:38 -0800 Subject: [PATCH] fix hex float exponent parsing --- src/Language/Wasm/Lexer.x | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Language/Wasm/Lexer.x b/src/Language/Wasm/Lexer.x index 4de4b0e..ad5193c 100644 --- a/src/Language/Wasm/Lexer.x +++ b/src/Language/Wasm/Lexer.x @@ -41,7 +41,7 @@ $doublequote = \" @float = @floatfrac | @scientificint | @scientificfloat @hexfloatfrac = "0x" @hexnum "." (@hexnum)? @hexexp = [Pp] $sign? @num -@hexscientificint = "0x" @hexnum @exp +@hexscientificint = "0x" @hexnum @hexexp @hexscientificfloat = @hexfloatfrac @hexexp @hexfloat = @hexfloatfrac | @hexscientificint | @hexscientificfloat @nanhex = "nan:0x" @hexnum @@ -134,7 +134,7 @@ parseDecFloat = token $ \(pos, _, s, _) len -> parseHexFloat :: AlexAction Lexeme parseHexFloat = token $ \(pos, _, s, _) len -> let (sign, slen) = parseSign s in - let ('0' : 'x' : str) = filter (/= '_') $ takeChars len $ LBS.drop slen s in + let ('0' : 'x' : str) = filter (/= '_') $ takeChars (len - slen) $ LBS.drop slen s in Lexeme pos $ TFloatLit $ readHexFloat str startBlockComment :: AlexAction Lexeme @@ -333,6 +333,8 @@ readHexFloat str = where readHexExp :: String -> Double readHexExp [] = 1 + readHexExp ('+' : rest) = readHexExp rest + readHexExp ('-' : rest) = negate $ readHexExp rest readHexExp expStr = 2 * read expStr readHexFrac :: String -> Double