diff --git a/src/Language/Wasm/Lexer.x b/src/Language/Wasm/Lexer.x index b4ee3b9..4de4b0e 100644 --- a/src/Language/Wasm/Lexer.x +++ b/src/Language/Wasm/Lexer.x @@ -44,10 +44,20 @@ $doublequote = \" @hexscientificint = "0x" @hexnum @exp @hexscientificfloat = @hexfloatfrac @hexexp @hexfloat = @hexfloatfrac | @hexscientificint | @hexscientificfloat +@nanhex = "nan:0x" @hexnum tokens :- <0> $space ; +<0> "nan" { constToken $ TFloatLit nan } +<0> "+nan" { constToken $ TFloatLit nan } +<0> "-nan" { constToken $ TFloatLit minusNaN } +<0> @nanhex { constToken $ TFloatLit nan {- TODO: real hex rep parsing -}} +<0> "+" @nanhex { constToken $ TFloatLit nan {- TODO: real hex rep parsing -}} +<0> "-" @nanhex { constToken $ TFloatLit minusNaN {- TODO: real hex rep parsing -}} +<0> "inf" { constToken $ TFloatLit inf } +<0> "+inf" { constToken $ TFloatLit inf } +<0> "-inf" { constToken $ TFloatLit minusInf } <0> @keyword { tokenStr TKeyword } <0> @linecomment ; <0> @id { tokenStr TId } @@ -87,6 +97,12 @@ isAllowedStringChar _userState (_pos, _rest, inp, _) _len _nextInp = let code = Char.ord char in code >= 0x20 && code /= 0x7f && char /= '"' && char /= '\\' +minusNaN, nan, inf, minusInf :: Double +minusNaN = read "-NaN" +nan = read "NaN" +inf = read "Infinity" +minusInf = read "-Infinity" + parseSign :: (Num a) => LBS.ByteString -> ((a -> a), Int64) parseSign str = let Just (ch, _) = LBSUtf8.decode str in diff --git a/tests/Test.hs b/tests/Test.hs index 1996ff5..46e2d61 100644 --- a/tests/Test.hs +++ b/tests/Test.hs @@ -11,6 +11,6 @@ import qualified Language.Wasm.Lexer as Lexer main :: IO () main = do - file <- LBS.readFile "tests/samples/i64.wast" + file <- LBS.readFile "tests/samples/f64.wast" print $ map Lexer.tok <$> Lexer.scanner file defaultMain $ testGroup "Test Suite" []