Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Parser.Lathe.Numeric.Integral
Description
Functions for parsing bounded integers expressed as numbers with no fractional part or exponent.
Parsing functions in this module are only guaranteed to operate correctly when their arguments are sensible and the input number has no leading zeroes.
Example
Converting "-123,040,567 "
to an Int32
, skipping operations
outside of this module:
>>>parse
(wholeInt32Dec
() Minus (WholeInt 0) 0) "123,040,567 " (Scrap 3 ",040,567 " End,Right (WholeInt 123,3)) >>> parse (wholeInt32Dec () Minus (WholeInt 123) 3) "040,567 " (Scrap 3 ",567 " End,Right (WholeInt 123040,6)) >>> parse (wholeInt32Dec () Minus (WholeInt 123040) 6) "567 " (Scrap 3 " " End,Right (WholeInt 123040567,9)) >>>wholeToInt32
Minus (WholeInt 123040567) -123040567
Synopsis
- data Sign
- newtype WholeInt word = WholeInt word
- wholeToInt8 :: Sign -> WholeInt Word8 -> Int8
- wholeToInt16 :: Sign -> WholeInt Word16 -> Int16
- wholeToInt32 :: Sign -> WholeInt Word32 -> Int32
- wholeToInt64 :: Sign -> WholeInt Word64 -> Int64
- wholeToInt :: Sign -> WholeInt Word -> Int
- wholeWord8Dec :: overflow -> Word8 -> Int -> Parser overflow (Word8, Int)
- wholeWord16Dec :: overflow -> Word16 -> Int -> Parser overflow (Word16, Int)
- wholeWord32Dec :: overflow -> Word32 -> Int -> Parser overflow (Word32, Int)
- wholeWord64Dec :: overflow -> Word64 -> Int -> Parser overflow (Word64, Int)
- wholeWordDec :: overflow -> Word -> Int -> Parser overflow (Word, Int)
- wholeNaturalDec :: Natural -> Parser never Natural
- wholeInt8Dec :: overflow -> Sign -> WholeInt Word8 -> Int -> Parser overflow (WholeInt Word8, Int)
- wholeInt16Dec :: overflow -> Sign -> WholeInt Word16 -> Int -> Parser overflow (WholeInt Word16, Int)
- wholeInt32Dec :: overflow -> Sign -> WholeInt Word32 -> Int -> Parser overflow (WholeInt Word32, Int)
- wholeInt64Dec :: overflow -> Sign -> WholeInt Word64 -> Int -> Parser overflow (WholeInt Word64, Int)
- wholeIntDec :: overflow -> Sign -> WholeInt Word -> Int -> Parser overflow (WholeInt Word, Int)
- wholeWord8Hex :: overflow -> Word8 -> Int -> Parser overflow (Word8, Int)
- wholeWord16Hex :: overflow -> Word16 -> Int -> Parser overflow (Word16, Int)
- wholeWord32Hex :: overflow -> Word32 -> Int -> Parser overflow (Word32, Int)
- wholeWord64Hex :: overflow -> Word64 -> Int -> Parser overflow (Word64, Int)
- wholeWordHex :: overflow -> Word -> Int -> Parser overflow (Word, Int)
Representation
Signed
Whether the number is positive or negative.
newtype WholeInt word Source #
Intermediate representation of a signed integer.
Constructors
WholeInt word | Number as an unsigned integer. |
Conversions
wholeToInt8 :: Sign -> WholeInt Word8 -> Int8 Source #
Convert the intermediate representation into an Int8
.
wholeToInt16 :: Sign -> WholeInt Word16 -> Int16 Source #
Convert the intermediate representation into an Int16
.
wholeToInt32 :: Sign -> WholeInt Word32 -> Int32 Source #
Convert the intermediate representation into an Int32
.
wholeToInt64 :: Sign -> WholeInt Word64 -> Int64 Source #
Convert the intermediate representation into an Int64
.
wholeToInt :: Sign -> WholeInt Word -> Int Source #
Convert the intermediate representation into an Int
.
Parsing
Decimal
Unsigned
Arguments
:: overflow | |
-> Word8 | |
-> Int | Number of decimal digits consumed by this number. |
-> Parser overflow (Word8, Int) |
Consume up to 3 decimal digits into a Word8
.
Arguments
:: overflow | |
-> Word16 | |
-> Int | Number of decimal digits consumed by this number. |
-> Parser overflow (Word16, Int) |
Consume up to 5 decimal digits into a Word16
.
Arguments
:: overflow | |
-> Word32 | |
-> Int | Number of decimal digits consumed by this number. |
-> Parser overflow (Word32, Int) |
Consume up to 10 decimal digits into a Word32
.
Arguments
:: overflow | |
-> Word64 | |
-> Int | Number of decimal digits consumed by this number. |
-> Parser overflow (Word64, Int) |
Consume up to 20 decimal digits into a Word64
.
Arguments
:: overflow | |
-> Word | |
-> Int | Number of decimal digits consumed by this number. |
-> Parser overflow (Word, Int) |
Consume up to 10 or 20 decimal digits
(depending on machine integer size) into a Word
.
wholeNaturalDec :: Natural -> Parser never Natural Source #
Consume any number of decimal digits into a Natural
.
Signed
Arguments
:: overflow | |
-> Sign | |
-> WholeInt Word8 | |
-> Int | Number of decimal digits consumed by this number. |
-> Parser overflow (WholeInt Word8, Int) |
Consume up to 3 decimal digits into an Int8
-compatible container.
Arguments
:: overflow | |
-> Sign | |
-> WholeInt Word16 | |
-> Int | Number of decimal digits consumed by this number. |
-> Parser overflow (WholeInt Word16, Int) |
Consume up to 5 decimal digits into an Int16
-compatible container.
Arguments
:: overflow | |
-> Sign | |
-> WholeInt Word32 | |
-> Int | Number of decimal digits consumed by this number. |
-> Parser overflow (WholeInt Word32, Int) |
Consume up to 10 decimal digits into an Int32
-compatible container.
Arguments
:: overflow | |
-> Sign | |
-> WholeInt Word64 | |
-> Int | Number of decimal digits consumed by this number. |
-> Parser overflow (WholeInt Word64, Int) |
Consume up to 19 decimal digits into an Int64
-compatible container.
Arguments
:: overflow | |
-> Sign | |
-> WholeInt Word | |
-> Int | Number of decimal digits consumed by this number. |
-> Parser overflow (WholeInt Word, Int) |
Consume up to 10 or 19 decimal digits (depending on current platform's integer size)
into an Int
-compatible container.
Hexadecimal
Unsigned
Arguments
:: overflow | |
-> Word8 | |
-> Int | Number of hexadecimal digits consumed by this number. |
-> Parser overflow (Word8, Int) |
Consume up to 2 hexadecimal digits into a Word8
.
Arguments
:: overflow | |
-> Word16 | |
-> Int | Number of hexadecimal digits consumed by this number. |
-> Parser overflow (Word16, Int) |
Consume up to 4 hexadecimal digits into a Word16
.
Arguments
:: overflow | |
-> Word32 | |
-> Int | Number of hexadecimal digits consumed by this number. |
-> Parser overflow (Word32, Int) |
Consume up to 8 hexadecimal digits into a Word32
.