forked from GitHub/haskell-wasm
add nan and inf parsing
This commit is contained in:
@@ -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
@@ -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" []
|
||||
|
||||
Reference in New Issue
Block a user