git.iko.soy/typeable/attoparsec
on master help sign in
Only use Sci.scientific to construct the final Scientific
613f166Bas van Dijk
Data/Attoparsec/ByteString/Char8.hs+13−10
@@ -551,6 +551,9 @@ number = scientifically $ \s ->
551scientific :: Parser Scientific
551scientific :: Parser Scientific
552scientific = scientifically id
552scientific = scientifically id
553
553
554+-- A strict pair
555+data SP = SP !Integer {-# UNPACK #-}!Int
556+
554{-# INLINE scientifically #-}
557{-# INLINE scientifically #-}
555scientifically :: (Scientific -> a) -> Parser a
558scientifically :: (Scientific -> a) -> Parser a
556scientifically h = do
559scientifically h = do
@@ -563,21 +566,21 @@ scientifically h = do
563
566
564 n <- decimal
567 n <- decimal
565
568
566− let f fracDigits = Sci.scientific (B8.foldl' step n fracDigits)
569+ let f fracDigits = SP (B8.foldl' step n fracDigits)
567− (negate $ B8.length fracDigits)
570+ (negate $ B8.length fracDigits)
568 step a w = a * 10 + fromIntegral (w - 48)
571 step a w = a * 10 + fromIntegral (w - 48)
569
572
570 dotty <- I.peekWord8
573 dotty <- I.peekWord8
571 -- '.' -> ascii 46
574 -- '.' -> ascii 46
572− s <- case dotty of
575+ SP c e <- case dotty of
573− Just 46 -> I.anyWord8 *> (f <$> I.takeWhile isDigit_w8)
576+ Just 46 -> I.anyWord8 *> (f <$> I.takeWhile isDigit_w8)
574− _ -> pure (Sci.scientific n 0)
577+ _ -> pure (SP n 0)
575
578
576− let !signedCoeff | positive = coefficient s
579+ let !signedCoeff | positive = c
577− | otherwise = negate $ coefficient s
580+ | otherwise = -c
578
581
579 let littleE = 101
582 let littleE = 101
580 bigE = 69
583 bigE = 69
581− (I.satisfy (\c -> c == littleE || c == bigE) *>
584+ (I.satisfy (\ex -> ex == littleE || ex == bigE) *>
582− fmap (h . Sci.scientific signedCoeff . (base10Exponent s +)) (signed decimal)) <|>
585+ fmap (h . Sci.scientific signedCoeff . (e +)) (signed decimal)) <|>
583− return (h $ Sci.scientific signedCoeff (base10Exponent s))
586+ return (h $ Sci.scientific signedCoeff e)
Data/Attoparsec/Text.hs+12−9
@@ -400,6 +400,9 @@ number = scientifically $ \s ->
400scientific :: Parser Scientific
400scientific :: Parser Scientific
401scientific = scientifically id
401scientific = scientifically id
402
402
403+-- A strict pair
404+data SP = SP !Integer {-# UNPACK #-}!Int
405+
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
408
411
409 n <- decimal
412 n <- decimal
410
413
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)
414
417
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)
417
420
418− let !signedCoeff | positive = coefficient s
421+ let !signedCoeff | positive = c
419− | otherwise = negate $ coefficient s
422+ | otherwise = -c
420
423
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)
424
427
425-- | Parse a single digit, as recognised by 'isDigit'.
428-- | Parse a single digit, as recognised by 'isDigit'.
426digit :: Parser Char
429digit :: Parser Char