{-# LANGUAGE Safe #-}
{-# LANGUAGE DataKinds, ConstraintKinds, AllowAmbiguousTypes, KindSignatures, MonoLocalBinds #-}
{-# OPTIONS_GHC -Wno-incomplete-record-updates #-}
{-# OPTIONS_HADDOCK hide #-}
module Text.Gigaparsec.Internal.Token.Numeric (module Text.Gigaparsec.Internal.Token.Numeric) where
import Text.Gigaparsec (Parsec, unit, void, atomic, (<|>), ($>), many, (<:>))
import Text.Gigaparsec.Char (char, oneOf, digit, hexDigit, octDigit, bit)
import Text.Gigaparsec.Combinator (optional, optionalAs)
import Text.Gigaparsec.Token.Descriptions
( BreakCharDesc(BreakCharSupported, NoBreakChar),
NumericDesc( NumericDesc, positiveSign, literalBreakChar
, integerNumbersCanBeHexadecimal, integerNumbersCanBeOctal
, integerNumbersCanBeBinary
, realNumbersCanBeHexadecimal, realNumbersCanBeOctal, realNumbersCanBeBinary
, hexadecimalLeads, octalLeads, binaryLeads
, leadingDotAllowed, trailingDotAllowed
, decimalExponentDesc, hexadecimalExponentDesc
, octalExponentDesc, binaryExponentDesc
),
ExponentDesc(NoExponents, ExponentsSupported, compulsory, chars, base, expSign, expLeadingZerosAllowd),
PlusSignPresence(PlusIllegal, PlusRequired, PlusOptional) )
import Text.Gigaparsec.Internal.Token.Generic (
GenericNumeric( plainDecimal, plainHexadecimal, plainOctal, plainBinary
, zeroAllowedDecimal, zeroAllowedHexadecimal, zeroAllowedOctal, zeroAllowedBinary
, zeroNotAllowedDecimal )
)
import Text.Gigaparsec.Internal.Token.BitBounds (
CanHoldUnsigned, CanHoldSigned,
BitBounds(upperSigned, upperUnsigned, lowerSigned),
Bits(B8, B16, B32, B64), bits
)
import Text.Gigaparsec.Token.Errors (
ErrorConfig ( filterIntegerOutOfBounds
, labelIntegerSignedDecimal, labelIntegerUnsignedDecimal
, labelIntegerSignedHexadecimal, labelIntegerUnsignedHexadecimal
, labelIntegerSignedOctal, labelIntegerUnsignedOctal
, labelIntegerSignedBinary, labelIntegerUnsignedBinary
, labelIntegerSignedNumber, labelIntegerUnsignedNumber
, labelIntegerDecimalEnd, labelIntegerHexadecimalEnd
, labelIntegerOctalEnd, labelIntegerBinaryEnd, labelIntegerNumberEnd
, labelRealDecimal, labelRealHexadecimalEnd, labelRealOctalEnd
, labelRealBinaryEnd, labelRealNumberEnd
, labelRealDot, labelRealExponent, labelRealExponentEnd
, preventRealDoubleDroppedZero
, labelNumericBreakChar )
)
import Data.Kind (Constraint)
import Data.Proxy (Proxy(Proxy))
import Data.Ratio ((%))
import Data.List (foldl')
import Data.Char (digitToInt)
import Data.Bifunctor (bimap)
import Control.Monad (when, unless)
import Text.Gigaparsec.Internal.Token.Errors ( mapMaybeS, LabelWithExplainConfig, annotate
, LabelConfig(LNotConfigured)
, PreventDotIsZeroConfig(UnexpectedZeroDot, UnexpectedZeroDotWithReason, ZeroDotReason, ZeroDotFail) )
import Text.Gigaparsec.Errors.Combinator (filterOut, guardAgainst, unexpectedWhen, unexpectedWithReasonWhen)
type IntegerParsers :: (Bits -> * -> Constraint) -> *
data IntegerParsers canHold = IntegerParsers {
forall (canHold :: Bits -> * -> Constraint).
IntegerParsers canHold -> Parsec Integer
decimal :: Parsec Integer
, forall (canHold :: Bits -> * -> Constraint).
IntegerParsers canHold -> Parsec Integer
hexadecimal :: Parsec Integer
, forall (canHold :: Bits -> * -> Constraint).
IntegerParsers canHold -> Parsec Integer
octal :: Parsec Integer
, forall (canHold :: Bits -> * -> Constraint).
IntegerParsers canHold -> Parsec Integer
binary :: Parsec Integer
, forall (canHold :: Bits -> * -> Constraint).
IntegerParsers canHold -> Parsec Integer
number :: Parsec Integer
, forall (canHold :: Bits -> * -> Constraint).
IntegerParsers canHold
-> forall (bits :: Bits) t.
canHold bits t =>
Proxy bits
-> Parsec Integer
-> Int
-> (ErrorConfig -> Bool -> Maybe Bits -> LabelWithExplainConfig)
-> Parsec t
_bounded :: forall (bits :: Bits) t. canHold bits t
=> Proxy bits
-> Parsec Integer
-> Int
-> (ErrorConfig -> Bool -> Maybe Bits -> LabelWithExplainConfig)
-> Parsec t
}
decimalBounded :: forall (bits :: Bits) canHold t. canHold bits t => IntegerParsers canHold -> Parsec t
decimalBounded :: forall (bits :: Bits) (canHold :: Bits -> * -> Constraint) t.
canHold bits t =>
IntegerParsers canHold -> Parsec t
decimalBounded IntegerParsers{Parsec Integer
forall (bits :: Bits) t.
canHold bits t =>
Proxy bits
-> Parsec Integer
-> Int
-> (ErrorConfig -> Bool -> Maybe Bits -> LabelWithExplainConfig)
-> Parsec t
decimal :: forall (canHold :: Bits -> * -> Constraint).
IntegerParsers canHold -> Parsec Integer
hexadecimal :: forall (canHold :: Bits -> * -> Constraint).
IntegerParsers canHold -> Parsec Integer
octal :: forall (canHold :: Bits -> * -> Constraint).
IntegerParsers canHold -> Parsec Integer
binary :: forall (canHold :: Bits -> * -> Constraint).
IntegerParsers canHold -> Parsec Integer
number :: forall (canHold :: Bits -> * -> Constraint).
IntegerParsers canHold -> Parsec Integer
_bounded :: forall (canHold :: Bits -> * -> Constraint).
IntegerParsers canHold
-> forall (bits :: Bits) t.
canHold bits t =>
Proxy bits
-> Parsec Integer
-> Int
-> (ErrorConfig -> Bool -> Maybe Bits -> LabelWithExplainConfig)
-> Parsec t
decimal :: Parsec Integer
hexadecimal :: Parsec Integer
octal :: Parsec Integer
binary :: Parsec Integer
number :: Parsec Integer
_bounded :: forall (bits :: Bits) t.
canHold bits t =>
Proxy bits
-> Parsec Integer
-> Int
-> (ErrorConfig -> Bool -> Maybe Bits -> LabelWithExplainConfig)
-> Parsec t
..} = Proxy bits
-> Parsec Integer
-> Int
-> (ErrorConfig -> Bool -> Maybe Bits -> LabelWithExplainConfig)
-> Parsec t
forall (bits :: Bits) t.
canHold bits t =>
Proxy bits
-> Parsec Integer
-> Int
-> (ErrorConfig -> Bool -> Maybe Bits -> LabelWithExplainConfig)
-> Parsec t
_bounded (forall {k} (t :: k). Proxy t
forall (t :: Bits). Proxy t
Proxy @bits) Parsec Integer
decimal Int
10 ErrorConfig -> Bool -> Maybe Bits -> LabelWithExplainConfig
label
where label :: ErrorConfig -> Bool -> Maybe Bits -> LabelWithExplainConfig
label !ErrorConfig
err Bool
True = ErrorConfig -> Maybe Bits -> LabelWithExplainConfig
labelIntegerSignedDecimal ErrorConfig
err
label ErrorConfig
err Bool
False = ErrorConfig -> Maybe Bits -> LabelWithExplainConfig
labelIntegerUnsignedDecimal ErrorConfig
err
hexadecimalBounded :: forall (bits :: Bits) canHold t. canHold bits t => IntegerParsers canHold -> Parsec t
hexadecimalBounded :: forall (bits :: Bits) (canHold :: Bits -> * -> Constraint) t.
canHold bits t =>
IntegerParsers canHold -> Parsec t
hexadecimalBounded IntegerParsers{Parsec Integer
forall (bits :: Bits) t.
canHold bits t =>
Proxy bits
-> Parsec Integer
-> Int
-> (ErrorConfig -> Bool -> Maybe Bits -> LabelWithExplainConfig)
-> Parsec t
decimal :: forall (canHold :: Bits -> * -> Constraint).
IntegerParsers canHold -> Parsec Integer
hexadecimal :: forall (canHold :: Bits -> * -> Constraint).
IntegerParsers canHold -> Parsec Integer
octal :: forall (canHold :: Bits -> * -> Constraint).
IntegerParsers canHold -> Parsec Integer
binary :: forall (canHold :: Bits -> * -> Constraint).
IntegerParsers canHold -> Parsec Integer
number :: forall (canHold :: Bits -> * -> Constraint).
IntegerParsers canHold -> Parsec Integer
_bounded :: forall (canHold :: Bits -> * -> Constraint).
IntegerParsers canHold
-> forall (bits :: Bits) t.
canHold bits t =>
Proxy bits
-> Parsec Integer
-> Int
-> (ErrorConfig -> Bool -> Maybe Bits -> LabelWithExplainConfig)
-> Parsec t
decimal :: Parsec Integer
hexadecimal :: Parsec Integer
octal :: Parsec Integer
binary :: Parsec Integer
number :: Parsec Integer
_bounded :: forall (bits :: Bits) t.
canHold bits t =>
Proxy bits
-> Parsec Integer
-> Int
-> (ErrorConfig -> Bool -> Maybe Bits -> LabelWithExplainConfig)
-> Parsec t
..} = Proxy bits
-> Parsec Integer
-> Int
-> (ErrorConfig -> Bool -> Maybe Bits -> LabelWithExplainConfig)
-> Parsec t
forall (bits :: Bits) t.
canHold bits t =>
Proxy bits
-> Parsec Integer
-> Int
-> (ErrorConfig -> Bool -> Maybe Bits -> LabelWithExplainConfig)
-> Parsec t
_bounded (forall {k} (t :: k). Proxy t
forall (t :: Bits). Proxy t
Proxy @bits) Parsec Integer
hexadecimal Int
16 ErrorConfig -> Bool -> Maybe Bits -> LabelWithExplainConfig
label
where label :: ErrorConfig -> Bool -> Maybe Bits -> LabelWithExplainConfig
label !ErrorConfig
err Bool
True = ErrorConfig -> Maybe Bits -> LabelWithExplainConfig
labelIntegerSignedHexadecimal ErrorConfig
err
label ErrorConfig
err Bool
False = ErrorConfig -> Maybe Bits -> LabelWithExplainConfig
labelIntegerUnsignedHexadecimal ErrorConfig
err
octalBounded :: forall (bits :: Bits) canHold t. canHold bits t => IntegerParsers canHold -> Parsec t
octalBounded :: forall (bits :: Bits) (canHold :: Bits -> * -> Constraint) t.
canHold bits t =>
IntegerParsers canHold -> Parsec t
octalBounded IntegerParsers{Parsec Integer
forall (bits :: Bits) t.
canHold bits t =>
Proxy bits
-> Parsec Integer
-> Int
-> (ErrorConfig -> Bool -> Maybe Bits -> LabelWithExplainConfig)
-> Parsec t
decimal :: forall (canHold :: Bits -> * -> Constraint).
IntegerParsers canHold -> Parsec Integer
hexadecimal :: forall (canHold :: Bits -> * -> Constraint).
IntegerParsers canHold -> Parsec Integer
octal :: forall (canHold :: Bits -> * -> Constraint).
IntegerParsers canHold -> Parsec Integer
binary :: forall (canHold :: Bits -> * -> Constraint).
IntegerParsers canHold -> Parsec Integer
number :: forall (canHold :: Bits -> * -> Constraint).
IntegerParsers canHold -> Parsec Integer
_bounded :: forall (canHold :: Bits -> * -> Constraint).
IntegerParsers canHold
-> forall (bits :: Bits) t.
canHold bits t =>
Proxy bits
-> Parsec Integer
-> Int
-> (ErrorConfig -> Bool -> Maybe Bits -> LabelWithExplainConfig)
-> Parsec t
decimal :: Parsec Integer
hexadecimal :: Parsec Integer
octal :: Parsec Integer
binary :: Parsec Integer
number :: Parsec Integer
_bounded :: forall (bits :: Bits) t.
canHold bits t =>
Proxy bits
-> Parsec Integer
-> Int
-> (ErrorConfig -> Bool -> Maybe Bits -> LabelWithExplainConfig)
-> Parsec t
..} = Proxy bits
-> Parsec Integer
-> Int
-> (ErrorConfig -> Bool -> Maybe Bits -> LabelWithExplainConfig)
-> Parsec t
forall (bits :: Bits) t.
canHold bits t =>
Proxy bits
-> Parsec Integer
-> Int
-> (ErrorConfig -> Bool -> Maybe Bits -> LabelWithExplainConfig)
-> Parsec t
_bounded (forall {k} (t :: k). Proxy t
forall (t :: Bits). Proxy t
Proxy @bits) Parsec Integer
octal Int
8 ErrorConfig -> Bool -> Maybe Bits -> LabelWithExplainConfig
label
where label :: ErrorConfig -> Bool -> Maybe Bits -> LabelWithExplainConfig
label !ErrorConfig
err Bool
True = ErrorConfig -> Maybe Bits -> LabelWithExplainConfig
labelIntegerSignedOctal ErrorConfig
err
label ErrorConfig
err Bool
False = ErrorConfig -> Maybe Bits -> LabelWithExplainConfig
labelIntegerUnsignedOctal ErrorConfig
err
binaryBounded :: forall (bits :: Bits) canHold t. canHold bits t => IntegerParsers canHold -> Parsec t
binaryBounded :: forall (bits :: Bits) (canHold :: Bits -> * -> Constraint) t.
canHold bits t =>
IntegerParsers canHold -> Parsec t
binaryBounded IntegerParsers{Parsec Integer
forall (bits :: Bits) t.
canHold bits t =>
Proxy bits
-> Parsec Integer
-> Int
-> (ErrorConfig -> Bool -> Maybe Bits -> LabelWithExplainConfig)
-> Parsec t
decimal :: forall (canHold :: Bits -> * -> Constraint).
IntegerParsers canHold -> Parsec Integer
hexadecimal :: forall (canHold :: Bits -> * -> Constraint).
IntegerParsers canHold -> Parsec Integer
octal :: forall (canHold :: Bits -> * -> Constraint).
IntegerParsers canHold -> Parsec Integer
binary :: forall (canHold :: Bits -> * -> Constraint).
IntegerParsers canHold -> Parsec Integer
number :: forall (canHold :: Bits -> * -> Constraint).
IntegerParsers canHold -> Parsec Integer
_bounded :: forall (canHold :: Bits -> * -> Constraint).
IntegerParsers canHold
-> forall (bits :: Bits) t.
canHold bits t =>
Proxy bits
-> Parsec Integer
-> Int
-> (ErrorConfig -> Bool -> Maybe Bits -> LabelWithExplainConfig)
-> Parsec t
decimal :: Parsec Integer
hexadecimal :: Parsec Integer
octal :: Parsec Integer
binary :: Parsec Integer
number :: Parsec Integer
_bounded :: forall (bits :: Bits) t.
canHold bits t =>
Proxy bits
-> Parsec Integer
-> Int
-> (ErrorConfig -> Bool -> Maybe Bits -> LabelWithExplainConfig)
-> Parsec t
..} = Proxy bits
-> Parsec Integer
-> Int
-> (ErrorConfig -> Bool -> Maybe Bits -> LabelWithExplainConfig)
-> Parsec t
forall (bits :: Bits) t.
canHold bits t =>
Proxy bits
-> Parsec Integer
-> Int
-> (ErrorConfig -> Bool -> Maybe Bits -> LabelWithExplainConfig)
-> Parsec t
_bounded (forall {k} (t :: k). Proxy t
forall (t :: Bits). Proxy t
Proxy @bits) Parsec Integer
binary Int
2 ErrorConfig -> Bool -> Maybe Bits -> LabelWithExplainConfig
label
where label :: ErrorConfig -> Bool -> Maybe Bits -> LabelWithExplainConfig
label !ErrorConfig
err Bool
True = ErrorConfig -> Maybe Bits -> LabelWithExplainConfig
labelIntegerSignedBinary ErrorConfig
err
label ErrorConfig
err Bool
False = ErrorConfig -> Maybe Bits -> LabelWithExplainConfig
labelIntegerUnsignedBinary ErrorConfig
err
numberBounded :: forall (bits :: Bits) canHold t. canHold bits t => IntegerParsers canHold -> Parsec t
numberBounded :: forall (bits :: Bits) (canHold :: Bits -> * -> Constraint) t.
canHold bits t =>
IntegerParsers canHold -> Parsec t
numberBounded IntegerParsers{Parsec Integer
forall (bits :: Bits) t.
canHold bits t =>
Proxy bits
-> Parsec Integer
-> Int
-> (ErrorConfig -> Bool -> Maybe Bits -> LabelWithExplainConfig)
-> Parsec t
decimal :: forall (canHold :: Bits -> * -> Constraint).
IntegerParsers canHold -> Parsec Integer
hexadecimal :: forall (canHold :: Bits -> * -> Constraint).
IntegerParsers canHold -> Parsec Integer
octal :: forall (canHold :: Bits -> * -> Constraint).
IntegerParsers canHold -> Parsec Integer
binary :: forall (canHold :: Bits -> * -> Constraint).
IntegerParsers canHold -> Parsec Integer
number :: forall (canHold :: Bits -> * -> Constraint).
IntegerParsers canHold -> Parsec Integer
_bounded :: forall (canHold :: Bits -> * -> Constraint).
IntegerParsers canHold
-> forall (bits :: Bits) t.
canHold bits t =>
Proxy bits
-> Parsec Integer
-> Int
-> (ErrorConfig -> Bool -> Maybe Bits -> LabelWithExplainConfig)
-> Parsec t
decimal :: Parsec Integer
hexadecimal :: Parsec Integer
octal :: Parsec Integer
binary :: Parsec Integer
number :: Parsec Integer
_bounded :: forall (bits :: Bits) t.
canHold bits t =>
Proxy bits
-> Parsec Integer
-> Int
-> (ErrorConfig -> Bool -> Maybe Bits -> LabelWithExplainConfig)
-> Parsec t
..} = Proxy bits
-> Parsec Integer
-> Int
-> (ErrorConfig -> Bool -> Maybe Bits -> LabelWithExplainConfig)
-> Parsec t
forall (bits :: Bits) t.
canHold bits t =>
Proxy bits
-> Parsec Integer
-> Int
-> (ErrorConfig -> Bool -> Maybe Bits -> LabelWithExplainConfig)
-> Parsec t
_bounded (forall {k} (t :: k). Proxy t
forall (t :: Bits). Proxy t
Proxy @bits) Parsec Integer
number Int
10 ErrorConfig -> Bool -> Maybe Bits -> LabelWithExplainConfig
label
where label :: ErrorConfig -> Bool -> Maybe Bits -> LabelWithExplainConfig
label !ErrorConfig
err Bool
True = ErrorConfig -> Maybe Bits -> LabelWithExplainConfig
labelIntegerSignedNumber ErrorConfig
err
label ErrorConfig
err Bool
False = ErrorConfig -> Maybe Bits -> LabelWithExplainConfig
labelIntegerUnsignedNumber ErrorConfig
err
decimal8 :: forall a canHold. canHold 'B8 a => IntegerParsers canHold -> Parsec a
decimal8 :: forall a (canHold :: Bits -> * -> Constraint).
canHold 'B8 a =>
IntegerParsers canHold -> Parsec a
decimal8 = forall (bits :: Bits) (canHold :: Bits -> * -> Constraint) t.
canHold bits t =>
IntegerParsers canHold -> Parsec t
decimalBounded @'B8
hexadecimal8 :: forall a canHold. canHold 'B8 a => IntegerParsers canHold -> Parsec a
hexadecimal8 :: forall a (canHold :: Bits -> * -> Constraint).
canHold 'B8 a =>
IntegerParsers canHold -> Parsec a
hexadecimal8 = forall (bits :: Bits) (canHold :: Bits -> * -> Constraint) t.
canHold bits t =>
IntegerParsers canHold -> Parsec t
hexadecimalBounded @'B8
octal8 :: forall a canHold. canHold 'B8 a => IntegerParsers canHold -> Parsec a
octal8 :: forall a (canHold :: Bits -> * -> Constraint).
canHold 'B8 a =>
IntegerParsers canHold -> Parsec a
octal8 = forall (bits :: Bits) (canHold :: Bits -> * -> Constraint) t.
canHold bits t =>
IntegerParsers canHold -> Parsec t
octalBounded @'B8
binary8 :: forall a canHold. canHold 'B8 a => IntegerParsers canHold -> Parsec a
binary8 :: forall a (canHold :: Bits -> * -> Constraint).
canHold 'B8 a =>
IntegerParsers canHold -> Parsec a
binary8 = forall (bits :: Bits) (canHold :: Bits -> * -> Constraint) t.
canHold bits t =>
IntegerParsers canHold -> Parsec t
binaryBounded @'B8
number8 :: forall a canHold. canHold 'B8 a => IntegerParsers canHold -> Parsec a
number8 :: forall a (canHold :: Bits -> * -> Constraint).
canHold 'B8 a =>
IntegerParsers canHold -> Parsec a
number8 = forall (bits :: Bits) (canHold :: Bits -> * -> Constraint) t.
canHold bits t =>
IntegerParsers canHold -> Parsec t
numberBounded @'B8
decimal16 :: forall a canHold. canHold 'B16 a => IntegerParsers canHold -> Parsec a
decimal16 :: forall a (canHold :: Bits -> * -> Constraint).
canHold 'B16 a =>
IntegerParsers canHold -> Parsec a
decimal16 = forall (bits :: Bits) (canHold :: Bits -> * -> Constraint) t.
canHold bits t =>
IntegerParsers canHold -> Parsec t
decimalBounded @'B16
hexadecimal16 :: forall a canHold. canHold 'B16 a => IntegerParsers canHold -> Parsec a
hexadecimal16 :: forall a (canHold :: Bits -> * -> Constraint).
canHold 'B16 a =>
IntegerParsers canHold -> Parsec a
hexadecimal16 = forall (bits :: Bits) (canHold :: Bits -> * -> Constraint) t.
canHold bits t =>
IntegerParsers canHold -> Parsec t
hexadecimalBounded @'B16
octal16 :: forall a canHold. canHold 'B16 a => IntegerParsers canHold -> Parsec a
octal16 :: forall a (canHold :: Bits -> * -> Constraint).
canHold 'B16 a =>
IntegerParsers canHold -> Parsec a
octal16 = forall (bits :: Bits) (canHold :: Bits -> * -> Constraint) t.
canHold bits t =>
IntegerParsers canHold -> Parsec t
octalBounded @'B16
binary16 :: forall a canHold. canHold 'B16 a => IntegerParsers canHold -> Parsec a
binary16 :: forall a (canHold :: Bits -> * -> Constraint).
canHold 'B16 a =>
IntegerParsers canHold -> Parsec a
binary16 = forall (bits :: Bits) (canHold :: Bits -> * -> Constraint) t.
canHold bits t =>
IntegerParsers canHold -> Parsec t
binaryBounded @'B16
number16 :: forall a canHold. canHold 'B16 a => IntegerParsers canHold -> Parsec a
number16 :: forall a (canHold :: Bits -> * -> Constraint).
canHold 'B16 a =>
IntegerParsers canHold -> Parsec a
number16 = forall (bits :: Bits) (canHold :: Bits -> * -> Constraint) t.
canHold bits t =>
IntegerParsers canHold -> Parsec t
numberBounded @'B16
decimal32 :: forall a canHold. canHold 'B32 a => IntegerParsers canHold -> Parsec a
decimal32 :: forall a (canHold :: Bits -> * -> Constraint).
canHold 'B32 a =>
IntegerParsers canHold -> Parsec a
decimal32 = forall (bits :: Bits) (canHold :: Bits -> * -> Constraint) t.
canHold bits t =>
IntegerParsers canHold -> Parsec t
decimalBounded @'B32
hexadecimal32 :: forall a canHold. canHold 'B32 a => IntegerParsers canHold -> Parsec a
hexadecimal32 :: forall a (canHold :: Bits -> * -> Constraint).
canHold 'B32 a =>
IntegerParsers canHold -> Parsec a
hexadecimal32 = forall (bits :: Bits) (canHold :: Bits -> * -> Constraint) t.
canHold bits t =>
IntegerParsers canHold -> Parsec t
hexadecimalBounded @'B32
octal32 :: forall a canHold. canHold 'B32 a => IntegerParsers canHold -> Parsec a
octal32 :: forall a (canHold :: Bits -> * -> Constraint).
canHold 'B32 a =>
IntegerParsers canHold -> Parsec a
octal32 = forall (bits :: Bits) (canHold :: Bits -> * -> Constraint) t.
canHold bits t =>
IntegerParsers canHold -> Parsec t
octalBounded @'B32
binary32 :: forall a canHold. canHold 'B32 a => IntegerParsers canHold -> Parsec a
binary32 :: forall a (canHold :: Bits -> * -> Constraint).
canHold 'B32 a =>
IntegerParsers canHold -> Parsec a
binary32 = forall (bits :: Bits) (canHold :: Bits -> * -> Constraint) t.
canHold bits t =>
IntegerParsers canHold -> Parsec t
binaryBounded @'B32
number32 :: forall a canHold. canHold 'B32 a => IntegerParsers canHold -> Parsec a
number32 :: forall a (canHold :: Bits -> * -> Constraint).
canHold 'B32 a =>
IntegerParsers canHold -> Parsec a
number32 = forall (bits :: Bits) (canHold :: Bits -> * -> Constraint) t.
canHold bits t =>
IntegerParsers canHold -> Parsec t
numberBounded @'B32
decimal64 :: forall a canHold. canHold 'B64 a => IntegerParsers canHold -> Parsec a
decimal64 :: forall a (canHold :: Bits -> * -> Constraint).
canHold 'B64 a =>
IntegerParsers canHold -> Parsec a
decimal64 = forall (bits :: Bits) (canHold :: Bits -> * -> Constraint) t.
canHold bits t =>
IntegerParsers canHold -> Parsec t
decimalBounded @'B64
hexadecimal64 :: forall a canHold. canHold 'B64 a => IntegerParsers canHold -> Parsec a
hexadecimal64 :: forall a (canHold :: Bits -> * -> Constraint).
canHold 'B64 a =>
IntegerParsers canHold -> Parsec a
hexadecimal64 = forall (bits :: Bits) (canHold :: Bits -> * -> Constraint) t.
canHold bits t =>
IntegerParsers canHold -> Parsec t
hexadecimalBounded @'B64
octal64 :: forall a canHold. canHold 'B64 a => IntegerParsers canHold -> Parsec a
octal64 :: forall a (canHold :: Bits -> * -> Constraint).
canHold 'B64 a =>
IntegerParsers canHold -> Parsec a
octal64 = forall (bits :: Bits) (canHold :: Bits -> * -> Constraint) t.
canHold bits t =>
IntegerParsers canHold -> Parsec t
octalBounded @'B64
binary64 :: forall a canHold. canHold 'B64 a => IntegerParsers canHold -> Parsec a
binary64 :: forall a (canHold :: Bits -> * -> Constraint).
canHold 'B64 a =>
IntegerParsers canHold -> Parsec a
binary64 = forall (bits :: Bits) (canHold :: Bits -> * -> Constraint) t.
canHold bits t =>
IntegerParsers canHold -> Parsec t
binaryBounded @'B64
number64 :: forall a canHold. canHold 'B64 a => IntegerParsers canHold -> Parsec a
number64 :: forall a (canHold :: Bits -> * -> Constraint).
canHold 'B64 a =>
IntegerParsers canHold -> Parsec a
number64 = forall (bits :: Bits) (canHold :: Bits -> * -> Constraint) t.
canHold bits t =>
IntegerParsers canHold -> Parsec t
numberBounded @'B64
mkUnsigned :: NumericDesc -> GenericNumeric -> ErrorConfig -> IntegerParsers CanHoldUnsigned
mkUnsigned :: NumericDesc
-> GenericNumeric -> ErrorConfig -> IntegerParsers CanHoldUnsigned
mkUnsigned desc :: NumericDesc
desc@NumericDesc{Bool
Set Char
PlusSignPresence
BreakCharDesc
ExponentDesc
positiveSign :: NumericDesc -> PlusSignPresence
literalBreakChar :: NumericDesc -> BreakCharDesc
integerNumbersCanBeHexadecimal :: NumericDesc -> Bool
integerNumbersCanBeOctal :: NumericDesc -> Bool
integerNumbersCanBeBinary :: NumericDesc -> Bool
realNumbersCanBeHexadecimal :: NumericDesc -> Bool
realNumbersCanBeOctal :: NumericDesc -> Bool
realNumbersCanBeBinary :: NumericDesc -> Bool
hexadecimalLeads :: NumericDesc -> Set Char
octalLeads :: NumericDesc -> Set Char
binaryLeads :: NumericDesc -> Set Char
leadingDotAllowed :: NumericDesc -> Bool
trailingDotAllowed :: NumericDesc -> Bool
decimalExponentDesc :: NumericDesc -> ExponentDesc
hexadecimalExponentDesc :: NumericDesc -> ExponentDesc
octalExponentDesc :: NumericDesc -> ExponentDesc
binaryExponentDesc :: NumericDesc -> ExponentDesc
literalBreakChar :: BreakCharDesc
leadingDotAllowed :: Bool
trailingDotAllowed :: Bool
positiveSign :: PlusSignPresence
integerNumbersCanBeHexadecimal :: Bool
integerNumbersCanBeOctal :: Bool
integerNumbersCanBeBinary :: Bool
realNumbersCanBeHexadecimal :: Bool
realNumbersCanBeOctal :: Bool
realNumbersCanBeBinary :: Bool
hexadecimalLeads :: Set Char
octalLeads :: Set Char
binaryLeads :: Set Char
decimalExponentDesc :: ExponentDesc
hexadecimalExponentDesc :: ExponentDesc
octalExponentDesc :: ExponentDesc
binaryExponentDesc :: ExponentDesc
..} !GenericNumeric
gen !ErrorConfig
err = IntegerParsers {Parsec Integer
Proxy bits
-> Parsec Integer
-> Int
-> (ErrorConfig -> Bool -> Maybe Bits -> LabelWithExplainConfig)
-> Parsec t
forall (bits :: Bits) t.
CanHoldUnsigned bits t =>
Proxy bits
-> Parsec Integer
-> Int
-> (ErrorConfig -> Bool -> Maybe Bits -> LabelWithExplainConfig)
-> Parsec t
decimal :: Parsec Integer
hexadecimal :: Parsec Integer
octal :: Parsec Integer
binary :: Parsec Integer
number :: Parsec Integer
_bounded :: forall (bits :: Bits) t.
CanHoldUnsigned bits t =>
Proxy bits
-> Parsec Integer
-> Int
-> (ErrorConfig -> Bool -> Maybe Bits -> LabelWithExplainConfig)
-> Parsec t
_bounded :: forall (bits :: Bits) t.
CanHoldUnsigned bits t =>
Proxy bits
-> Parsec Integer
-> Int
-> (ErrorConfig -> Bool -> Maybe Bits -> LabelWithExplainConfig)
-> Parsec t
decimal :: Parsec Integer
hexadecimal :: Parsec Integer
octal :: Parsec Integer
binary :: Parsec Integer
number :: Parsec Integer
..}
where _bounded :: forall (b :: Bits) t. CanHoldUnsigned b t
=> Proxy b -> Parsec Integer -> Int
-> (ErrorConfig -> Bool -> Maybe Bits -> LabelWithExplainConfig)
-> Parsec t
_bounded :: forall (bits :: Bits) t.
CanHoldUnsigned bits t =>
Proxy bits
-> Parsec Integer
-> Int
-> (ErrorConfig -> Bool -> Maybe Bits -> LabelWithExplainConfig)
-> Parsec t
_bounded Proxy b
_ Parsec Integer
num Int
radix ErrorConfig -> Bool -> Maybe Bits -> LabelWithExplainConfig
label = LabelWithExplainConfig -> Parsec t -> Parsec t
forall config a. Annotate config => config -> Parsec a -> Parsec a
forall a. LabelWithExplainConfig -> Parsec a -> Parsec a
annotate (ErrorConfig -> Bool -> Maybe Bits -> LabelWithExplainConfig
label ErrorConfig
err Bool
False (Bits -> Maybe Bits
forall a. a -> Maybe a
Just (forall (b :: Bits). BitBounds b => Bits
bits @b))) (Parsec t -> Parsec t) -> Parsec t -> Parsec t
forall a b. (a -> b) -> a -> b
$
FilterConfig Integer
-> (Integer -> Maybe t) -> Parsec Integer -> Parsec t
forall a b.
FilterConfig a -> (a -> Maybe b) -> Parsec a -> Parsec b
forall (config :: * -> *) a b.
Filter config =>
config a -> (a -> Maybe b) -> Parsec a -> Parsec b
mapMaybeS (ErrorConfig -> Integer -> Integer -> Int -> FilterConfig Integer
filterIntegerOutOfBounds ErrorConfig
err Integer
0 (forall (b :: Bits). BitBounds b => Integer
upperUnsigned @b) Int
radix)
(\Integer
n -> if Integer
n Integer -> Integer -> Bool
forall a. Ord a => a -> a -> Bool
>= Integer
0 Bool -> Bool -> Bool
&& Integer
n Integer -> Integer -> Bool
forall a. Ord a => a -> a -> Bool
<= forall (b :: Bits). BitBounds b => Integer
upperUnsigned @b then t -> Maybe t
forall a. a -> Maybe a
Just (Integer -> t
forall a. Num a => Integer -> a
fromInteger Integer
n) else Maybe t
forall a. Maybe a
Nothing)
Parsec Integer
num
leadingBreakChar :: Parsec ()
leadingBreakChar = case BreakCharDesc
literalBreakChar of
BreakCharDesc
NoBreakChar -> Parsec ()
unit
BreakCharSupported Char
breakChar Bool
allowedAfterNonDecimalPrefix ->
Bool -> Parsec () -> Parsec ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when Bool
allowedAfterNonDecimalPrefix (Parsec Char -> Parsec ()
forall a. Parsec a -> Parsec ()
optional (Char -> Parsec Char
char Char
breakChar))
noZeroHexadecimal :: Parsec Integer
noZeroHexadecimal = do
Bool -> Parsec () -> Parsec ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless (Set Char -> Bool
forall a. Set a -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null Set Char
hexadecimalLeads) (Parsec Char -> Parsec ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void (Set Char -> Parsec Char
oneOf Set Char
hexadecimalLeads))
Parsec ()
leadingBreakChar
LabelConfig -> Parsec Integer -> Parsec Integer
forall config a. Annotate config => config -> Parsec a -> Parsec a
forall a. LabelConfig -> Parsec a -> Parsec a
annotate (ErrorConfig -> LabelConfig
labelIntegerHexadecimalEnd ErrorConfig
err) (GenericNumeric -> NumericDesc -> LabelConfig -> Parsec Integer
plainHexadecimal GenericNumeric
gen NumericDesc
desc (ErrorConfig -> LabelConfig
labelIntegerHexadecimalEnd ErrorConfig
err))
noZeroOctal :: Parsec Integer
noZeroOctal = do
Bool -> Parsec () -> Parsec ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless (Set Char -> Bool
forall a. Set a -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null Set Char
octalLeads) (Parsec Char -> Parsec ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void (Set Char -> Parsec Char
oneOf Set Char
octalLeads))
Parsec ()
leadingBreakChar
LabelConfig -> Parsec Integer -> Parsec Integer
forall config a. Annotate config => config -> Parsec a -> Parsec a
forall a. LabelConfig -> Parsec a -> Parsec a
annotate (ErrorConfig -> LabelConfig
labelIntegerOctalEnd ErrorConfig
err) (GenericNumeric -> NumericDesc -> LabelConfig -> Parsec Integer
plainOctal GenericNumeric
gen NumericDesc
desc (ErrorConfig -> LabelConfig
labelIntegerOctalEnd ErrorConfig
err))
noZeroBinary :: Parsec Integer
noZeroBinary = do
Bool -> Parsec () -> Parsec ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless (Set Char -> Bool
forall a. Set a -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null Set Char
binaryLeads) (Parsec Char -> Parsec ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void (Set Char -> Parsec Char
oneOf Set Char
binaryLeads))
Parsec ()
leadingBreakChar
LabelConfig -> Parsec Integer -> Parsec Integer
forall config a. Annotate config => config -> Parsec a -> Parsec a
forall a. LabelConfig -> Parsec a -> Parsec a
annotate (ErrorConfig -> LabelConfig
labelIntegerBinaryEnd ErrorConfig
err) (GenericNumeric -> NumericDesc -> LabelConfig -> Parsec Integer
plainBinary GenericNumeric
gen NumericDesc
desc (ErrorConfig -> LabelConfig
labelIntegerBinaryEnd ErrorConfig
err))
decimal :: Parsec Integer
decimal = LabelWithExplainConfig -> Parsec Integer -> Parsec Integer
forall config a. Annotate config => config -> Parsec a -> Parsec a
forall a. LabelWithExplainConfig -> Parsec a -> Parsec a
annotate (ErrorConfig -> Maybe Bits -> LabelWithExplainConfig
labelIntegerUnsignedDecimal ErrorConfig
err Maybe Bits
forall a. Maybe a
Nothing) (Parsec Integer -> Parsec Integer)
-> Parsec Integer -> Parsec Integer
forall a b. (a -> b) -> a -> b
$ GenericNumeric -> NumericDesc -> LabelConfig -> Parsec Integer
plainDecimal GenericNumeric
gen NumericDesc
desc (ErrorConfig -> LabelConfig
labelIntegerDecimalEnd ErrorConfig
err)
hexadecimal :: Parsec Integer
hexadecimal = LabelWithExplainConfig -> Parsec Integer -> Parsec Integer
forall config a. Annotate config => config -> Parsec a -> Parsec a
forall a. LabelWithExplainConfig -> Parsec a -> Parsec a
annotate (ErrorConfig -> Maybe Bits -> LabelWithExplainConfig
labelIntegerUnsignedHexadecimal ErrorConfig
err Maybe Bits
forall a. Maybe a
Nothing) (Parsec Integer -> Parsec Integer)
-> Parsec Integer -> Parsec Integer
forall a b. (a -> b) -> a -> b
$ Parsec Integer -> Parsec Integer
forall a. Parsec a -> Parsec a
atomic (Char -> Parsec Char
char Char
'0' Parsec Char -> Parsec Integer -> Parsec Integer
forall a b. Parsec a -> Parsec b -> Parsec b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parsec Integer
noZeroHexadecimal)
octal :: Parsec Integer
octal = LabelWithExplainConfig -> Parsec Integer -> Parsec Integer
forall config a. Annotate config => config -> Parsec a -> Parsec a
forall a. LabelWithExplainConfig -> Parsec a -> Parsec a
annotate (ErrorConfig -> Maybe Bits -> LabelWithExplainConfig
labelIntegerUnsignedOctal ErrorConfig
err Maybe Bits
forall a. Maybe a
Nothing) (Parsec Integer -> Parsec Integer)
-> Parsec Integer -> Parsec Integer
forall a b. (a -> b) -> a -> b
$ Parsec Integer -> Parsec Integer
forall a. Parsec a -> Parsec a
atomic (Char -> Parsec Char
char Char
'0' Parsec Char -> Parsec Integer -> Parsec Integer
forall a b. Parsec a -> Parsec b -> Parsec b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parsec Integer
noZeroOctal)
binary :: Parsec Integer
binary = LabelWithExplainConfig -> Parsec Integer -> Parsec Integer
forall config a. Annotate config => config -> Parsec a -> Parsec a
forall a. LabelWithExplainConfig -> Parsec a -> Parsec a
annotate (ErrorConfig -> Maybe Bits -> LabelWithExplainConfig
labelIntegerUnsignedBinary ErrorConfig
err Maybe Bits
forall a. Maybe a
Nothing) (Parsec Integer -> Parsec Integer)
-> Parsec Integer -> Parsec Integer
forall a b. (a -> b) -> a -> b
$ Parsec Integer -> Parsec Integer
forall a. Parsec a -> Parsec a
atomic (Char -> Parsec Char
char Char
'0' Parsec Char -> Parsec Integer -> Parsec Integer
forall a b. Parsec a -> Parsec b -> Parsec b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parsec Integer
noZeroBinary)
number :: Parsec Integer
number
| Bool -> Bool
not Bool
integerNumbersCanBeBinary
, Bool -> Bool
not Bool
integerNumbersCanBeHexadecimal
, Bool -> Bool
not Bool
integerNumbersCanBeOctal = LabelWithExplainConfig -> Parsec Integer -> Parsec Integer
forall config a. Annotate config => config -> Parsec a -> Parsec a
forall a. LabelWithExplainConfig -> Parsec a -> Parsec a
annotate (ErrorConfig -> Maybe Bits -> LabelWithExplainConfig
labelIntegerUnsignedNumber ErrorConfig
err Maybe Bits
forall a. Maybe a
Nothing) Parsec Integer
decimal
| Bool
otherwise = LabelWithExplainConfig -> Parsec Integer -> Parsec Integer
forall config a. Annotate config => config -> Parsec a -> Parsec a
forall a. LabelWithExplainConfig -> Parsec a -> Parsec a
annotate (ErrorConfig -> Maybe Bits -> LabelWithExplainConfig
labelIntegerUnsignedNumber ErrorConfig
err Maybe Bits
forall a. Maybe a
Nothing) (Parsec Integer -> Parsec Integer)
-> Parsec Integer -> Parsec Integer
forall a b. (a -> b) -> a -> b
$ Parsec Integer -> Parsec Integer
forall a. Parsec a -> Parsec a
atomic (Parsec Integer
zeroLead Parsec Integer -> Parsec Integer -> Parsec Integer
forall a. Parsec a -> Parsec a -> Parsec a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Parsec Integer
decimal)
where zeroLead :: Parsec Integer
zeroLead = Char -> Parsec Char
char Char
'0' Parsec Char -> Parsec Integer -> Parsec Integer
forall a b. Parsec a -> Parsec b -> Parsec b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parsec Integer -> Parsec Integer
addHex (Parsec Integer -> Parsec Integer
addOct (Parsec Integer -> Parsec Integer
addBin (Parsec Integer
decimal Parsec Integer -> Parsec Integer -> Parsec Integer
forall a. Parsec a -> Parsec a -> Parsec a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Integer -> Parsec Integer
forall a. a -> Parsec a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Integer
0)))
addHex :: Parsec Integer -> Parsec Integer
addHex
| Bool
integerNumbersCanBeHexadecimal = (Parsec Integer
noZeroHexadecimal Parsec Integer -> Parsec Integer -> Parsec Integer
forall a. Parsec a -> Parsec a -> Parsec a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|>)
| Bool
otherwise = Parsec Integer -> Parsec Integer
forall a. a -> a
id
addOct :: Parsec Integer -> Parsec Integer
addOct
| Bool
integerNumbersCanBeOctal = (Parsec Integer
noZeroOctal Parsec Integer -> Parsec Integer -> Parsec Integer
forall a. Parsec a -> Parsec a -> Parsec a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|>)
| Bool
otherwise = Parsec Integer -> Parsec Integer
forall a. a -> a
id
addBin :: Parsec Integer -> Parsec Integer
addBin
| Bool
integerNumbersCanBeBinary = (Parsec Integer
noZeroBinary Parsec Integer -> Parsec Integer -> Parsec Integer
forall a. Parsec a -> Parsec a -> Parsec a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|>)
| Bool
otherwise = Parsec Integer -> Parsec Integer
forall a. a -> a
id
mkSigned :: NumericDesc -> IntegerParsers c -> ErrorConfig -> IntegerParsers CanHoldSigned
mkSigned :: forall (c :: Bits -> * -> Constraint).
NumericDesc
-> IntegerParsers c -> ErrorConfig -> IntegerParsers CanHoldSigned
mkSigned NumericDesc{Bool
Set Char
PlusSignPresence
BreakCharDesc
ExponentDesc
positiveSign :: NumericDesc -> PlusSignPresence
literalBreakChar :: NumericDesc -> BreakCharDesc
integerNumbersCanBeHexadecimal :: NumericDesc -> Bool
integerNumbersCanBeOctal :: NumericDesc -> Bool
integerNumbersCanBeBinary :: NumericDesc -> Bool
realNumbersCanBeHexadecimal :: NumericDesc -> Bool
realNumbersCanBeOctal :: NumericDesc -> Bool
realNumbersCanBeBinary :: NumericDesc -> Bool
hexadecimalLeads :: NumericDesc -> Set Char
octalLeads :: NumericDesc -> Set Char
binaryLeads :: NumericDesc -> Set Char
leadingDotAllowed :: NumericDesc -> Bool
trailingDotAllowed :: NumericDesc -> Bool
decimalExponentDesc :: NumericDesc -> ExponentDesc
hexadecimalExponentDesc :: NumericDesc -> ExponentDesc
octalExponentDesc :: NumericDesc -> ExponentDesc
binaryExponentDesc :: NumericDesc -> ExponentDesc
literalBreakChar :: BreakCharDesc
leadingDotAllowed :: Bool
trailingDotAllowed :: Bool
positiveSign :: PlusSignPresence
integerNumbersCanBeHexadecimal :: Bool
integerNumbersCanBeOctal :: Bool
integerNumbersCanBeBinary :: Bool
realNumbersCanBeHexadecimal :: Bool
realNumbersCanBeOctal :: Bool
realNumbersCanBeBinary :: Bool
hexadecimalLeads :: Set Char
octalLeads :: Set Char
binaryLeads :: Set Char
decimalExponentDesc :: ExponentDesc
hexadecimalExponentDesc :: ExponentDesc
octalExponentDesc :: ExponentDesc
binaryExponentDesc :: ExponentDesc
..} !IntegerParsers c
unsigned !ErrorConfig
err = IntegerParsers {
decimal :: Parsec Integer
decimal = Parsec Integer
_decimal,
hexadecimal :: Parsec Integer
hexadecimal = Parsec Integer
_hexadecimal,
octal :: Parsec Integer
octal = Parsec Integer
_octal,
binary :: Parsec Integer
binary = Parsec Integer
_binary,
number :: Parsec Integer
number = Parsec Integer
_number,
Proxy bits
-> Parsec Integer
-> Int
-> (ErrorConfig -> Bool -> Maybe Bits -> LabelWithExplainConfig)
-> Parsec t
forall (bits :: Bits) t.
CanHoldSigned bits t =>
Proxy bits
-> Parsec Integer
-> Int
-> (ErrorConfig -> Bool -> Maybe Bits -> LabelWithExplainConfig)
-> Parsec t
_bounded :: forall (bits :: Bits) t.
CanHoldSigned bits t =>
Proxy bits
-> Parsec Integer
-> Int
-> (ErrorConfig -> Bool -> Maybe Bits -> LabelWithExplainConfig)
-> Parsec t
_bounded :: forall (bits :: Bits) t.
CanHoldSigned bits t =>
Proxy bits
-> Parsec Integer
-> Int
-> (ErrorConfig -> Bool -> Maybe Bits -> LabelWithExplainConfig)
-> Parsec t
..
}
where _bounded :: forall (b :: Bits) t. CanHoldSigned b t
=> Proxy b -> Parsec Integer -> Int
-> (ErrorConfig -> Bool -> Maybe Bits -> LabelWithExplainConfig)
-> Parsec t
_bounded :: forall (bits :: Bits) t.
CanHoldSigned bits t =>
Proxy bits
-> Parsec Integer
-> Int
-> (ErrorConfig -> Bool -> Maybe Bits -> LabelWithExplainConfig)
-> Parsec t
_bounded Proxy b
_ Parsec Integer
num Int
radix ErrorConfig -> Bool -> Maybe Bits -> LabelWithExplainConfig
label = LabelWithExplainConfig -> Parsec t -> Parsec t
forall config a. Annotate config => config -> Parsec a -> Parsec a
forall a. LabelWithExplainConfig -> Parsec a -> Parsec a
annotate (ErrorConfig -> Bool -> Maybe Bits -> LabelWithExplainConfig
label ErrorConfig
err Bool
True (Bits -> Maybe Bits
forall a. a -> Maybe a
Just (forall (b :: Bits). BitBounds b => Bits
bits @b))) (Parsec t -> Parsec t) -> Parsec t -> Parsec t
forall a b. (a -> b) -> a -> b
$
FilterConfig Integer
-> (Integer -> Maybe t) -> Parsec Integer -> Parsec t
forall a b.
FilterConfig a -> (a -> Maybe b) -> Parsec a -> Parsec b
forall (config :: * -> *) a b.
Filter config =>
config a -> (a -> Maybe b) -> Parsec a -> Parsec b
mapMaybeS (ErrorConfig -> Integer -> Integer -> Int -> FilterConfig Integer
filterIntegerOutOfBounds ErrorConfig
err (forall (b :: Bits). BitBounds b => Integer
lowerSigned @b) (forall (b :: Bits). BitBounds b => Integer
upperSigned @b) Int
radix)
(\Integer
n -> if Integer
n Integer -> Integer -> Bool
forall a. Ord a => a -> a -> Bool
>= forall (b :: Bits). BitBounds b => Integer
lowerSigned @b Bool -> Bool -> Bool
&& Integer
n Integer -> Integer -> Bool
forall a. Ord a => a -> a -> Bool
<= forall (b :: Bits). BitBounds b => Integer
upperSigned @b
then t -> Maybe t
forall a. a -> Maybe a
Just (Integer -> t
forall a. Num a => Integer -> a
fromInteger Integer
n)
else Maybe t
forall a. Maybe a
Nothing)
Parsec Integer
num
sign :: Parsec (Integer -> Integer)
sign :: Parsec (Integer -> Integer)
sign = case PlusSignPresence
positiveSign of
PlusSignPresence
PlusRequired -> Char -> Parsec Char
char Char
'+' Parsec Char -> (Integer -> Integer) -> Parsec (Integer -> Integer)
forall a b. Parsec a -> b -> Parsec b
$> Integer -> Integer
forall a. a -> a
id Parsec (Integer -> Integer)
-> Parsec (Integer -> Integer) -> Parsec (Integer -> Integer)
forall a. Parsec a -> Parsec a -> Parsec a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Char -> Parsec Char
char Char
'-' Parsec Char -> (Integer -> Integer) -> Parsec (Integer -> Integer)
forall a b. Parsec a -> b -> Parsec b
$> Integer -> Integer
forall a. Num a => a -> a
negate
PlusSignPresence
PlusOptional -> Char -> Parsec Char
char Char
'-' Parsec Char -> (Integer -> Integer) -> Parsec (Integer -> Integer)
forall a b. Parsec a -> b -> Parsec b
$> Integer -> Integer
forall a. Num a => a -> a
negate Parsec (Integer -> Integer)
-> Parsec (Integer -> Integer) -> Parsec (Integer -> Integer)
forall a. Parsec a -> Parsec a -> Parsec a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (Integer -> Integer) -> Parsec Char -> Parsec (Integer -> Integer)
forall b a. b -> Parsec a -> Parsec b
optionalAs Integer -> Integer
forall a. a -> a
id (Char -> Parsec Char
char Char
'+')
PlusSignPresence
PlusIllegal -> (Integer -> Integer) -> Parsec (Integer -> Integer)
forall a. a -> Parsec a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Integer -> Integer
forall a. a -> a
id
_decimal :: Parsec Integer
_decimal = LabelWithExplainConfig -> Parsec Integer -> Parsec Integer
forall config a. Annotate config => config -> Parsec a -> Parsec a
forall a. LabelWithExplainConfig -> Parsec a -> Parsec a
annotate (ErrorConfig -> Maybe Bits -> LabelWithExplainConfig
labelIntegerSignedDecimal ErrorConfig
err Maybe Bits
forall a. Maybe a
Nothing) (Parsec Integer -> Parsec Integer)
-> Parsec Integer -> Parsec Integer
forall a b. (a -> b) -> a -> b
$
Parsec Integer -> Parsec Integer
forall a. Parsec a -> Parsec a
atomic (Parsec (Integer -> Integer)
sign Parsec (Integer -> Integer) -> Parsec Integer -> Parsec Integer
forall a b. Parsec (a -> b) -> Parsec a -> Parsec b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> LabelConfig -> Parsec Integer -> Parsec Integer
forall config a. Annotate config => config -> Parsec a -> Parsec a
forall a. LabelConfig -> Parsec a -> Parsec a
annotate (ErrorConfig -> LabelConfig
labelIntegerDecimalEnd ErrorConfig
err) (IntegerParsers c -> Parsec Integer
forall (canHold :: Bits -> * -> Constraint).
IntegerParsers canHold -> Parsec Integer
decimal IntegerParsers c
unsigned))
_hexadecimal :: Parsec Integer
_hexadecimal = LabelWithExplainConfig -> Parsec Integer -> Parsec Integer
forall config a. Annotate config => config -> Parsec a -> Parsec a
forall a. LabelWithExplainConfig -> Parsec a -> Parsec a
annotate (ErrorConfig -> Maybe Bits -> LabelWithExplainConfig
labelIntegerSignedHexadecimal ErrorConfig
err Maybe Bits
forall a. Maybe a
Nothing) (Parsec Integer -> Parsec Integer)
-> Parsec Integer -> Parsec Integer
forall a b. (a -> b) -> a -> b
$
Parsec Integer -> Parsec Integer
forall a. Parsec a -> Parsec a
atomic (Parsec (Integer -> Integer)
sign Parsec (Integer -> Integer) -> Parsec Integer -> Parsec Integer
forall a b. Parsec (a -> b) -> Parsec a -> Parsec b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> LabelConfig -> Parsec Integer -> Parsec Integer
forall config a. Annotate config => config -> Parsec a -> Parsec a
forall a. LabelConfig -> Parsec a -> Parsec a
annotate (ErrorConfig -> LabelConfig
labelIntegerHexadecimalEnd ErrorConfig
err) (IntegerParsers c -> Parsec Integer
forall (canHold :: Bits -> * -> Constraint).
IntegerParsers canHold -> Parsec Integer
hexadecimal IntegerParsers c
unsigned))
_octal :: Parsec Integer
_octal = LabelWithExplainConfig -> Parsec Integer -> Parsec Integer
forall config a. Annotate config => config -> Parsec a -> Parsec a
forall a. LabelWithExplainConfig -> Parsec a -> Parsec a
annotate (ErrorConfig -> Maybe Bits -> LabelWithExplainConfig
labelIntegerSignedOctal ErrorConfig
err Maybe Bits
forall a. Maybe a
Nothing) (Parsec Integer -> Parsec Integer)
-> Parsec Integer -> Parsec Integer
forall a b. (a -> b) -> a -> b
$
Parsec Integer -> Parsec Integer
forall a. Parsec a -> Parsec a
atomic (Parsec (Integer -> Integer)
sign Parsec (Integer -> Integer) -> Parsec Integer -> Parsec Integer
forall a b. Parsec (a -> b) -> Parsec a -> Parsec b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> LabelConfig -> Parsec Integer -> Parsec Integer
forall config a. Annotate config => config -> Parsec a -> Parsec a
forall a. LabelConfig -> Parsec a -> Parsec a
annotate (ErrorConfig -> LabelConfig
labelIntegerOctalEnd ErrorConfig
err) (IntegerParsers c -> Parsec Integer
forall (canHold :: Bits -> * -> Constraint).
IntegerParsers canHold -> Parsec Integer
octal IntegerParsers c
unsigned))
_binary :: Parsec Integer
_binary = LabelWithExplainConfig -> Parsec Integer -> Parsec Integer
forall config a. Annotate config => config -> Parsec a -> Parsec a
forall a. LabelWithExplainConfig -> Parsec a -> Parsec a
annotate (ErrorConfig -> Maybe Bits -> LabelWithExplainConfig
labelIntegerSignedBinary ErrorConfig
err Maybe Bits
forall a. Maybe a
Nothing) (Parsec Integer -> Parsec Integer)
-> Parsec Integer -> Parsec Integer
forall a b. (a -> b) -> a -> b
$
Parsec Integer -> Parsec Integer
forall a. Parsec a -> Parsec a
atomic (Parsec (Integer -> Integer)
sign Parsec (Integer -> Integer) -> Parsec Integer -> Parsec Integer
forall a b. Parsec (a -> b) -> Parsec a -> Parsec b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> LabelConfig -> Parsec Integer -> Parsec Integer
forall config a. Annotate config => config -> Parsec a -> Parsec a
forall a. LabelConfig -> Parsec a -> Parsec a
annotate (ErrorConfig -> LabelConfig
labelIntegerBinaryEnd ErrorConfig
err) (IntegerParsers c -> Parsec Integer
forall (canHold :: Bits -> * -> Constraint).
IntegerParsers canHold -> Parsec Integer
binary IntegerParsers c
unsigned))
_number :: Parsec Integer
_number = LabelWithExplainConfig -> Parsec Integer -> Parsec Integer
forall config a. Annotate config => config -> Parsec a -> Parsec a
forall a. LabelWithExplainConfig -> Parsec a -> Parsec a
annotate (ErrorConfig -> Maybe Bits -> LabelWithExplainConfig
labelIntegerSignedNumber ErrorConfig
err Maybe Bits
forall a. Maybe a
Nothing) (Parsec Integer -> Parsec Integer)
-> Parsec Integer -> Parsec Integer
forall a b. (a -> b) -> a -> b
$
Parsec Integer -> Parsec Integer
forall a. Parsec a -> Parsec a
atomic (Parsec (Integer -> Integer)
sign Parsec (Integer -> Integer) -> Parsec Integer -> Parsec Integer
forall a b. Parsec (a -> b) -> Parsec a -> Parsec b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> LabelConfig -> Parsec Integer -> Parsec Integer
forall config a. Annotate config => config -> Parsec a -> Parsec a
forall a. LabelConfig -> Parsec a -> Parsec a
annotate (ErrorConfig -> LabelConfig
labelIntegerNumberEnd ErrorConfig
err) (IntegerParsers c -> Parsec Integer
forall (canHold :: Bits -> * -> Constraint).
IntegerParsers canHold -> Parsec Integer
number IntegerParsers c
unsigned))
type FloatingParsers :: *
data FloatingParsers = FloatingParsers {
FloatingParsers -> Parsec (Ratio Integer)
decimalFloating :: Parsec Rational
, FloatingParsers -> Parsec (Ratio Integer)
hexadecimalFloating :: Parsec Rational
, FloatingParsers -> Parsec (Ratio Integer)
octalFloating :: Parsec Rational
, FloatingParsers -> Parsec (Ratio Integer)
binaryFloating :: Parsec Rational
, FloatingParsers -> Parsec (Ratio Integer)
numberFloating :: Parsec Rational
}
mkUnsignedFloating :: NumericDesc -> IntegerParsers CanHoldUnsigned -> GenericNumeric -> ErrorConfig -> FloatingParsers
mkUnsignedFloating :: NumericDesc
-> IntegerParsers CanHoldUnsigned
-> GenericNumeric
-> ErrorConfig
-> FloatingParsers
mkUnsignedFloating NumericDesc{Bool
Set Char
PlusSignPresence
BreakCharDesc
ExponentDesc
positiveSign :: NumericDesc -> PlusSignPresence
literalBreakChar :: NumericDesc -> BreakCharDesc
integerNumbersCanBeHexadecimal :: NumericDesc -> Bool
integerNumbersCanBeOctal :: NumericDesc -> Bool
integerNumbersCanBeBinary :: NumericDesc -> Bool
realNumbersCanBeHexadecimal :: NumericDesc -> Bool
realNumbersCanBeOctal :: NumericDesc -> Bool
realNumbersCanBeBinary :: NumericDesc -> Bool
hexadecimalLeads :: NumericDesc -> Set Char
octalLeads :: NumericDesc -> Set Char
binaryLeads :: NumericDesc -> Set Char
leadingDotAllowed :: NumericDesc -> Bool
trailingDotAllowed :: NumericDesc -> Bool
decimalExponentDesc :: NumericDesc -> ExponentDesc
hexadecimalExponentDesc :: NumericDesc -> ExponentDesc
octalExponentDesc :: NumericDesc -> ExponentDesc
binaryExponentDesc :: NumericDesc -> ExponentDesc
literalBreakChar :: BreakCharDesc
leadingDotAllowed :: Bool
trailingDotAllowed :: Bool
positiveSign :: PlusSignPresence
integerNumbersCanBeHexadecimal :: Bool
integerNumbersCanBeOctal :: Bool
integerNumbersCanBeBinary :: Bool
realNumbersCanBeHexadecimal :: Bool
realNumbersCanBeOctal :: Bool
realNumbersCanBeBinary :: Bool
hexadecimalLeads :: Set Char
octalLeads :: Set Char
binaryLeads :: Set Char
decimalExponentDesc :: ExponentDesc
hexadecimalExponentDesc :: ExponentDesc
octalExponentDesc :: ExponentDesc
binaryExponentDesc :: ExponentDesc
..} !IntegerParsers CanHoldUnsigned
nat !GenericNumeric
gen !ErrorConfig
err = FloatingParsers {Parsec (Ratio Integer)
decimalFloating :: Parsec (Ratio Integer)
hexadecimalFloating :: Parsec (Ratio Integer)
octalFloating :: Parsec (Ratio Integer)
binaryFloating :: Parsec (Ratio Integer)
numberFloating :: Parsec (Ratio Integer)
decimalFloating :: Parsec (Ratio Integer)
hexadecimalFloating :: Parsec (Ratio Integer)
octalFloating :: Parsec (Ratio Integer)
binaryFloating :: Parsec (Ratio Integer)
numberFloating :: Parsec (Ratio Integer)
..}
where
foldFrac :: Integer -> [Char] -> Rational
foldFrac :: Integer -> [Char] -> Ratio Integer
foldFrac Integer
radix [Char]
ds = case ((Integer, Integer) -> Char -> (Integer, Integer))
-> (Integer, Integer) -> [Char] -> (Integer, Integer)
forall b a. (b -> a -> b) -> b -> [a] -> b
forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl' (Integer, Integer) -> Char -> (Integer, Integer)
go (Integer
0, Integer
1) [Char]
ds of { (Integer
n, Integer
p) -> Integer
n Integer -> Integer -> Ratio Integer
forall a. Integral a => a -> a -> Ratio a
% Integer
p }
where go :: (Integer, Integer) -> Char -> (Integer, Integer)
go (Integer
n, Integer
p) Char
d = (Integer
n Integer -> Integer -> Integer
forall a. Num a => a -> a -> a
* Integer
radix Integer -> Integer -> Integer
forall a. Num a => a -> a -> a
+ Int -> Integer
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Char -> Int
digitToInt Char
d), Integer
p Integer -> Integer -> Integer
forall a. Num a => a -> a -> a
* Integer
radix)
collectFracDigits :: Parsec Char -> LabelConfig -> Bool -> Parsec [Char]
collectFracDigits :: Parsec Char -> LabelConfig -> Bool -> Parsec [Char]
collectFracDigits Parsec Char
dig LabelConfig
endLabel Bool
allowEmpty = case BreakCharDesc
literalBreakChar of
BreakCharDesc
NoBreakChar
| Bool
allowEmpty -> Parsec Char -> Parsec [Char]
forall a. Parsec a -> Parsec [a]
forall (f :: * -> *) a. Alternative f => f a -> f [a]
many (LabelConfig -> Parsec Char -> Parsec Char
forall config a. Annotate config => config -> Parsec a -> Parsec a
forall a. LabelConfig -> Parsec a -> Parsec a
annotate LabelConfig
endLabel Parsec Char
dig)
| Bool
otherwise -> LabelConfig -> Parsec Char -> Parsec Char
forall config a. Annotate config => config -> Parsec a -> Parsec a
forall a. LabelConfig -> Parsec a -> Parsec a
annotate LabelConfig
endLabel Parsec Char
dig Parsec Char -> Parsec [Char] -> Parsec [Char]
forall a. Parsec a -> Parsec [a] -> Parsec [a]
<:> Parsec Char -> Parsec [Char]
forall a. Parsec a -> Parsec [a]
forall (f :: * -> *) a. Alternative f => f a -> f [a]
many (LabelConfig -> Parsec Char -> Parsec Char
forall config a. Annotate config => config -> Parsec a -> Parsec a
forall a. LabelConfig -> Parsec a -> Parsec a
annotate LabelConfig
endLabel Parsec Char
dig)
BreakCharSupported Char
bc Bool
_
| Bool
allowEmpty -> Parsec Char -> Parsec [Char]
forall a. Parsec a -> Parsec [a]
forall (f :: * -> *) a. Alternative f => f a -> f [a]
many (Parsec Char -> Parsec ()
forall a. Parsec a -> Parsec ()
optional (LabelWithExplainConfig -> Parsec Char -> Parsec Char
forall config a. Annotate config => config -> Parsec a -> Parsec a
forall a. LabelWithExplainConfig -> Parsec a -> Parsec a
annotate (ErrorConfig -> LabelWithExplainConfig
labelNumericBreakChar ErrorConfig
err) (Char -> Parsec Char
char Char
bc)) Parsec () -> Parsec Char -> Parsec Char
forall a b. Parsec a -> Parsec b -> Parsec b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> LabelConfig -> Parsec Char -> Parsec Char
forall config a. Annotate config => config -> Parsec a -> Parsec a
forall a. LabelConfig -> Parsec a -> Parsec a
annotate LabelConfig
endLabel Parsec Char
dig)
| Bool
otherwise -> LabelConfig -> Parsec Char -> Parsec Char
forall config a. Annotate config => config -> Parsec a -> Parsec a
forall a. LabelConfig -> Parsec a -> Parsec a
annotate LabelConfig
endLabel Parsec Char
dig Parsec Char -> Parsec [Char] -> Parsec [Char]
forall a. Parsec a -> Parsec [a] -> Parsec [a]
<:> Parsec Char -> Parsec [Char]
forall a. Parsec a -> Parsec [a]
forall (f :: * -> *) a. Alternative f => f a -> f [a]
many (Parsec Char -> Parsec ()
forall a. Parsec a -> Parsec ()
optional (LabelWithExplainConfig -> Parsec Char -> Parsec Char
forall config a. Annotate config => config -> Parsec a -> Parsec a
forall a. LabelWithExplainConfig -> Parsec a -> Parsec a
annotate (ErrorConfig -> LabelWithExplainConfig
labelNumericBreakChar ErrorConfig
err) (Char -> Parsec Char
char Char
bc)) Parsec () -> Parsec Char -> Parsec Char
forall a b. Parsec a -> Parsec b -> Parsec b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> LabelConfig -> Parsec Char -> Parsec Char
forall config a. Annotate config => config -> Parsec a -> Parsec a
forall a. LabelConfig -> Parsec a -> Parsec a
annotate LabelConfig
endLabel Parsec Char
dig)
applyPrevent :: Parsec ()
applyPrevent :: Parsec ()
applyPrevent = case ErrorConfig -> PreventDotIsZeroConfig
preventRealDoubleDroppedZero ErrorConfig
err of
UnexpectedZeroDot [Char]
msg ->
(() -> Maybe [Char]) -> Parsec () -> Parsec ()
forall a. (a -> Maybe [Char]) -> Parsec a -> Parsec a
unexpectedWhen (Maybe [Char] -> () -> Maybe [Char]
forall a b. a -> b -> a
const ([Char] -> Maybe [Char]
forall a. a -> Maybe a
Just [Char]
msg)) (() -> Parsec ()
forall a. a -> Parsec a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ())
UnexpectedZeroDotWithReason [Char]
msg [Char]
rsn ->
(() -> Maybe ([Char], [Char])) -> Parsec () -> Parsec ()
forall a. (a -> Maybe ([Char], [Char])) -> Parsec a -> Parsec a
unexpectedWithReasonWhen (Maybe ([Char], [Char]) -> () -> Maybe ([Char], [Char])
forall a b. a -> b -> a
const (([Char], [Char]) -> Maybe ([Char], [Char])
forall a. a -> Maybe a
Just ([Char]
msg, [Char]
rsn))) (() -> Parsec ()
forall a. a -> Parsec a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ())
ZeroDotReason [Char]
rsn ->
(() -> Maybe [Char]) -> Parsec () -> Parsec ()
forall a. (a -> Maybe [Char]) -> Parsec a -> Parsec a
filterOut (Maybe [Char] -> () -> Maybe [Char]
forall a b. a -> b -> a
const ([Char] -> Maybe [Char]
forall a. a -> Maybe a
Just [Char]
rsn)) (() -> Parsec ()
forall a. a -> Parsec a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ())
ZeroDotFail [[Char]]
msgs ->
(() -> Maybe [[Char]]) -> Parsec () -> Parsec ()
forall a. (a -> Maybe [[Char]]) -> Parsec a -> Parsec a
guardAgainst (Maybe [[Char]] -> () -> Maybe [[Char]]
forall a b. a -> b -> a
const ([[Char]] -> Maybe [[Char]]
forall a. a -> Maybe a
Just [[Char]]
msgs)) (() -> Parsec ()
forall a. a -> Parsec a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ())
parseExponent :: ExponentDesc -> Parsec (Rational -> Rational)
parseExponent :: ExponentDesc -> Parsec (Ratio Integer -> Ratio Integer)
parseExponent ExponentDesc
NoExponents = (Ratio Integer -> Ratio Integer)
-> Parsec (Ratio Integer -> Ratio Integer)
forall a. a -> Parsec a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Ratio Integer -> Ratio Integer
forall a. a -> a
id
parseExponent ExponentsSupported{ compulsory :: ExponentDesc -> Bool
compulsory = Bool
compulsory, chars :: ExponentDesc -> Set Char
chars = Set Char
expChars, base :: ExponentDesc -> Int
base = Int
expBase
, expSign :: ExponentDesc -> PlusSignPresence
expSign = PlusSignPresence
expSign, expLeadingZerosAllowd :: ExponentDesc -> Bool
expLeadingZerosAllowd = Bool
expLeadingZerosAllowd } =
let expDigits :: Parsec Integer
expDigits = if Bool
expLeadingZerosAllowd
then GenericNumeric -> LabelConfig -> Parsec Integer
zeroAllowedDecimal GenericNumeric
gen (ErrorConfig -> LabelConfig
labelRealExponentEnd ErrorConfig
err)
else GenericNumeric -> LabelConfig -> Parsec Integer
zeroNotAllowedDecimal GenericNumeric
gen (ErrorConfig -> LabelConfig
labelRealExponentEnd ErrorConfig
err)
expSignParser :: Parsec (Integer -> Integer)
expSignParser :: Parsec (Integer -> Integer)
expSignParser = case PlusSignPresence
expSign of
PlusSignPresence
PlusRequired -> Char -> Parsec Char
char Char
'+' Parsec Char -> (Integer -> Integer) -> Parsec (Integer -> Integer)
forall a b. Parsec a -> b -> Parsec b
$> Integer -> Integer
forall a. a -> a
id Parsec (Integer -> Integer)
-> Parsec (Integer -> Integer) -> Parsec (Integer -> Integer)
forall a. Parsec a -> Parsec a -> Parsec a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Char -> Parsec Char
char Char
'-' Parsec Char -> (Integer -> Integer) -> Parsec (Integer -> Integer)
forall a b. Parsec a -> b -> Parsec b
$> Integer -> Integer
forall a. Num a => a -> a
negate
PlusSignPresence
PlusOptional -> Char -> Parsec Char
char Char
'-' Parsec Char -> (Integer -> Integer) -> Parsec (Integer -> Integer)
forall a b. Parsec a -> b -> Parsec b
$> Integer -> Integer
forall a. Num a => a -> a
negate Parsec (Integer -> Integer)
-> Parsec (Integer -> Integer) -> Parsec (Integer -> Integer)
forall a. Parsec a -> Parsec a -> Parsec a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (Integer -> Integer) -> Parsec Char -> Parsec (Integer -> Integer)
forall b a. b -> Parsec a -> Parsec b
optionalAs Integer -> Integer
forall a. a -> a
id (Char -> Parsec Char
char Char
'+')
PlusSignPresence
PlusIllegal -> (Integer -> Integer) -> Parsec (Integer -> Integer)
forall a. a -> Parsec a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Integer -> Integer
forall a. a -> a
id
expParser :: Parsec (Ratio Integer -> Ratio Integer)
expParser = LabelWithExplainConfig
-> Parsec (Ratio Integer -> Ratio Integer)
-> Parsec (Ratio Integer -> Ratio Integer)
forall config a. Annotate config => config -> Parsec a -> Parsec a
forall a. LabelWithExplainConfig -> Parsec a -> Parsec a
annotate (ErrorConfig -> LabelWithExplainConfig
labelRealExponent ErrorConfig
err) (Parsec (Ratio Integer -> Ratio Integer)
-> Parsec (Ratio Integer -> Ratio Integer))
-> Parsec (Ratio Integer -> Ratio Integer)
-> Parsec (Ratio Integer -> Ratio Integer)
forall a b. (a -> b) -> a -> b
$ do
Parsec Char -> Parsec ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void (Set Char -> Parsec Char
oneOf Set Char
expChars)
applySign <- Parsec (Integer -> Integer)
expSignParser
n <- expDigits
let e = Integer -> Integer
applySign Integer
n
pure $ if e >= 0
then (* fromInteger (toInteger expBase ^ e))
else (/ fromInteger (toInteger expBase ^ negate e))
in if Bool
compulsory then Parsec (Ratio Integer -> Ratio Integer)
expParser else Parsec (Ratio Integer -> Ratio Integer)
expParser Parsec (Ratio Integer -> Ratio Integer)
-> Parsec (Ratio Integer -> Ratio Integer)
-> Parsec (Ratio Integer -> Ratio Integer)
forall a. Parsec a -> Parsec a -> Parsec a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (Ratio Integer -> Ratio Integer)
-> Parsec (Ratio Integer -> Ratio Integer)
forall a. a -> Parsec a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Ratio Integer -> Ratio Integer
forall a. a -> a
id
floatBody :: Integer -> Parsec Integer -> Parsec Char -> LabelConfig -> ExponentDesc -> Parsec Rational
floatBody :: Integer
-> Parsec Integer
-> Parsec Char
-> LabelConfig
-> ExponentDesc
-> Parsec (Ratio Integer)
floatBody Integer
radix Parsec Integer
intP Parsec Char
dig LabelConfig
endLabel ExponentDesc
expDesc = do
mInt <- if Bool
leadingDotAllowed then Maybe Integer -> Parsec (Maybe Integer) -> Parsec (Maybe Integer)
forall b a. b -> Parsec a -> Parsec b
optionalAs Maybe Integer
forall a. Maybe a
Nothing ((Integer -> Maybe Integer)
-> Parsec Integer -> Parsec (Maybe Integer)
forall a b. (a -> b) -> Parsec a -> Parsec b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Integer -> Maybe Integer
forall a. a -> Maybe a
Just Parsec Integer
intP) else (Integer -> Maybe Integer)
-> Parsec Integer -> Parsec (Maybe Integer)
forall a b. (a -> b) -> Parsec a -> Parsec b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Integer -> Maybe Integer
forall a. a -> Maybe a
Just Parsec Integer
intP
void (annotate (labelRealDot err) (char '.'))
fracs <- collectFracDigits dig endLabel trailingDotAllowed
when (leadingDotAllowed && trailingDotAllowed && null mInt && null fracs) applyPrevent
let sig = Ratio Integer
-> (Integer -> Ratio Integer) -> Maybe Integer -> Ratio Integer
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Ratio Integer
0 Integer -> Ratio Integer
forall a. Num a => Integer -> a
fromInteger Maybe Integer
mInt Ratio Integer -> Ratio Integer -> Ratio Integer
forall a. Num a => a -> a -> a
+ Integer -> [Char] -> Ratio Integer
foldFrac Integer
radix [Char]
fracs
expFn <- parseExponent expDesc
pure (expFn sig)
leadingBreakChar :: Parsec ()
leadingBreakChar :: Parsec ()
leadingBreakChar = case BreakCharDesc
literalBreakChar of
BreakCharDesc
NoBreakChar -> Parsec ()
unit
BreakCharSupported Char
breakChar Bool
allowedAfterNonDecimalPrefix ->
Bool -> Parsec () -> Parsec ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when Bool
allowedAfterNonDecimalPrefix (Parsec Char -> Parsec ()
forall a. Parsec a -> Parsec ()
optional (Char -> Parsec Char
char Char
breakChar))
noZeroHexFloat :: Parsec Rational
noZeroHexFloat :: Parsec (Ratio Integer)
noZeroHexFloat = do
Bool -> Parsec () -> Parsec ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless (Set Char -> Bool
forall a. Set a -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null Set Char
hexadecimalLeads) (Parsec Char -> Parsec ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void (Set Char -> Parsec Char
oneOf Set Char
hexadecimalLeads))
Parsec ()
leadingBreakChar
Integer
-> Parsec Integer
-> Parsec Char
-> LabelConfig
-> ExponentDesc
-> Parsec (Ratio Integer)
floatBody Integer
16 (GenericNumeric -> LabelConfig -> Parsec Integer
zeroAllowedHexadecimal GenericNumeric
gen (ErrorConfig -> LabelConfig
labelRealHexadecimalEnd ErrorConfig
err))
Parsec Char
hexDigit (ErrorConfig -> LabelConfig
labelRealHexadecimalEnd ErrorConfig
err) ExponentDesc
hexadecimalExponentDesc
noZeroOctalFloat :: Parsec Rational
noZeroOctalFloat :: Parsec (Ratio Integer)
noZeroOctalFloat = do
Bool -> Parsec () -> Parsec ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless (Set Char -> Bool
forall a. Set a -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null Set Char
octalLeads) (Parsec Char -> Parsec ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void (Set Char -> Parsec Char
oneOf Set Char
octalLeads))
Parsec ()
leadingBreakChar
Integer
-> Parsec Integer
-> Parsec Char
-> LabelConfig
-> ExponentDesc
-> Parsec (Ratio Integer)
floatBody Integer
8 (GenericNumeric -> LabelConfig -> Parsec Integer
zeroAllowedOctal GenericNumeric
gen (ErrorConfig -> LabelConfig
labelRealOctalEnd ErrorConfig
err))
Parsec Char
octDigit (ErrorConfig -> LabelConfig
labelRealOctalEnd ErrorConfig
err) ExponentDesc
octalExponentDesc
noZeroBinaryFloat :: Parsec Rational
noZeroBinaryFloat :: Parsec (Ratio Integer)
noZeroBinaryFloat = do
Bool -> Parsec () -> Parsec ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless (Set Char -> Bool
forall a. Set a -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null Set Char
binaryLeads) (Parsec Char -> Parsec ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void (Set Char -> Parsec Char
oneOf Set Char
binaryLeads))
Parsec ()
leadingBreakChar
Integer
-> Parsec Integer
-> Parsec Char
-> LabelConfig
-> ExponentDesc
-> Parsec (Ratio Integer)
floatBody Integer
2 (GenericNumeric -> LabelConfig -> Parsec Integer
zeroAllowedBinary GenericNumeric
gen (ErrorConfig -> LabelConfig
labelRealBinaryEnd ErrorConfig
err))
Parsec Char
bit (ErrorConfig -> LabelConfig
labelRealBinaryEnd ErrorConfig
err) ExponentDesc
binaryExponentDesc
decimalFloating :: Parsec Rational
decimalFloating :: Parsec (Ratio Integer)
decimalFloating = LabelConfig -> Parsec (Ratio Integer) -> Parsec (Ratio Integer)
forall config a. Annotate config => config -> Parsec a -> Parsec a
forall a. LabelConfig -> Parsec a -> Parsec a
annotate (ErrorConfig -> LabelConfig
labelRealDecimal ErrorConfig
err) (Parsec (Ratio Integer) -> Parsec (Ratio Integer))
-> Parsec (Ratio Integer) -> Parsec (Ratio Integer)
forall a b. (a -> b) -> a -> b
$ Parsec (Ratio Integer) -> Parsec (Ratio Integer)
forall a. Parsec a -> Parsec a
atomic (Parsec (Ratio Integer) -> Parsec (Ratio Integer))
-> Parsec (Ratio Integer) -> Parsec (Ratio Integer)
forall a b. (a -> b) -> a -> b
$
Integer
-> Parsec Integer
-> Parsec Char
-> LabelConfig
-> ExponentDesc
-> Parsec (Ratio Integer)
floatBody Integer
10 (IntegerParsers CanHoldUnsigned -> Parsec Integer
forall (canHold :: Bits -> * -> Constraint).
IntegerParsers canHold -> Parsec Integer
decimal IntegerParsers CanHoldUnsigned
nat) Parsec Char
digit LabelConfig
LNotConfigured ExponentDesc
decimalExponentDesc
hexadecimalFloating :: Parsec Rational
hexadecimalFloating :: Parsec (Ratio Integer)
hexadecimalFloating = LabelConfig -> Parsec (Ratio Integer) -> Parsec (Ratio Integer)
forall config a. Annotate config => config -> Parsec a -> Parsec a
forall a. LabelConfig -> Parsec a -> Parsec a
annotate (ErrorConfig -> LabelConfig
labelRealHexadecimalEnd ErrorConfig
err) (Parsec (Ratio Integer) -> Parsec (Ratio Integer))
-> Parsec (Ratio Integer) -> Parsec (Ratio Integer)
forall a b. (a -> b) -> a -> b
$ Parsec (Ratio Integer) -> Parsec (Ratio Integer)
forall a. Parsec a -> Parsec a
atomic (Char -> Parsec Char
char Char
'0' Parsec Char -> Parsec (Ratio Integer) -> Parsec (Ratio Integer)
forall a b. Parsec a -> Parsec b -> Parsec b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parsec (Ratio Integer)
noZeroHexFloat)
octalFloating :: Parsec Rational
octalFloating :: Parsec (Ratio Integer)
octalFloating = LabelConfig -> Parsec (Ratio Integer) -> Parsec (Ratio Integer)
forall config a. Annotate config => config -> Parsec a -> Parsec a
forall a. LabelConfig -> Parsec a -> Parsec a
annotate (ErrorConfig -> LabelConfig
labelRealOctalEnd ErrorConfig
err) (Parsec (Ratio Integer) -> Parsec (Ratio Integer))
-> Parsec (Ratio Integer) -> Parsec (Ratio Integer)
forall a b. (a -> b) -> a -> b
$ Parsec (Ratio Integer) -> Parsec (Ratio Integer)
forall a. Parsec a -> Parsec a
atomic (Char -> Parsec Char
char Char
'0' Parsec Char -> Parsec (Ratio Integer) -> Parsec (Ratio Integer)
forall a b. Parsec a -> Parsec b -> Parsec b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parsec (Ratio Integer)
noZeroOctalFloat)
binaryFloating :: Parsec Rational
binaryFloating :: Parsec (Ratio Integer)
binaryFloating = LabelConfig -> Parsec (Ratio Integer) -> Parsec (Ratio Integer)
forall config a. Annotate config => config -> Parsec a -> Parsec a
forall a. LabelConfig -> Parsec a -> Parsec a
annotate (ErrorConfig -> LabelConfig
labelRealBinaryEnd ErrorConfig
err) (Parsec (Ratio Integer) -> Parsec (Ratio Integer))
-> Parsec (Ratio Integer) -> Parsec (Ratio Integer)
forall a b. (a -> b) -> a -> b
$ Parsec (Ratio Integer) -> Parsec (Ratio Integer)
forall a. Parsec a -> Parsec a
atomic (Char -> Parsec Char
char Char
'0' Parsec Char -> Parsec (Ratio Integer) -> Parsec (Ratio Integer)
forall a b. Parsec a -> Parsec b -> Parsec b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parsec (Ratio Integer)
noZeroBinaryFloat)
numberFloating :: Parsec Rational
numberFloating :: Parsec (Ratio Integer)
numberFloating
| Bool -> Bool
not Bool
realNumbersCanBeBinary
, Bool -> Bool
not Bool
realNumbersCanBeHexadecimal
, Bool -> Bool
not Bool
realNumbersCanBeOctal =
LabelConfig -> Parsec (Ratio Integer) -> Parsec (Ratio Integer)
forall config a. Annotate config => config -> Parsec a -> Parsec a
forall a. LabelConfig -> Parsec a -> Parsec a
annotate (ErrorConfig -> LabelConfig
labelRealNumberEnd ErrorConfig
err) Parsec (Ratio Integer)
decimalFloating
| Bool
otherwise = LabelConfig -> Parsec (Ratio Integer) -> Parsec (Ratio Integer)
forall config a. Annotate config => config -> Parsec a -> Parsec a
forall a. LabelConfig -> Parsec a -> Parsec a
annotate (ErrorConfig -> LabelConfig
labelRealNumberEnd ErrorConfig
err) (Parsec (Ratio Integer) -> Parsec (Ratio Integer))
-> Parsec (Ratio Integer) -> Parsec (Ratio Integer)
forall a b. (a -> b) -> a -> b
$ Parsec (Ratio Integer) -> Parsec (Ratio Integer)
forall a. Parsec a -> Parsec a
atomic (Parsec (Ratio Integer) -> Parsec (Ratio Integer))
-> Parsec (Ratio Integer) -> Parsec (Ratio Integer)
forall a b. (a -> b) -> a -> b
$
Parsec (Ratio Integer) -> Parsec (Ratio Integer)
addHex (Parsec (Ratio Integer) -> Parsec (Ratio Integer)
addOct (Parsec (Ratio Integer) -> Parsec (Ratio Integer)
addBin Parsec (Ratio Integer)
decimalFloating))
where
addHex :: Parsec (Ratio Integer) -> Parsec (Ratio Integer)
addHex | Bool
realNumbersCanBeHexadecimal = (Parsec (Ratio Integer)
hexadecimalFloating Parsec (Ratio Integer)
-> Parsec (Ratio Integer) -> Parsec (Ratio Integer)
forall a. Parsec a -> Parsec a -> Parsec a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|>)
| Bool
otherwise = Parsec (Ratio Integer) -> Parsec (Ratio Integer)
forall a. a -> a
id
addOct :: Parsec (Ratio Integer) -> Parsec (Ratio Integer)
addOct | Bool
realNumbersCanBeOctal = (Parsec (Ratio Integer)
octalFloating Parsec (Ratio Integer)
-> Parsec (Ratio Integer) -> Parsec (Ratio Integer)
forall a. Parsec a -> Parsec a -> Parsec a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|>)
| Bool
otherwise = Parsec (Ratio Integer) -> Parsec (Ratio Integer)
forall a. a -> a
id
addBin :: Parsec (Ratio Integer) -> Parsec (Ratio Integer)
addBin | Bool
realNumbersCanBeBinary = (Parsec (Ratio Integer)
binaryFloating Parsec (Ratio Integer)
-> Parsec (Ratio Integer) -> Parsec (Ratio Integer)
forall a. Parsec a -> Parsec a -> Parsec a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|>)
| Bool
otherwise = Parsec (Ratio Integer) -> Parsec (Ratio Integer)
forall a. a -> a
id
mkSignedFloating :: NumericDesc -> FloatingParsers -> ErrorConfig -> FloatingParsers
mkSignedFloating :: NumericDesc -> FloatingParsers -> ErrorConfig -> FloatingParsers
mkSignedFloating NumericDesc{positiveSign :: NumericDesc -> PlusSignPresence
positiveSign = PlusSignPresence
positiveSign} !FloatingParsers
unsigned !ErrorConfig
_err = FloatingParsers {
decimalFloating :: Parsec (Ratio Integer)
decimalFloating = Parsec (Ratio Integer) -> Parsec (Ratio Integer)
signed (FloatingParsers -> Parsec (Ratio Integer)
decimalFloating FloatingParsers
unsigned),
hexadecimalFloating :: Parsec (Ratio Integer)
hexadecimalFloating = Parsec (Ratio Integer) -> Parsec (Ratio Integer)
signed (FloatingParsers -> Parsec (Ratio Integer)
hexadecimalFloating FloatingParsers
unsigned),
octalFloating :: Parsec (Ratio Integer)
octalFloating = Parsec (Ratio Integer) -> Parsec (Ratio Integer)
signed (FloatingParsers -> Parsec (Ratio Integer)
octalFloating FloatingParsers
unsigned),
binaryFloating :: Parsec (Ratio Integer)
binaryFloating = Parsec (Ratio Integer) -> Parsec (Ratio Integer)
signed (FloatingParsers -> Parsec (Ratio Integer)
binaryFloating FloatingParsers
unsigned),
numberFloating :: Parsec (Ratio Integer)
numberFloating = Parsec (Ratio Integer) -> Parsec (Ratio Integer)
signed (FloatingParsers -> Parsec (Ratio Integer)
numberFloating FloatingParsers
unsigned)
}
where
sign :: Parsec (Rational -> Rational)
sign :: Parsec (Ratio Integer -> Ratio Integer)
sign = case PlusSignPresence
positiveSign of
PlusSignPresence
PlusRequired -> Char -> Parsec Char
char Char
'+' Parsec Char
-> (Ratio Integer -> Ratio Integer)
-> Parsec (Ratio Integer -> Ratio Integer)
forall a b. Parsec a -> b -> Parsec b
$> Ratio Integer -> Ratio Integer
forall a. a -> a
id Parsec (Ratio Integer -> Ratio Integer)
-> Parsec (Ratio Integer -> Ratio Integer)
-> Parsec (Ratio Integer -> Ratio Integer)
forall a. Parsec a -> Parsec a -> Parsec a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Char -> Parsec Char
char Char
'-' Parsec Char
-> (Ratio Integer -> Ratio Integer)
-> Parsec (Ratio Integer -> Ratio Integer)
forall a b. Parsec a -> b -> Parsec b
$> Ratio Integer -> Ratio Integer
forall a. Num a => a -> a
negate
PlusSignPresence
PlusOptional -> Char -> Parsec Char
char Char
'-' Parsec Char
-> (Ratio Integer -> Ratio Integer)
-> Parsec (Ratio Integer -> Ratio Integer)
forall a b. Parsec a -> b -> Parsec b
$> Ratio Integer -> Ratio Integer
forall a. Num a => a -> a
negate Parsec (Ratio Integer -> Ratio Integer)
-> Parsec (Ratio Integer -> Ratio Integer)
-> Parsec (Ratio Integer -> Ratio Integer)
forall a. Parsec a -> Parsec a -> Parsec a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (Ratio Integer -> Ratio Integer)
-> Parsec Char -> Parsec (Ratio Integer -> Ratio Integer)
forall b a. b -> Parsec a -> Parsec b
optionalAs Ratio Integer -> Ratio Integer
forall a. a -> a
id (Char -> Parsec Char
char Char
'+')
PlusSignPresence
PlusIllegal -> (Ratio Integer -> Ratio Integer)
-> Parsec (Ratio Integer -> Ratio Integer)
forall a. a -> Parsec a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Ratio Integer -> Ratio Integer
forall a. a -> a
id
signed :: Parsec Rational -> Parsec Rational
signed :: Parsec (Ratio Integer) -> Parsec (Ratio Integer)
signed Parsec (Ratio Integer)
p = Parsec (Ratio Integer) -> Parsec (Ratio Integer)
forall a. Parsec a -> Parsec a
atomic (Parsec (Ratio Integer -> Ratio Integer)
sign Parsec (Ratio Integer -> Ratio Integer)
-> Parsec (Ratio Integer) -> Parsec (Ratio Integer)
forall a b. Parsec (a -> b) -> Parsec a -> Parsec b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parsec (Ratio Integer)
p)
type CombinedParsers :: *
data CombinedParsers = CombinedParsers {
CombinedParsers -> Parsec (Either Integer (Ratio Integer))
decimalCombined :: Parsec (Either Integer Rational)
, CombinedParsers -> Parsec (Either Integer (Ratio Integer))
hexadecimalCombined :: Parsec (Either Integer Rational)
, CombinedParsers -> Parsec (Either Integer (Ratio Integer))
octalCombined :: Parsec (Either Integer Rational)
, CombinedParsers -> Parsec (Either Integer (Ratio Integer))
binaryCombined :: Parsec (Either Integer Rational)
, CombinedParsers -> Parsec (Either Integer (Ratio Integer))
numberCombined :: Parsec (Either Integer Rational)
}
mkUnsignedCombined :: NumericDesc -> IntegerParsers CanHoldUnsigned -> FloatingParsers -> CombinedParsers
mkUnsignedCombined :: NumericDesc
-> IntegerParsers CanHoldUnsigned
-> FloatingParsers
-> CombinedParsers
mkUnsignedCombined NumericDesc
_desc !IntegerParsers CanHoldUnsigned
nat !FloatingParsers
fl = CombinedParsers {
decimalCombined :: Parsec (Either Integer (Ratio Integer))
decimalCombined = Parsec (Ratio Integer)
-> Parsec Integer -> Parsec (Either Integer (Ratio Integer))
combinedOf (FloatingParsers -> Parsec (Ratio Integer)
decimalFloating FloatingParsers
fl) (IntegerParsers CanHoldUnsigned -> Parsec Integer
forall (canHold :: Bits -> * -> Constraint).
IntegerParsers canHold -> Parsec Integer
decimal IntegerParsers CanHoldUnsigned
nat),
hexadecimalCombined :: Parsec (Either Integer (Ratio Integer))
hexadecimalCombined = Parsec (Ratio Integer)
-> Parsec Integer -> Parsec (Either Integer (Ratio Integer))
combinedOf (FloatingParsers -> Parsec (Ratio Integer)
hexadecimalFloating FloatingParsers
fl) (IntegerParsers CanHoldUnsigned -> Parsec Integer
forall (canHold :: Bits -> * -> Constraint).
IntegerParsers canHold -> Parsec Integer
hexadecimal IntegerParsers CanHoldUnsigned
nat),
octalCombined :: Parsec (Either Integer (Ratio Integer))
octalCombined = Parsec (Ratio Integer)
-> Parsec Integer -> Parsec (Either Integer (Ratio Integer))
combinedOf (FloatingParsers -> Parsec (Ratio Integer)
octalFloating FloatingParsers
fl) (IntegerParsers CanHoldUnsigned -> Parsec Integer
forall (canHold :: Bits -> * -> Constraint).
IntegerParsers canHold -> Parsec Integer
octal IntegerParsers CanHoldUnsigned
nat),
binaryCombined :: Parsec (Either Integer (Ratio Integer))
binaryCombined = Parsec (Ratio Integer)
-> Parsec Integer -> Parsec (Either Integer (Ratio Integer))
combinedOf (FloatingParsers -> Parsec (Ratio Integer)
binaryFloating FloatingParsers
fl) (IntegerParsers CanHoldUnsigned -> Parsec Integer
forall (canHold :: Bits -> * -> Constraint).
IntegerParsers canHold -> Parsec Integer
binary IntegerParsers CanHoldUnsigned
nat),
numberCombined :: Parsec (Either Integer (Ratio Integer))
numberCombined = Parsec (Ratio Integer)
-> Parsec Integer -> Parsec (Either Integer (Ratio Integer))
combinedOf (FloatingParsers -> Parsec (Ratio Integer)
numberFloating FloatingParsers
fl) (IntegerParsers CanHoldUnsigned -> Parsec Integer
forall (canHold :: Bits -> * -> Constraint).
IntegerParsers canHold -> Parsec Integer
number IntegerParsers CanHoldUnsigned
nat)
}
where
combinedOf :: Parsec Rational -> Parsec Integer -> Parsec (Either Integer Rational)
combinedOf :: Parsec (Ratio Integer)
-> Parsec Integer -> Parsec (Either Integer (Ratio Integer))
combinedOf Parsec (Ratio Integer)
real Parsec Integer
int = (Ratio Integer -> Either Integer (Ratio Integer))
-> Parsec (Ratio Integer)
-> Parsec (Either Integer (Ratio Integer))
forall a b. (a -> b) -> Parsec a -> Parsec b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Ratio Integer -> Either Integer (Ratio Integer)
forall a b. b -> Either a b
Right (Parsec (Ratio Integer) -> Parsec (Ratio Integer)
forall a. Parsec a -> Parsec a
atomic Parsec (Ratio Integer)
real) Parsec (Either Integer (Ratio Integer))
-> Parsec (Either Integer (Ratio Integer))
-> Parsec (Either Integer (Ratio Integer))
forall a. Parsec a -> Parsec a -> Parsec a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (Integer -> Either Integer (Ratio Integer))
-> Parsec Integer -> Parsec (Either Integer (Ratio Integer))
forall a b. (a -> b) -> Parsec a -> Parsec b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Integer -> Either Integer (Ratio Integer)
forall a b. a -> Either a b
Left Parsec Integer
int
mkSignedCombined :: NumericDesc -> CombinedParsers -> CombinedParsers
mkSignedCombined :: NumericDesc -> CombinedParsers -> CombinedParsers
mkSignedCombined NumericDesc{positiveSign :: NumericDesc -> PlusSignPresence
positiveSign = PlusSignPresence
positiveSign} !CombinedParsers
unsigned = CombinedParsers {
decimalCombined :: Parsec (Either Integer (Ratio Integer))
decimalCombined = Parsec (Either Integer (Ratio Integer))
-> Parsec (Either Integer (Ratio Integer))
signed (CombinedParsers -> Parsec (Either Integer (Ratio Integer))
decimalCombined CombinedParsers
unsigned),
hexadecimalCombined :: Parsec (Either Integer (Ratio Integer))
hexadecimalCombined = Parsec (Either Integer (Ratio Integer))
-> Parsec (Either Integer (Ratio Integer))
signed (CombinedParsers -> Parsec (Either Integer (Ratio Integer))
hexadecimalCombined CombinedParsers
unsigned),
octalCombined :: Parsec (Either Integer (Ratio Integer))
octalCombined = Parsec (Either Integer (Ratio Integer))
-> Parsec (Either Integer (Ratio Integer))
signed (CombinedParsers -> Parsec (Either Integer (Ratio Integer))
octalCombined CombinedParsers
unsigned),
binaryCombined :: Parsec (Either Integer (Ratio Integer))
binaryCombined = Parsec (Either Integer (Ratio Integer))
-> Parsec (Either Integer (Ratio Integer))
signed (CombinedParsers -> Parsec (Either Integer (Ratio Integer))
binaryCombined CombinedParsers
unsigned),
numberCombined :: Parsec (Either Integer (Ratio Integer))
numberCombined = Parsec (Either Integer (Ratio Integer))
-> Parsec (Either Integer (Ratio Integer))
signed (CombinedParsers -> Parsec (Either Integer (Ratio Integer))
numberCombined CombinedParsers
unsigned)
}
where
sign :: Parsec (Either Integer Rational -> Either Integer Rational)
sign :: Parsec
(Either Integer (Ratio Integer) -> Either Integer (Ratio Integer))
sign = case PlusSignPresence
positiveSign of
PlusSignPresence
PlusRequired -> Char -> Parsec Char
char Char
'+' Parsec Char
-> (Either Integer (Ratio Integer)
-> Either Integer (Ratio Integer))
-> Parsec
(Either Integer (Ratio Integer) -> Either Integer (Ratio Integer))
forall a b. Parsec a -> b -> Parsec b
$> Either Integer (Ratio Integer) -> Either Integer (Ratio Integer)
forall a. a -> a
id Parsec
(Either Integer (Ratio Integer) -> Either Integer (Ratio Integer))
-> Parsec
(Either Integer (Ratio Integer) -> Either Integer (Ratio Integer))
-> Parsec
(Either Integer (Ratio Integer) -> Either Integer (Ratio Integer))
forall a. Parsec a -> Parsec a -> Parsec a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Char -> Parsec Char
char Char
'-' Parsec Char
-> (Either Integer (Ratio Integer)
-> Either Integer (Ratio Integer))
-> Parsec
(Either Integer (Ratio Integer) -> Either Integer (Ratio Integer))
forall a b. Parsec a -> b -> Parsec b
$> (Integer -> Integer)
-> (Ratio Integer -> Ratio Integer)
-> Either Integer (Ratio Integer)
-> Either Integer (Ratio Integer)
forall a b c d. (a -> b) -> (c -> d) -> Either a c -> Either b d
forall (p :: * -> * -> *) a b c d.
Bifunctor p =>
(a -> b) -> (c -> d) -> p a c -> p b d
bimap Integer -> Integer
forall a. Num a => a -> a
negate Ratio Integer -> Ratio Integer
forall a. Num a => a -> a
negate
PlusSignPresence
PlusOptional -> Char -> Parsec Char
char Char
'-' Parsec Char
-> (Either Integer (Ratio Integer)
-> Either Integer (Ratio Integer))
-> Parsec
(Either Integer (Ratio Integer) -> Either Integer (Ratio Integer))
forall a b. Parsec a -> b -> Parsec b
$> (Integer -> Integer)
-> (Ratio Integer -> Ratio Integer)
-> Either Integer (Ratio Integer)
-> Either Integer (Ratio Integer)
forall a b c d. (a -> b) -> (c -> d) -> Either a c -> Either b d
forall (p :: * -> * -> *) a b c d.
Bifunctor p =>
(a -> b) -> (c -> d) -> p a c -> p b d
bimap Integer -> Integer
forall a. Num a => a -> a
negate Ratio Integer -> Ratio Integer
forall a. Num a => a -> a
negate Parsec
(Either Integer (Ratio Integer) -> Either Integer (Ratio Integer))
-> Parsec
(Either Integer (Ratio Integer) -> Either Integer (Ratio Integer))
-> Parsec
(Either Integer (Ratio Integer) -> Either Integer (Ratio Integer))
forall a. Parsec a -> Parsec a -> Parsec a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (Either Integer (Ratio Integer) -> Either Integer (Ratio Integer))
-> Parsec Char
-> Parsec
(Either Integer (Ratio Integer) -> Either Integer (Ratio Integer))
forall b a. b -> Parsec a -> Parsec b
optionalAs Either Integer (Ratio Integer) -> Either Integer (Ratio Integer)
forall a. a -> a
id (Char -> Parsec Char
char Char
'+')
PlusSignPresence
PlusIllegal -> (Either Integer (Ratio Integer) -> Either Integer (Ratio Integer))
-> Parsec
(Either Integer (Ratio Integer) -> Either Integer (Ratio Integer))
forall a. a -> Parsec a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Either Integer (Ratio Integer) -> Either Integer (Ratio Integer)
forall a. a -> a
id
signed :: Parsec (Either Integer Rational) -> Parsec (Either Integer Rational)
signed :: Parsec (Either Integer (Ratio Integer))
-> Parsec (Either Integer (Ratio Integer))
signed Parsec (Either Integer (Ratio Integer))
p = Parsec (Either Integer (Ratio Integer))
-> Parsec (Either Integer (Ratio Integer))
forall a. Parsec a -> Parsec a
atomic (Parsec
(Either Integer (Ratio Integer) -> Either Integer (Ratio Integer))
sign Parsec
(Either Integer (Ratio Integer) -> Either Integer (Ratio Integer))
-> Parsec (Either Integer (Ratio Integer))
-> Parsec (Either Integer (Ratio Integer))
forall a b. Parsec (a -> b) -> Parsec a -> Parsec b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parsec (Either Integer (Ratio Integer))
p)
lexemeInteger :: (forall a. Parsec a -> Parsec a) -> IntegerParsers c -> IntegerParsers c
lexemeInteger :: forall (c :: Bits -> * -> Constraint).
(forall a. Parsec a -> Parsec a)
-> IntegerParsers c -> IntegerParsers c
lexemeInteger forall a. Parsec a -> Parsec a
lexe IntegerParsers{Parsec Integer
forall (bits :: Bits) t.
c bits t =>
Proxy bits
-> Parsec Integer
-> Int
-> (ErrorConfig -> Bool -> Maybe Bits -> LabelWithExplainConfig)
-> Parsec t
decimal :: forall (canHold :: Bits -> * -> Constraint).
IntegerParsers canHold -> Parsec Integer
hexadecimal :: forall (canHold :: Bits -> * -> Constraint).
IntegerParsers canHold -> Parsec Integer
octal :: forall (canHold :: Bits -> * -> Constraint).
IntegerParsers canHold -> Parsec Integer
binary :: forall (canHold :: Bits -> * -> Constraint).
IntegerParsers canHold -> Parsec Integer
number :: forall (canHold :: Bits -> * -> Constraint).
IntegerParsers canHold -> Parsec Integer
_bounded :: forall (canHold :: Bits -> * -> Constraint).
IntegerParsers canHold
-> forall (bits :: Bits) t.
canHold bits t =>
Proxy bits
-> Parsec Integer
-> Int
-> (ErrorConfig -> Bool -> Maybe Bits -> LabelWithExplainConfig)
-> Parsec t
decimal :: Parsec Integer
hexadecimal :: Parsec Integer
octal :: Parsec Integer
binary :: Parsec Integer
number :: Parsec Integer
_bounded :: forall (bits :: Bits) t.
c bits t =>
Proxy bits
-> Parsec Integer
-> Int
-> (ErrorConfig -> Bool -> Maybe Bits -> LabelWithExplainConfig)
-> Parsec t
..} = IntegerParsers {
decimal :: Parsec Integer
decimal = Parsec Integer -> Parsec Integer
forall a. Parsec a -> Parsec a
lexe Parsec Integer
decimal,
hexadecimal :: Parsec Integer
hexadecimal = Parsec Integer -> Parsec Integer
forall a. Parsec a -> Parsec a
lexe Parsec Integer
hexadecimal,
octal :: Parsec Integer
octal = Parsec Integer -> Parsec Integer
forall a. Parsec a -> Parsec a
lexe Parsec Integer
octal,
binary :: Parsec Integer
binary = Parsec Integer -> Parsec Integer
forall a. Parsec a -> Parsec a
lexe Parsec Integer
binary,
number :: Parsec Integer
number = Parsec Integer -> Parsec Integer
forall a. Parsec a -> Parsec a
lexe Parsec Integer
number,
_bounded :: forall (bits :: Bits) t.
c bits t =>
Proxy bits
-> Parsec Integer
-> Int
-> (ErrorConfig -> Bool -> Maybe Bits -> LabelWithExplainConfig)
-> Parsec t
_bounded = \Proxy bits
n Parsec Integer
b Int
radix ErrorConfig -> Bool -> Maybe Bits -> LabelWithExplainConfig
label -> Parsec t -> Parsec t
forall a. Parsec a -> Parsec a
lexe (Proxy bits
-> Parsec Integer
-> Int
-> (ErrorConfig -> Bool -> Maybe Bits -> LabelWithExplainConfig)
-> Parsec t
forall (bits :: Bits) t.
c bits t =>
Proxy bits
-> Parsec Integer
-> Int
-> (ErrorConfig -> Bool -> Maybe Bits -> LabelWithExplainConfig)
-> Parsec t
_bounded Proxy bits
n Parsec Integer
b Int
radix ErrorConfig -> Bool -> Maybe Bits -> LabelWithExplainConfig
label)
}
lexemeFloating :: (forall a. Parsec a -> Parsec a) -> FloatingParsers -> FloatingParsers
lexemeFloating :: (forall a. Parsec a -> Parsec a)
-> FloatingParsers -> FloatingParsers
lexemeFloating forall a. Parsec a -> Parsec a
lexe FloatingParsers{Parsec (Ratio Integer)
decimalFloating :: FloatingParsers -> Parsec (Ratio Integer)
hexadecimalFloating :: FloatingParsers -> Parsec (Ratio Integer)
octalFloating :: FloatingParsers -> Parsec (Ratio Integer)
binaryFloating :: FloatingParsers -> Parsec (Ratio Integer)
numberFloating :: FloatingParsers -> Parsec (Ratio Integer)
decimalFloating :: Parsec (Ratio Integer)
hexadecimalFloating :: Parsec (Ratio Integer)
octalFloating :: Parsec (Ratio Integer)
binaryFloating :: Parsec (Ratio Integer)
numberFloating :: Parsec (Ratio Integer)
..} = FloatingParsers {
decimalFloating :: Parsec (Ratio Integer)
decimalFloating = Parsec (Ratio Integer) -> Parsec (Ratio Integer)
forall a. Parsec a -> Parsec a
lexe Parsec (Ratio Integer)
decimalFloating,
hexadecimalFloating :: Parsec (Ratio Integer)
hexadecimalFloating = Parsec (Ratio Integer) -> Parsec (Ratio Integer)
forall a. Parsec a -> Parsec a
lexe Parsec (Ratio Integer)
hexadecimalFloating,
octalFloating :: Parsec (Ratio Integer)
octalFloating = Parsec (Ratio Integer) -> Parsec (Ratio Integer)
forall a. Parsec a -> Parsec a
lexe Parsec (Ratio Integer)
octalFloating,
binaryFloating :: Parsec (Ratio Integer)
binaryFloating = Parsec (Ratio Integer) -> Parsec (Ratio Integer)
forall a. Parsec a -> Parsec a
lexe Parsec (Ratio Integer)
binaryFloating,
numberFloating :: Parsec (Ratio Integer)
numberFloating = Parsec (Ratio Integer) -> Parsec (Ratio Integer)
forall a. Parsec a -> Parsec a
lexe Parsec (Ratio Integer)
numberFloating
}
lexemeCombined :: (forall a. Parsec a -> Parsec a) -> CombinedParsers -> CombinedParsers
lexemeCombined :: (forall a. Parsec a -> Parsec a)
-> CombinedParsers -> CombinedParsers
lexemeCombined forall a. Parsec a -> Parsec a
lexe CombinedParsers{Parsec (Either Integer (Ratio Integer))
decimalCombined :: CombinedParsers -> Parsec (Either Integer (Ratio Integer))
hexadecimalCombined :: CombinedParsers -> Parsec (Either Integer (Ratio Integer))
octalCombined :: CombinedParsers -> Parsec (Either Integer (Ratio Integer))
binaryCombined :: CombinedParsers -> Parsec (Either Integer (Ratio Integer))
numberCombined :: CombinedParsers -> Parsec (Either Integer (Ratio Integer))
decimalCombined :: Parsec (Either Integer (Ratio Integer))
hexadecimalCombined :: Parsec (Either Integer (Ratio Integer))
octalCombined :: Parsec (Either Integer (Ratio Integer))
binaryCombined :: Parsec (Either Integer (Ratio Integer))
numberCombined :: Parsec (Either Integer (Ratio Integer))
..} = CombinedParsers {
decimalCombined :: Parsec (Either Integer (Ratio Integer))
decimalCombined = Parsec (Either Integer (Ratio Integer))
-> Parsec (Either Integer (Ratio Integer))
forall a. Parsec a -> Parsec a
lexe Parsec (Either Integer (Ratio Integer))
decimalCombined,
hexadecimalCombined :: Parsec (Either Integer (Ratio Integer))
hexadecimalCombined = Parsec (Either Integer (Ratio Integer))
-> Parsec (Either Integer (Ratio Integer))
forall a. Parsec a -> Parsec a
lexe Parsec (Either Integer (Ratio Integer))
hexadecimalCombined,
octalCombined :: Parsec (Either Integer (Ratio Integer))
octalCombined = Parsec (Either Integer (Ratio Integer))
-> Parsec (Either Integer (Ratio Integer))
forall a. Parsec a -> Parsec a
lexe Parsec (Either Integer (Ratio Integer))
octalCombined,
binaryCombined :: Parsec (Either Integer (Ratio Integer))
binaryCombined = Parsec (Either Integer (Ratio Integer))
-> Parsec (Either Integer (Ratio Integer))
forall a. Parsec a -> Parsec a
lexe Parsec (Either Integer (Ratio Integer))
binaryCombined,
numberCombined :: Parsec (Either Integer (Ratio Integer))
numberCombined = Parsec (Either Integer (Ratio Integer))
-> Parsec (Either Integer (Ratio Integer))
forall a. Parsec a -> Parsec a
lexe Parsec (Either Integer (Ratio Integer))
numberCombined
}