Safe Haskell | None |
---|---|
Language | Haskell2010 |
Flexible numeric parsers for real-world programming languages. These parsers aim to be a superset of the numeric syntaxes across the most popular programming languages.
All parsers assume any trailing whitespace has already been
consumed, and places no requirement for an endOfInput
at the end
of a literal. Be sure to handle these in a calling context. These
parsers do not use TokenParsing
, and therefore
may fail while consuming input, depending on if you use a parser
that automatically backtracks or not. Apply try
if needed.
Synopsis
- integer :: (CharParsing m, Monad m) => m Integer
- natural :: (CharParsing m, Monad m) => m Natural
- decimal :: (CharParsing m, Monad m) => m Integer
- hexadecimal :: forall a m. (Eq a, Num a, CharParsing m, Monad m) => m a
- octal :: forall a m. (Num a, CharParsing m, Monad m) => m a
- binary :: forall a m. (Show a, Num a, CharParsing m, Monad m) => m a
- floating :: (CharParsing m, Monad m) => m Scientific
- signed :: forall a m. (CharParsing m, Num a) => m a -> m a
- imaginary :: forall a m. (CharParsing m, Monad m, Num a) => m a -> m (Complex a)
Documentation
natural :: (CharParsing m, Monad m) => m Natural Source #
Parse a natural number in decimal
, hexadecimal
, octal
, or binary
. As with integer
,
a leading 0
is interpreted as octal. Leading signs are not accepted.
decimal :: (CharParsing m, Monad m) => m Integer Source #
Parse an integer in base 10.
Accepts 0..9
and underscore separators. No leading signs are accepted.
hexadecimal :: forall a m. (Eq a, Num a, CharParsing m, Monad m) => m a Source #
Parse a number in hexadecimal.
Requires a 0x
or 0X
prefix. No leading signs are accepted.
Accepts A..F
, a..f
, 0..9
and underscore separators.
octal :: forall a m. (Num a, CharParsing m, Monad m) => m a Source #
Parse a number in octal.
Requires a 0
, 0o
or 0O
prefix. No leading signs are accepted.
Accepts 0..7
and underscore separators.
binary :: forall a m. (Show a, Num a, CharParsing m, Monad m) => m a Source #
Parse a number in binary.
Requires a 0b
or 0B
prefix. No leading signs are accepted.
Accepts 0
, 1
, and underscore separators.
floating :: (CharParsing m, Monad m) => m Scientific Source #
Parse an arbitrary-precision number with an optional decimal part.
Unlike scientificP
or Scientific's Read
instance, this handles:
- omitted whole parts, e.g.
.5
- omitted decimal parts, e.g.
5.
- exponential notation, e.g.
3.14e+1
- numeric parts, in whole or decimal or exponent parts, with
_
characters - hexadecimal, octal, and binary integer literals, without a decimal part.
You may either omit the whole or the leading part, not both; this parser also rejects the empty string. It does not handle hexadecimal floating-point numbers.
signed :: forall a m. (CharParsing m, Num a) => m a -> m a Source #
Converts a numeric parser to one that accepts an optional leading sign.
imaginary :: forall a m. (CharParsing m, Monad m, Num a) => m a -> m (Complex a) Source #
Converts a numeric parser to one that accepts a trailing imaginary specifier
i
or j
. This does not add facilities for two-valued literals, i.e. 1+4j
,
as those are generally best left to high-level expression facilities.