@@ -32,6 +32,7 @@ type Lexer a = Text -> Either String (a,Text)
3232-- | Read a decimal number.
3333decimal :: Integral a => Lexer a
3434{-# SPECIALIZE decimal :: Lexer Int #-}
35+{-# SPECIALIZE decimal :: Lexer Integer #-}
3536decimal txt
3637 | T.null h = Left "no digits in input"
3738 | otherwise = Right (T.foldl' go 0 h, t)
@@ -42,6 +43,7 @@ decimal txt
4243-- function is case insensitive.
4344hexadecimal :: Integral a => Lexer a
4445{-# SPECIALIZE hex :: Lexer Int #-}
46+{-# SPECIALIZE hex :: Lexer Integer #-}
4547hexadecimal txt
4648 | T.toLower h == "0x" = hex t
4749 | otherwise = hex txt
@@ -49,6 +51,7 @@ hexadecimal txt
4951
5052hex :: Integral a => Lexer a
5153{-# SPECIALIZE hex :: Lexer Int #-}
54+{-# SPECIALIZE hex :: Lexer Integer #-}
5255hex txt
5356 | T.null h = Left "no digits in input"
5457 | otherwise = Right (T.foldl' go 0 h, t)
@@ -69,7 +72,8 @@ signed :: Num a => Lexer a -> Lexer a
6972signed f = runP (signa (P f))
7073
7174signa :: Num a => Parser a -> Parser a
72−{-# SPECIALIZE signa :: Parser Int -> Parser Int #-}
75+{-# SPECIALIZE signa :: Parser Int -> Parser Int #-}
76+{-# SPECIALIZE signa :: Parser Integer -> Parser Integer #-}
7377signa p = do
7478 sign <- perhaps '+' $ char (`elem` "-+")
7579 if sign == '+' then p else negate `liftM` p
@@ -108,6 +112,11 @@ rational = runP $ do
108112 n <- P decimal
109113 return (n, digits)
110114 power <- perhaps 0 (char (`elem` "eE") >> signa (P decimal) :: Parser Int)
111− return $! fromRational ((real % 1 + fraction % (10 ^ fracDigits)) *
112− (10 ^ power))
115+ return $! if fraction == 0
116+ then if power == 0
117+ then fromIntegral real
118+ else fromIntegral real * (10 ^^ power)
119+ else fromRational $ if power == 0
120+ then real % 1 + fraction % (10 ^ fracDigits)
121+ else (real % 1 + fraction % (10 ^ fracDigits)) * (10 ^^ power)
113122