add nan and inf parsing

This commit is contained in:
Ilya Rezvov
2018-01-19 10:26:10 -08:00
parent 4853e1bdf5
commit 5c4ca137a5
2 changed files with 17 additions and 1 deletions
+16
View File
@@ -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
+1 -1
View File
@@ -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" []