git.iko.soy/typeable/attoparsec
on master help sign in
Fix up docs for rational
commit66424cde735eefd0edcc5024165614882b9303ad authorBryan O'Sullivan <bos@serpentine.com> dateWed 28 May 2014, 23:08 (12 years ago) parenta8eeed8
3 files changed+42−35
Data/Attoparsec/ByteString/Char8.hs+20−18 Data/Attoparsec/Internal/Types.hs+2−2 Data/Attoparsec/Text.hs+20−15
Data/Attoparsec/ByteString/Char8.hs+20−18
@@ -475,6 +475,24 @@ signed p = (negate <$> (char8 '-' *> p))
475475 <|> (char8 '+' *> p)
476476 <|> p
477477
478+-- | Parse a rational number.
479+--
480+-- The syntax accepted by this parser is the same as for 'double'.
481+--
482+-- /Note/: this parser is not safe for use with inputs from untrusted
483+-- sources. An input with a suitably large exponent such as
484+-- @"1e1000000000"@ will cause a huge 'Integer' to be allocated,
485+-- resulting in what is effectively a denial-of-service attack.
486+--
487+-- In most cases, it is better to use 'double' or 'scientific'
488+-- instead.
489+rational :: Fractional a => Parser a
490+{-# SPECIALIZE rational :: Parser Double #-}
491+{-# SPECIALIZE rational :: Parser Float #-}
492+{-# SPECIALIZE rational :: Parser Rational #-}
493+{-# SPECIALIZE rational :: Parser Scientific #-}
494+rational = scientifically realToFrac
495+
478496-- | Parse a rational number.
479497--
480498-- This parser accepts an optional leading sign character, followed by
@@ -502,28 +520,12 @@ signed p = (negate <$> (char8 '-' *> p))
502520--
503521-- This function does not accept string representations of \"NaN\" or
504522-- \"Infinity\".
505−rational :: Fractional a => Parser a
506−{-# SPECIALIZE rational :: Parser Double #-}
507−{-# SPECIALIZE rational :: Parser Float #-}
508−{-# SPECIALIZE rational :: Parser Rational #-}
509−{-# SPECIALIZE rational :: Parser Scientific #-}
510−rational = scientifically realToFrac
511−
512−-- | Parse a rational number.
513−--
514−-- The syntax accepted by this parser is the same as for 'rational'.
515−--
516−-- This function does not accept string representations of \"NaN\" or
517−-- \"Infinity\".
518523double :: Parser Double
519524double = scientifically Sci.toRealFloat
520525
521526-- | Parse a number, attempting to preserve both speed and precision.
522527--
523−-- The syntax accepted by this parser is the same as for 'rational'.
524−--
525− -- This function does not accept string representations of \"NaN\" or
526− -- \"Infinity\".
528+-- The syntax accepted by this parser is the same as for 'double'.
527529number :: Parser Number
528530number = scientifically $ \s ->
529531 let e = Sci.base10Exponent s
@@ -535,7 +537,7 @@ number = scientifically $ \s ->
535537
536538-- | Parse a scientific number.
537539--
538−-- The syntax accepted by this parser is the same as for 'rational'.
540+-- The syntax accepted by this parser is the same as for 'double'.
539541scientific :: Parser Scientific
540542scientific = scientifically id
541543
Data/Attoparsec/Internal/Types.hs+2−2
@@ -72,8 +72,8 @@ instance Functor (IResult i) where
7272 fmap f (Partial k) = Partial (fmap f . k)
7373 fmap f (Done t r) = Done t (f r)
7474
75−-- | The core parser type. This is parameterised over the type @t@ of
76−-- string being processed.
75+-- | The core parser type. This is parameterised over the types @i@
76+-- of string being processed and @t@ of internal state representation.
7777--
7878-- This type is an instance of the following classes:
7979--
Data/Attoparsec/Text.hs+20−15
@@ -324,6 +324,24 @@ signed p = (negate <$> (I.char '-' *> p))
324324 <|> (I.char '+' *> p)
325325 <|> p
326326
327+-- | Parse a rational number.
328+--
329+-- The syntax accepted by this parser is the same as for 'double'.
330+--
331+-- /Note/: this parser is not safe for use with inputs from untrusted
332+-- sources. An input with a suitably large exponent such as
333+-- @"1e1000000000"@ will cause a huge 'Integer' to be allocated,
334+-- resulting in what is effectively a denial-of-service attack.
335+--
336+-- In most cases, it is better to use 'double' or 'scientific'
337+-- instead.
338+rational :: Fractional a => Parser a
339+{-# SPECIALIZE rational :: Parser Double #-}
340+{-# SPECIALIZE rational :: Parser Float #-}
341+{-# SPECIALIZE rational :: Parser Rational #-}
342+{-# SPECIALIZE rational :: Parser Scientific #-}
343+rational = scientifically realToFrac
344+
327345-- | Parse a rational number.
328346--
329347-- This parser accepts an optional leading sign character, followed by
@@ -351,25 +369,12 @@ signed p = (negate <$> (I.char '-' *> p))
351369--
352370-- This function does not accept string representations of \"NaN\" or
353371-- \"Infinity\".
354−rational :: Fractional a => Parser a
355−{-# SPECIALIZE rational :: Parser Double #-}
356−{-# SPECIALIZE rational :: Parser Float #-}
357−{-# SPECIALIZE rational :: Parser Rational #-}
358−{-# SPECIALIZE rational :: Parser Scientific #-}
359−rational = scientifically realToFrac
360−
361−-- | Parse a rational number.
362−--
363−-- The syntax accepted by this parser is the same as for 'rational'.
364−--
365−-- This function does not accept string representations of \"NaN\" or
366−-- \"Infinity\".
367372double :: Parser Double
368373double = scientifically Sci.toRealFloat
369374
370375-- | Parse a number, attempting to preserve both speed and precision.
371376--
372−-- The syntax accepted by this parser is the same as for 'rational'.
377+-- The syntax accepted by this parser is the same as for 'double'.
373378--
374379-- This function does not accept string representations of \"NaN\" or
375380-- \"Infinity\".
@@ -384,7 +389,7 @@ number = scientifically $ \s ->
384389
385390-- | Parse a scientific number.
386391--
387−-- The syntax accepted by this parser is the same as for 'rational'.
392+-- The syntax accepted by this parser is the same as for 'double'.
388393scientific :: Parser Scientific
389394scientific = scientifically id
390395