lathe-0.1.0.0: Pure incremental byte parser.
Safe HaskellSafe-Inferred
LanguageHaskell2010

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

Representation

Signed

data Sign Source #

Whether the number is positive or negative.

Constructors

Plus 
Minus 

Instances

Instances details
Show Sign Source # 
Instance details

Defined in Parser.Lathe.Numeric.Internal

Methods

showsPrec :: Int -> Sign -> ShowS #

show :: Sign -> String #

showList :: [Sign] -> ShowS #

newtype WholeInt word Source #

Intermediate representation of a signed integer.

Constructors

WholeInt word

Number as an unsigned integer.

Instances

Instances details
Show word => Show (WholeInt word) Source # 
Instance details

Defined in Parser.Lathe.Numeric.Integral

Methods

showsPrec :: Int -> WholeInt word -> ShowS #

show :: WholeInt word -> String #

showList :: [WholeInt word] -> ShowS #

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

wholeWord8Dec Source #

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.

wholeWord16Dec Source #

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.

wholeWord32Dec Source #

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.

wholeWord64Dec Source #

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.

wholeWordDec Source #

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

wholeInt8Dec Source #

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.

wholeInt16Dec Source #

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.

wholeInt32Dec Source #

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.

wholeInt64Dec Source #

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.

wholeIntDec Source #

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

wholeWord8Hex Source #

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.

wholeWord16Hex Source #

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.

wholeWord32Hex Source #

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.

wholeWord64Hex Source #

Arguments

:: overflow 
-> Word64 
-> Int

Number of hexadecimal digits consumed by this number.

-> Parser overflow (Word64, Int) 

Consume up to 16 hexadecimal digits into a Word64.

wholeWordHex Source #

Arguments

:: overflow 
-> Word 
-> Int

Number of hexadecimal digits consumed by this number.

-> Parser overflow (Word, Int) 

Consume up to 8 or 16 hexadecimal digits (depending on current platform's integer size) into a Word.