@@ -400,6 +400,9 @@ number = scientifically $ \s ->
400scientific :: Parser Scientific
400scientific :: Parser Scientific
401scientific = scientifically id
401scientific = scientifically id
404+data SP = SP !Integer {-# UNPACK #-}!Int
403{-# INLINE scientifically #-}
406{-# INLINE scientifically #-}
404scientifically :: (Scientific -> a) -> Parser a
407scientifically :: (Scientific -> a) -> Parser a
405scientifically h = do
408scientifically h = do
@@ -408,19 +411,19 @@ scientifically h = do
409 n <- decimal
412 n <- decimal
411− let f fracDigits = Sci.scientific (T.foldl' step n fracDigits)
414+ let f fracDigits = SP (T.foldl' step n fracDigits)
412− (negate $ T.length fracDigits)
415+ (negate $ T.length fracDigits)
413 step a c = a * 10 + fromIntegral (ord c - 48)
416 step a c = a * 10 + fromIntegral (ord c - 48)
415− s <- (I.satisfy (=='.') *> (f <$> I.takeWhile isDigit)) <|>
418+ SP c e <- (I.satisfy (=='.') *> (f <$> I.takeWhile isDigit)) <|>
416− pure (Sci.scientific n 0)
419+ pure (SP n 0)
418− let !signedCoeff | positive = coefficient s
421+ let !signedCoeff | positive = c
419− | otherwise = negate $ coefficient s
422+ | otherwise = -c
421− (I.satisfy (\c -> c == 'e' || c == 'E') *>
424+ (I.satisfy (\w -> w == 'e' || w == 'E') *>
422− fmap (h . Sci.scientific signedCoeff . (base10Exponent s +)) (signed decimal)) <|>
425+ fmap (h . Sci.scientific signedCoeff . (e +)) (signed decimal)) <|>
423− return (h $ Sci.scientific signedCoeff (base10Exponent s))
426+ return (h $ Sci.scientific signedCoeff e)
425-- | Parse a single digit, as recognised by 'isDigit'.
428-- | Parse a single digit, as recognised by 'isDigit'.
426digit :: Parser Char
429digit :: Parser Char