Copyright | (c) Dong Han 2017-2019 |
---|---|
License | BSD |
Maintainer | winterland1989@gmail.com |
Stability | experimental |
Portability | non-portable |
Safe Haskell | None |
Language | Haskell2010 |
Textual numeric parsers.
decimal
int :: Integral a => Parser a Source #
Parse a decimal number with an optional leading '+'
or '-'
sign
character.
hex
hex :: (Integral a, Bits a) => Parser a Source #
Parse and decode an unsigned hex number. The hex digits
'a'
through 'f'
may be upper or lower case.
This parser does not accept a leading "0x"
string, and consider
sign bit part of the binary hex nibbles, i.e.
'parse hex "0xFF" == Right (-1 :: Int8)'
fractional
rational :: Fractional a => Parser a Source #
Parse a rational number.
The syntax accepted by this parser is the same as for double
.
Note: this parser is not safe for use with inputs from untrusted
sources. An input with a suitably large exponent such as
"1e1000000000"
will cause a huge Integer
to be allocated,
resulting in what is effectively a denial-of-service attack.
In most cases, it is better to use double
or scientific
instead.
double :: Parser Double Source #
Parse a rational number and round to Double
.
This parser accepts an optional leading sign character, followed by
at least one decimal digit. The syntax similar to that accepted by
the read
function, with the exception that a trailing '.'
or
'e'
not followed by a number is not consumed.
Examples with behaviour identical to read
:
parseOnly double "3" == Right ("",1,3.0) parseOnly double "3.1" == Right ("",3,3.1) parseOnly double "3e4" == Right ("",3,30000.0) parseOnly double "3.1e4" == Right ("",5,31000.0)
parseOnly double ".3" == Left (".3",0,"takeWhile1") parseOnly double "e3" == Left ("e3",0,"takeWhile1")
Examples of differences from read
:
parseOnly double "3.foo" == Right (".foo",1,3.0) parseOnly double "3e" == Right ("e",1,3.0)
This function does not accept string representations of "NaN" or "Infinity".
scientific :: Parser Scientific Source #
Parse a scientific number.
The syntax accepted by this parser is the same as for double
.
scientifically :: (Scientific -> a) -> Parser a Source #
Parse a scientific number and convert to result using a user supply function.
The syntax accepted by this parser is the same as for double
.