Movatterモバイル変換


[0]ホーム

URL:


{-# LANGUAGE Trustworthy #-}{-# LANGUAGE NoImplicitPrelude #-}------------------------------------------------------------------------------- |-- Module      :  Text.Read.Lex-- Copyright   :  (c) The University of Glasgow 2002-- License     :  BSD-style (see the file libraries/base/LICENSE)---- Maintainer  :  libraries@haskell.org-- Stability   :  provisional-- Portability :  non-portable (uses Text.ParserCombinators.ReadP)---- The cut-down Haskell lexer, used by Text.Read-------------------------------------------------------------------------------moduleText.Read.Lex-- lexing types(Lexeme(..),Number,numberToInteger,numberToFixed,numberToRational,numberToRangedRational-- lexer,lex,expect,hsLex,lexChar,readIntP,readOctP,readDecP,readHexP,isSymbolChar)whereimportText.ParserCombinators.ReadPimportGHC.BaseimportGHC.CharimportGHC.Num(Num(..),Integer)importGHC.Show(Show(..))importGHC.Unicode(GeneralCategory(..),generalCategory,isSpace,isAlpha,isAlphaNum)importGHC.Real(Rational,(%),fromIntegral,Integral,toInteger,(^),quot,even)importGHC.ListimportGHC.Enum(minBound,maxBound)importData.Maybe-- local copy to break import-cycle-- | @'guard' b@ is @'return' ()@ if @b@ is 'True',-- and 'mzero' if @b@ is 'False'.guard::(MonadPlusm)=>Bool->m()guard :: Bool -> m ()guardBoolTrue=() -> m ()forall (m :: * -> *) a. Monad m => a -> m areturn()guardBoolFalse=m ()forall (m :: * -> *) a. MonadPlus m => m amzero-- ------------------------------------------------------------------------------- Lexing types-- ^ Haskell lexemes.dataLexeme=CharChar-- ^ Character literal|StringString-- ^ String literal, with escapes interpreted|PuncString-- ^ Punctuation or reserved symbol, e.g. @(@, @::@|IdentString-- ^ Haskell identifier, e.g. @foo@, @Baz@|SymbolString-- ^ Haskell symbol, e.g. @>>@, @:%@|NumberNumber-- ^ @since 4.6.0.0|EOFderiving(Eq-- ^ @since 2.01,Show-- ^ @since 2.01)-- | @since 4.6.0.0dataNumber=MkNumberInt-- BaseDigits-- Integral part|MkDecimalDigits-- Integral part(MaybeDigits)-- Fractional part(MaybeInteger)-- Exponentderiving(Eq-- ^ @since 4.6.0.0,Show-- ^ @since 4.6.0.0)-- | @since 4.5.1.0numberToInteger::Number->MaybeIntegernumberToInteger :: Number -> Maybe IntegernumberToInteger(MkNumberIntbaseDigitsiPart)=Integer -> Maybe Integerforall a. a -> Maybe aJust(Integer -> Digits -> Integerforall a. Num a => a -> Digits -> aval(Int -> Integerforall a b. (Integral a, Num b) => a -> bfromIntegralIntbase)DigitsiPart)numberToInteger(MkDecimalDigitsiPartMaybe DigitsNothingMaybe IntegerNothing)=Integer -> Maybe Integerforall a. a -> Maybe aJust(Integer -> Digits -> Integerforall a. Num a => a -> Digits -> avalInteger10DigitsiPart)numberToIntegerNumber_=Maybe Integerforall a. Maybe aNothing-- | @since 4.7.0.0numberToFixed::Integer->Number->Maybe(Integer,Integer)numberToFixed :: Integer -> Number -> Maybe (Integer, Integer)numberToFixedInteger_(MkNumberIntbaseDigitsiPart)=(Integer, Integer) -> Maybe (Integer, Integer)forall a. a -> Maybe aJust(Integer -> Digits -> Integerforall a. Num a => a -> Digits -> aval(Int -> Integerforall a b. (Integral a, Num b) => a -> bfromIntegralIntbase)DigitsiPart,Integer0)numberToFixedInteger_(MkDecimalDigitsiPartMaybe DigitsNothingMaybe IntegerNothing)=(Integer, Integer) -> Maybe (Integer, Integer)forall a. a -> Maybe aJust(Integer -> Digits -> Integerforall a. Num a => a -> Digits -> avalInteger10DigitsiPart,Integer0)numberToFixedIntegerp(MkDecimalDigitsiPart(JustDigitsfPart)Maybe IntegerNothing)=leti :: Integeri=Integer -> Digits -> Integerforall a. Num a => a -> Digits -> avalInteger10DigitsiPartf :: Integerf=Integer -> Digits -> Integerforall a. Num a => a -> Digits -> avalInteger10(Integer -> Digits -> Digitsforall a. Integer -> [a] -> [a]integerTakeIntegerp(DigitsfPartDigits -> Digits -> Digitsforall a. [a] -> [a] -> [a]++Int -> Digitsforall a. a -> [a]repeatInt0))-- Sigh, we really want genericTake, but that's above us in-- the hierarchy, so we define our own version here (actually-- specialised to Integer)integerTake::Integer->[a]->[a]integerTake :: Integer -> [a] -> [a]integerTakeIntegern[a]_|IntegernInteger -> Integer -> Boolforall a. Ord a => a -> a -> Bool<=Integer0=[]integerTakeInteger_[]=[]integerTakeIntegern(ax:[a]xs)=axa -> [a] -> [a]forall a. a -> [a] -> [a]:Integer -> [a] -> [a]forall a. Integer -> [a] -> [a]integerTake(IntegernInteger -> Integer -> Integerforall a. Num a => a -> a -> a-Integer1)[a]xsin(Integer, Integer) -> Maybe (Integer, Integer)forall a. a -> Maybe aJust(Integeri,Integerf)numberToFixedInteger_Number_=Maybe (Integer, Integer)forall a. Maybe aNothing-- This takes a floatRange, and if the Rational would be outside of-- the floatRange then it may return Nothing. Not that it will not-- /necessarily/ return Nothing, but it is good enough to fix the-- space problems in #5688-- Ways this is conservative:-- * the floatRange is in base 2, but we pretend it is in base 10-- * we pad the floateRange a bit, just in case it is very small--   and we would otherwise hit an edge case-- * We only worry about numbers that have an exponent. If they don't--   have an exponent then the Rational won't be much larger than the--   Number, so there is no problem-- | @since 4.5.1.0numberToRangedRational::(Int,Int)->Number->MaybeRational-- Nothing = InfnumberToRangedRational :: (Int, Int) -> Number -> Maybe RationalnumberToRangedRational(Intneg,Intpos)n :: Numbern@(MkDecimalDigitsiPartMaybe DigitsmFPart(JustIntegerexp))-- if exp is out of integer bounds,-- then the number is definitely out of range|IntegerexpInteger -> Integer -> Boolforall a. Ord a => a -> a -> Bool>Int -> Integerforall a b. (Integral a, Num b) => a -> bfromIntegral(Intforall a. Bounded a => amaxBound::Int)Bool -> Bool -> Bool||IntegerexpInteger -> Integer -> Boolforall a. Ord a => a -> a -> Bool<Int -> Integerforall a b. (Integral a, Num b) => a -> bfromIntegral(Intforall a. Bounded a => aminBound::Int)=Maybe Rationalforall a. Maybe aNothing|Boolotherwise=letmFirstDigit :: Maybe IntmFirstDigit=case(Int -> Bool) -> Digits -> Digitsforall a. (a -> Bool) -> [a] -> [a]dropWhile(Int0Int -> Int -> Boolforall a. Eq a => a -> a -> Bool==)DigitsiPartofiPart' :: DigitsiPart'@(Int_:Digits_)->Int -> Maybe Intforall a. a -> Maybe aJust(Digits -> Intforall a. [a] -> IntlengthDigitsiPart')[]->caseMaybe DigitsmFPartofMaybe DigitsNothing->Maybe Intforall a. Maybe aNothingJustDigitsfPart->case(Int -> Bool) -> Digits -> (Digits, Digits)forall a. (a -> Bool) -> [a] -> ([a], [a])span(Int0Int -> Int -> Boolforall a. Eq a => a -> a -> Bool==)DigitsfPartof(Digits_,[])->Maybe Intforall a. Maybe aNothing(Digitszeroes,Digits_)->Int -> Maybe Intforall a. a -> Maybe aJust(Int -> Intforall a. Num a => a -> anegate(Digits -> Intforall a. [a] -> IntlengthDigitszeroes))incaseMaybe IntmFirstDigitofMaybe IntNothing->Rational -> Maybe Rationalforall a. a -> Maybe aJustRational0JustIntfirstDigit->letfirstDigit' :: IntfirstDigit'=IntfirstDigitInt -> Int -> Intforall a. Num a => a -> a -> a+Integer -> Intforall a. Num a => Integer -> afromIntegerIntegerexpinifIntfirstDigit'Int -> Int -> Boolforall a. Ord a => a -> a -> Bool>(IntposInt -> Int -> Intforall a. Num a => a -> a -> a+Int3)thenMaybe Rationalforall a. Maybe aNothingelseifIntfirstDigit'Int -> Int -> Boolforall a. Ord a => a -> a -> Bool<(IntnegInt -> Int -> Intforall a. Num a => a -> a -> a-Int3)thenRational -> Maybe Rationalforall a. a -> Maybe aJustRational0elseRational -> Maybe Rationalforall a. a -> Maybe aJust(Number -> RationalnumberToRationalNumbern)numberToRangedRational(Int, Int)_Numbern=Rational -> Maybe Rationalforall a. a -> Maybe aJust(Number -> RationalnumberToRationalNumbern)-- | @since 4.6.0.0numberToRational::Number->RationalnumberToRational :: Number -> RationalnumberToRational(MkNumberIntbaseDigitsiPart)=Integer -> Digits -> Integerforall a. Num a => a -> Digits -> aval(Int -> Integerforall a b. (Integral a, Num b) => a -> bfromIntegralIntbase)DigitsiPartInteger -> Integer -> Rationalforall a. Integral a => a -> a -> Ratio a%Integer1numberToRational(MkDecimalDigitsiPartMaybe DigitsmFPartMaybe IntegermExp)=leti :: Integeri=Integer -> Digits -> Integerforall a. Num a => a -> Digits -> avalInteger10DigitsiPartincase(Maybe DigitsmFPart,Maybe IntegermExp)of(Maybe DigitsNothing,Maybe IntegerNothing)->IntegeriInteger -> Integer -> Rationalforall a. Integral a => a -> a -> Ratio a%Integer1(Maybe DigitsNothing,JustIntegerexp)|IntegerexpInteger -> Integer -> Boolforall a. Ord a => a -> a -> Bool>=Integer0->(IntegeriInteger -> Integer -> Integerforall a. Num a => a -> a -> a*(Integer10Integer -> Integer -> Integerforall a b. (Num a, Integral b) => a -> b -> a^Integerexp))Integer -> Integer -> Rationalforall a. Integral a => a -> a -> Ratio a%Integer1|Boolotherwise->IntegeriInteger -> Integer -> Rationalforall a. Integral a => a -> a -> Ratio a%(Integer10Integer -> Integer -> Integerforall a b. (Num a, Integral b) => a -> b -> a^(-Integerexp))(JustDigitsfPart,Maybe IntegerNothing)->Integer -> Integer -> Digits -> RationalfracExpInteger0IntegeriDigitsfPart(JustDigitsfPart,JustIntegerexp)->Integer -> Integer -> Digits -> RationalfracExpIntegerexpIntegeriDigitsfPart-- fracExp is a bit more efficient in calculating the Rational.-- Instead of calculating the fractional part alone, then-- adding the integral part and finally multiplying with-- 10 ^ exp if an exponent was given, do it all at once.-- ------------------------------------------------------------------------------- Lexinglex::ReadPLexemelex :: ReadP Lexemelex=ReadP ()skipSpacesReadP () -> ReadP Lexeme -> ReadP Lexemeforall (m :: * -> *) a b. Monad m => m a -> m b -> m b>>ReadP LexemelexToken-- | @since 4.7.0.0expect::Lexeme->ReadP()expect :: Lexeme -> ReadP ()expectLexemelexeme=do{ReadP ()skipSpaces;Lexemething<-ReadP LexemelexToken;ifLexemethingLexeme -> Lexeme -> Boolforall a. Eq a => a -> a -> Bool==Lexemelexemethen() -> ReadP ()forall (m :: * -> *) a. Monad m => a -> m areturn()elseReadP ()forall a. ReadP apfail}hsLex::ReadPString-- ^ Haskell lexer: returns the lexed string, rather than the lexemehsLex :: ReadP StringhsLex=doReadP ()skipSpaces(Strings,Lexeme_)<-ReadP Lexeme -> ReadP (String, Lexeme)forall a. ReadP a -> ReadP (String, a)gatherReadP LexemelexTokenString -> ReadP Stringforall (m :: * -> *) a. Monad m => a -> m areturnStringslexToken::ReadPLexemelexToken :: ReadP LexemelexToken=ReadP LexemelexEOFReadP Lexeme -> ReadP Lexeme -> ReadP Lexemeforall a. ReadP a -> ReadP a -> ReadP a+++ReadP LexemelexLitCharReadP Lexeme -> ReadP Lexeme -> ReadP Lexemeforall a. ReadP a -> ReadP a -> ReadP a+++ReadP LexemelexStringReadP Lexeme -> ReadP Lexeme -> ReadP Lexemeforall a. ReadP a -> ReadP a -> ReadP a+++ReadP LexemelexPuncReadP Lexeme -> ReadP Lexeme -> ReadP Lexemeforall a. ReadP a -> ReadP a -> ReadP a+++ReadP LexemelexSymbolReadP Lexeme -> ReadP Lexeme -> ReadP Lexemeforall a. ReadP a -> ReadP a -> ReadP a+++ReadP LexemelexIdReadP Lexeme -> ReadP Lexeme -> ReadP Lexemeforall a. ReadP a -> ReadP a -> ReadP a+++ReadP LexemelexNumber-- ------------------------------------------------------------------------ End of filelexEOF::ReadPLexemelexEOF :: ReadP LexemelexEOF=doStrings<-ReadP StringlookBool -> ReadP ()forall (m :: * -> *). MonadPlus m => Bool -> m ()guard(String -> Boolforall a. [a] -> BoolnullStrings)Lexeme -> ReadP Lexemeforall (m :: * -> *) a. Monad m => a -> m areturnLexemeEOF-- ----------------------------------------------------------------------------- Single character lexemeslexPunc::ReadPLexemelexPunc :: ReadP LexemelexPunc=doCharc<-(Char -> Bool) -> ReadP CharsatisfyChar -> BoolisPuncCharLexeme -> ReadP Lexemeforall (m :: * -> *) a. Monad m => a -> m areturn(String -> LexemePunc[Charc])-- | The @special@ character class as defined in the Haskell Report.isPuncChar::Char->BoolisPuncChar :: Char -> BoolisPuncCharCharc=CharcChar -> String -> Boolforall a. Eq a => a -> [a] -> Bool`elem`String",;()[]{}`"-- ------------------------------------------------------------------------ SymbolslexSymbol::ReadPLexemelexSymbol :: ReadP LexemelexSymbol=doStrings<-(Char -> Bool) -> ReadP Stringmunch1Char -> BoolisSymbolCharifStringsString -> [String] -> Boolforall a. Eq a => a -> [a] -> Bool`elem`[String]reserved_opsthenLexeme -> ReadP Lexemeforall (m :: * -> *) a. Monad m => a -> m areturn(String -> LexemePuncStrings)-- Reserved-ops count as punctuationelseLexeme -> ReadP Lexemeforall (m :: * -> *) a. Monad m => a -> m areturn(String -> LexemeSymbolStrings)wherereserved_ops :: [String]reserved_ops=[String"..",String"::",String"=",String"\\",String"|",String"<-",String"->",String"@",String"~",String"=>"]isSymbolChar::Char->BoolisSymbolChar :: Char -> BoolisSymbolCharCharc=Bool -> Boolnot(Char -> BoolisPuncCharCharc)Bool -> Bool -> Bool&&caseChar -> GeneralCategorygeneralCategoryCharcofGeneralCategoryMathSymbol->BoolTrueGeneralCategoryCurrencySymbol->BoolTrueGeneralCategoryModifierSymbol->BoolTrueGeneralCategoryOtherSymbol->BoolTrueGeneralCategoryDashPunctuation->BoolTrueGeneralCategoryOtherPunctuation->Bool -> Boolnot(CharcChar -> String -> Boolforall a. Eq a => a -> [a] -> Bool`elem`String"'\"")GeneralCategoryConnectorPunctuation->CharcChar -> Char -> Boolforall a. Eq a => a -> a -> Bool/=Char'_'GeneralCategory_->BoolFalse-- ------------------------------------------------------------------------ identifierslexId::ReadPLexemelexId :: ReadP LexemelexId=doCharc<-(Char -> Bool) -> ReadP CharsatisfyChar -> BoolisIdsCharStrings<-(Char -> Bool) -> ReadP StringmunchChar -> BoolisIdfCharLexeme -> ReadP Lexemeforall (m :: * -> *) a. Monad m => a -> m areturn(String -> LexemeIdent(CharcChar -> ShowSforall a. a -> [a] -> [a]:Strings))where-- Identifiers can start with a '_'isIdsChar :: Char -> BoolisIdsCharCharc=Char -> BoolisAlphaCharcBool -> Bool -> Bool||CharcChar -> Char -> Boolforall a. Eq a => a -> a -> Bool==Char'_'isIdfChar :: Char -> BoolisIdfCharCharc=Char -> BoolisAlphaNumCharcBool -> Bool -> Bool||CharcChar -> String -> Boolforall a. Eq a => a -> [a] -> Bool`elem`String"_'"-- ----------------------------------------------------------------------------- Lexing character literalslexLitChar::ReadPLexemelexLitChar :: ReadP LexemelexLitChar=doChar_<-Char -> ReadP CharcharChar'\''(Charc,Boolesc)<-ReadP (Char, Bool)lexCharEBool -> ReadP ()forall (m :: * -> *). MonadPlus m => Bool -> m ()guard(BoolescBool -> Bool -> Bool||CharcChar -> Char -> Boolforall a. Eq a => a -> a -> Bool/=Char'\'')-- Eliminate '' possibilityChar_<-Char -> ReadP CharcharChar'\''Lexeme -> ReadP Lexemeforall (m :: * -> *) a. Monad m => a -> m areturn(Char -> LexemeCharCharc)lexChar::ReadPCharlexChar :: ReadP CharlexChar=do{(Charc,Bool_)<-ReadP (Char, Bool)lexCharE;ReadP ()consumeEmpties;Char -> ReadP Charforall (m :: * -> *) a. Monad m => a -> m areturnCharc}where-- Consumes the string "\&" repeatedly and greedily (will only produce one match)consumeEmpties::ReadP()consumeEmpties :: ReadP ()consumeEmpties=doStringrest<-ReadP StringlookcaseStringrestof(Char'\\':Char'&':String_)->String -> ReadP StringstringString"\\&"ReadP String -> ReadP () -> ReadP ()forall (m :: * -> *) a b. Monad m => m a -> m b -> m b>>ReadP ()consumeEmptiesString_->() -> ReadP ()forall (m :: * -> *) a. Monad m => a -> m areturn()lexCharE::ReadP(Char,Bool)-- "escaped or not"?lexCharE :: ReadP (Char, Bool)lexCharE=doCharc1<-ReadP ChargetifCharc1Char -> Char -> Boolforall a. Eq a => a -> a -> Bool==Char'\\'thendoCharc2<-ReadP CharlexEsc;(Char, Bool) -> ReadP (Char, Bool)forall (m :: * -> *) a. Monad m => a -> m areturn(Charc2,BoolTrue)elsedo(Char, Bool) -> ReadP (Char, Bool)forall (m :: * -> *) a. Monad m => a -> m areturn(Charc1,BoolFalse)wherelexEsc :: ReadP CharlexEsc=ReadP CharlexEscCharReadP Char -> ReadP Char -> ReadP Charforall a. ReadP a -> ReadP a -> ReadP a+++ReadP CharlexNumericReadP Char -> ReadP Char -> ReadP Charforall a. ReadP a -> ReadP a -> ReadP a+++ReadP CharlexCntrlCharReadP Char -> ReadP Char -> ReadP Charforall a. ReadP a -> ReadP a -> ReadP a+++ReadP CharlexAsciilexEscChar :: ReadP CharlexEscChar=doCharc<-ReadP ChargetcaseCharcofChar'a'->Char -> ReadP Charforall (m :: * -> *) a. Monad m => a -> m areturnChar'\a'Char'b'->Char -> ReadP Charforall (m :: * -> *) a. Monad m => a -> m areturnChar'\b'Char'f'->Char -> ReadP Charforall (m :: * -> *) a. Monad m => a -> m areturnChar'\f'Char'n'->Char -> ReadP Charforall (m :: * -> *) a. Monad m => a -> m areturnChar'\n'Char'r'->Char -> ReadP Charforall (m :: * -> *) a. Monad m => a -> m areturnChar'\r'Char't'->Char -> ReadP Charforall (m :: * -> *) a. Monad m => a -> m areturnChar'\t'Char'v'->Char -> ReadP Charforall (m :: * -> *) a. Monad m => a -> m areturnChar'\v'Char'\\'->Char -> ReadP Charforall (m :: * -> *) a. Monad m => a -> m areturnChar'\\'Char'\"'->Char -> ReadP Charforall (m :: * -> *) a. Monad m => a -> m areturnChar'\"'Char'\''->Char -> ReadP Charforall (m :: * -> *) a. Monad m => a -> m areturnChar'\''Char_->ReadP Charforall a. ReadP apfaillexNumeric :: ReadP CharlexNumeric=doIntbase<-ReadP IntlexBaseCharReadP Int -> ReadP Int -> ReadP Intforall a. ReadP a -> ReadP a -> ReadP a<++Int -> ReadP Intforall (m :: * -> *) a. Monad m => a -> m areturnInt10Integern<-Int -> ReadP IntegerlexIntegerIntbaseBool -> ReadP ()forall (m :: * -> *). MonadPlus m => Bool -> m ()guard(IntegernInteger -> Integer -> Boolforall a. Ord a => a -> a -> Bool<=Int -> Integerforall a. Integral a => a -> IntegertoInteger(Char -> IntordCharforall a. Bounded a => amaxBound))Char -> ReadP Charforall (m :: * -> *) a. Monad m => a -> m areturn(Int -> Charchr(Integer -> Intforall a. Num a => Integer -> afromIntegerIntegern))lexCntrlChar :: ReadP CharlexCntrlChar=doChar_<-Char -> ReadP CharcharChar'^'Charc<-ReadP ChargetcaseCharcofChar'@'->Char -> ReadP Charforall (m :: * -> *) a. Monad m => a -> m areturnChar'\^@'Char'A'->Char -> ReadP Charforall (m :: * -> *) a. Monad m => a -> m areturnChar'\^A'Char'B'->Char -> ReadP Charforall (m :: * -> *) a. Monad m => a -> m areturnChar'\^B'Char'C'->Char -> ReadP Charforall (m :: * -> *) a. Monad m => a -> m areturnChar'\^C'Char'D'->Char -> ReadP Charforall (m :: * -> *) a. Monad m => a -> m areturnChar'\^D'Char'E'->Char -> ReadP Charforall (m :: * -> *) a. Monad m => a -> m areturnChar'\^E'Char'F'->Char -> ReadP Charforall (m :: * -> *) a. Monad m => a -> m areturnChar'\^F'Char'G'->Char -> ReadP Charforall (m :: * -> *) a. Monad m => a -> m areturnChar'\^G'Char'H'->Char -> ReadP Charforall (m :: * -> *) a. Monad m => a -> m areturnChar'\^H'Char'I'->Char -> ReadP Charforall (m :: * -> *) a. Monad m => a -> m areturnChar'\^I'Char'J'->Char -> ReadP Charforall (m :: * -> *) a. Monad m => a -> m areturnChar'\^J'Char'K'->Char -> ReadP Charforall (m :: * -> *) a. Monad m => a -> m areturnChar'\^K'Char'L'->Char -> ReadP Charforall (m :: * -> *) a. Monad m => a -> m areturnChar'\^L'Char'M'->Char -> ReadP Charforall (m :: * -> *) a. Monad m => a -> m areturnChar'\^M'Char'N'->Char -> ReadP Charforall (m :: * -> *) a. Monad m => a -> m areturnChar'\^N'Char'O'->Char -> ReadP Charforall (m :: * -> *) a. Monad m => a -> m areturnChar'\^O'Char'P'->Char -> ReadP Charforall (m :: * -> *) a. Monad m => a -> m areturnChar'\^P'Char'Q'->Char -> ReadP Charforall (m :: * -> *) a. Monad m => a -> m areturnChar'\^Q'Char'R'->Char -> ReadP Charforall (m :: * -> *) a. Monad m => a -> m areturnChar'\^R'Char'S'->Char -> ReadP Charforall (m :: * -> *) a. Monad m => a -> m areturnChar'\^S'Char'T'->Char -> ReadP Charforall (m :: * -> *) a. Monad m => a -> m areturnChar'\^T'Char'U'->Char -> ReadP Charforall (m :: * -> *) a. Monad m => a -> m areturnChar'\^U'Char'V'->Char -> ReadP Charforall (m :: * -> *) a. Monad m => a -> m areturnChar'\^V'Char'W'->Char -> ReadP Charforall (m :: * -> *) a. Monad m => a -> m areturnChar'\^W'Char'X'->Char -> ReadP Charforall (m :: * -> *) a. Monad m => a -> m areturnChar'\^X'Char'Y'->Char -> ReadP Charforall (m :: * -> *) a. Monad m => a -> m areturnChar'\^Y'Char'Z'->Char -> ReadP Charforall (m :: * -> *) a. Monad m => a -> m areturnChar'\^Z'Char'['->Char -> ReadP Charforall (m :: * -> *) a. Monad m => a -> m areturnChar'\^['Char'\\'->Char -> ReadP Charforall (m :: * -> *) a. Monad m => a -> m areturnChar'\^\'Char']'->Char -> ReadP Charforall (m :: * -> *) a. Monad m => a -> m areturnChar'\^]'Char'^'->Char -> ReadP Charforall (m :: * -> *) a. Monad m => a -> m areturnChar'\^^'Char'_'->Char -> ReadP Charforall (m :: * -> *) a. Monad m => a -> m areturnChar'\^_'Char_->ReadP Charforall a. ReadP apfaillexAscii :: ReadP CharlexAscii=do[ReadP Char] -> ReadP Charforall a. [ReadP a] -> ReadP achoice[(String -> ReadP StringstringString"SOH"ReadP String -> ReadP Char -> ReadP Charforall (m :: * -> *) a b. Monad m => m a -> m b -> m b>>Char -> ReadP Charforall (m :: * -> *) a. Monad m => a -> m areturnChar'\SOH')ReadP Char -> ReadP Char -> ReadP Charforall a. ReadP a -> ReadP a -> ReadP a<++(String -> ReadP StringstringString"SO"ReadP String -> ReadP Char -> ReadP Charforall (m :: * -> *) a b. Monad m => m a -> m b -> m b>>Char -> ReadP Charforall (m :: * -> *) a. Monad m => a -> m areturnChar'\SO')-- \SO and \SOH need maximal-munch treatment-- See the Haskell report Sect 2.6,String -> ReadP StringstringString"NUL"ReadP String -> ReadP Char -> ReadP Charforall (m :: * -> *) a b. Monad m => m a -> m b -> m b>>Char -> ReadP Charforall (m :: * -> *) a. Monad m => a -> m areturnChar'\NUL',String -> ReadP StringstringString"STX"ReadP String -> ReadP Char -> ReadP Charforall (m :: * -> *) a b. Monad m => m a -> m b -> m b>>Char -> ReadP Charforall (m :: * -> *) a. Monad m => a -> m areturnChar'\STX',String -> ReadP StringstringString"ETX"ReadP String -> ReadP Char -> ReadP Charforall (m :: * -> *) a b. Monad m => m a -> m b -> m b>>Char -> ReadP Charforall (m :: * -> *) a. Monad m => a -> m areturnChar'\ETX',String -> ReadP StringstringString"EOT"ReadP String -> ReadP Char -> ReadP Charforall (m :: * -> *) a b. Monad m => m a -> m b -> m b>>Char -> ReadP Charforall (m :: * -> *) a. Monad m => a -> m areturnChar'\EOT',String -> ReadP StringstringString"ENQ"ReadP String -> ReadP Char -> ReadP Charforall (m :: * -> *) a b. Monad m => m a -> m b -> m b>>Char -> ReadP Charforall (m :: * -> *) a. Monad m => a -> m areturnChar'\ENQ',String -> ReadP StringstringString"ACK"ReadP String -> ReadP Char -> ReadP Charforall (m :: * -> *) a b. Monad m => m a -> m b -> m b>>Char -> ReadP Charforall (m :: * -> *) a. Monad m => a -> m areturnChar'\ACK',String -> ReadP StringstringString"BEL"ReadP String -> ReadP Char -> ReadP Charforall (m :: * -> *) a b. Monad m => m a -> m b -> m b>>Char -> ReadP Charforall (m :: * -> *) a. Monad m => a -> m areturnChar'\BEL',String -> ReadP StringstringString"BS"ReadP String -> ReadP Char -> ReadP Charforall (m :: * -> *) a b. Monad m => m a -> m b -> m b>>Char -> ReadP Charforall (m :: * -> *) a. Monad m => a -> m areturnChar'\BS',String -> ReadP StringstringString"HT"ReadP String -> ReadP Char -> ReadP Charforall (m :: * -> *) a b. Monad m => m a -> m b -> m b>>Char -> ReadP Charforall (m :: * -> *) a. Monad m => a -> m areturnChar'\HT',String -> ReadP StringstringString"LF"ReadP String -> ReadP Char -> ReadP Charforall (m :: * -> *) a b. Monad m => m a -> m b -> m b>>Char -> ReadP Charforall (m :: * -> *) a. Monad m => a -> m areturnChar'\LF',String -> ReadP StringstringString"VT"ReadP String -> ReadP Char -> ReadP Charforall (m :: * -> *) a b. Monad m => m a -> m b -> m b>>Char -> ReadP Charforall (m :: * -> *) a. Monad m => a -> m areturnChar'\VT',String -> ReadP StringstringString"FF"ReadP String -> ReadP Char -> ReadP Charforall (m :: * -> *) a b. Monad m => m a -> m b -> m b>>Char -> ReadP Charforall (m :: * -> *) a. Monad m => a -> m areturnChar'\FF',String -> ReadP StringstringString"CR"ReadP String -> ReadP Char -> ReadP Charforall (m :: * -> *) a b. Monad m => m a -> m b -> m b>>Char -> ReadP Charforall (m :: * -> *) a. Monad m => a -> m areturnChar'\CR',String -> ReadP StringstringString"SI"ReadP String -> ReadP Char -> ReadP Charforall (m :: * -> *) a b. Monad m => m a -> m b -> m b>>Char -> ReadP Charforall (m :: * -> *) a. Monad m => a -> m areturnChar'\SI',String -> ReadP StringstringString"DLE"ReadP String -> ReadP Char -> ReadP Charforall (m :: * -> *) a b. Monad m => m a -> m b -> m b>>Char -> ReadP Charforall (m :: * -> *) a. Monad m => a -> m areturnChar'\DLE',String -> ReadP StringstringString"DC1"ReadP String -> ReadP Char -> ReadP Charforall (m :: * -> *) a b. Monad m => m a -> m b -> m b>>Char -> ReadP Charforall (m :: * -> *) a. Monad m => a -> m areturnChar'\DC1',String -> ReadP StringstringString"DC2"ReadP String -> ReadP Char -> ReadP Charforall (m :: * -> *) a b. Monad m => m a -> m b -> m b>>Char -> ReadP Charforall (m :: * -> *) a. Monad m => a -> m areturnChar'\DC2',String -> ReadP StringstringString"DC3"ReadP String -> ReadP Char -> ReadP Charforall (m :: * -> *) a b. Monad m => m a -> m b -> m b>>Char -> ReadP Charforall (m :: * -> *) a. Monad m => a -> m areturnChar'\DC3',String -> ReadP StringstringString"DC4"ReadP String -> ReadP Char -> ReadP Charforall (m :: * -> *) a b. Monad m => m a -> m b -> m b>>Char -> ReadP Charforall (m :: * -> *) a. Monad m => a -> m areturnChar'\DC4',String -> ReadP StringstringString"NAK"ReadP String -> ReadP Char -> ReadP Charforall (m :: * -> *) a b. Monad m => m a -> m b -> m b>>Char -> ReadP Charforall (m :: * -> *) a. Monad m => a -> m areturnChar'\NAK',String -> ReadP StringstringString"SYN"ReadP String -> ReadP Char -> ReadP Charforall (m :: * -> *) a b. Monad m => m a -> m b -> m b>>Char -> ReadP Charforall (m :: * -> *) a. Monad m => a -> m areturnChar'\SYN',String -> ReadP StringstringString"ETB"ReadP String -> ReadP Char -> ReadP Charforall (m :: * -> *) a b. Monad m => m a -> m b -> m b>>Char -> ReadP Charforall (m :: * -> *) a. Monad m => a -> m areturnChar'\ETB',String -> ReadP StringstringString"CAN"ReadP String -> ReadP Char -> ReadP Charforall (m :: * -> *) a b. Monad m => m a -> m b -> m b>>Char -> ReadP Charforall (m :: * -> *) a. Monad m => a -> m areturnChar'\CAN',String -> ReadP StringstringString"EM"ReadP String -> ReadP Char -> ReadP Charforall (m :: * -> *) a b. Monad m => m a -> m b -> m b>>Char -> ReadP Charforall (m :: * -> *) a. Monad m => a -> m areturnChar'\EM',String -> ReadP StringstringString"SUB"ReadP String -> ReadP Char -> ReadP Charforall (m :: * -> *) a b. Monad m => m a -> m b -> m b>>Char -> ReadP Charforall (m :: * -> *) a. Monad m => a -> m areturnChar'\SUB',String -> ReadP StringstringString"ESC"ReadP String -> ReadP Char -> ReadP Charforall (m :: * -> *) a b. Monad m => m a -> m b -> m b>>Char -> ReadP Charforall (m :: * -> *) a. Monad m => a -> m areturnChar'\ESC',String -> ReadP StringstringString"FS"ReadP String -> ReadP Char -> ReadP Charforall (m :: * -> *) a b. Monad m => m a -> m b -> m b>>Char -> ReadP Charforall (m :: * -> *) a. Monad m => a -> m areturnChar'\FS',String -> ReadP StringstringString"GS"ReadP String -> ReadP Char -> ReadP Charforall (m :: * -> *) a b. Monad m => m a -> m b -> m b>>Char -> ReadP Charforall (m :: * -> *) a. Monad m => a -> m areturnChar'\GS',String -> ReadP StringstringString"RS"ReadP String -> ReadP Char -> ReadP Charforall (m :: * -> *) a b. Monad m => m a -> m b -> m b>>Char -> ReadP Charforall (m :: * -> *) a. Monad m => a -> m areturnChar'\RS',String -> ReadP StringstringString"US"ReadP String -> ReadP Char -> ReadP Charforall (m :: * -> *) a b. Monad m => m a -> m b -> m b>>Char -> ReadP Charforall (m :: * -> *) a. Monad m => a -> m areturnChar'\US',String -> ReadP StringstringString"SP"ReadP String -> ReadP Char -> ReadP Charforall (m :: * -> *) a b. Monad m => m a -> m b -> m b>>Char -> ReadP Charforall (m :: * -> *) a. Monad m => a -> m areturnChar'\SP',String -> ReadP StringstringString"DEL"ReadP String -> ReadP Char -> ReadP Charforall (m :: * -> *) a b. Monad m => m a -> m b -> m b>>Char -> ReadP Charforall (m :: * -> *) a. Monad m => a -> m areturnChar'\DEL']-- ----------------------------------------------------------------------------- string literallexString::ReadPLexemelexString :: ReadP LexemelexString=doChar_<-Char -> ReadP CharcharChar'"'ShowS -> ReadP LexemebodyShowSforall a. a -> aidwherebody :: ShowS -> ReadP LexemebodyShowSf=do(Charc,Boolesc)<-ReadP (Char, Bool)lexStrItemifCharcChar -> Char -> Boolforall a. Eq a => a -> a -> Bool/=Char'"'Bool -> Bool -> Bool||BoolescthenShowS -> ReadP Lexemebody(ShowSfShowS -> ShowS -> ShowSforall b c a. (b -> c) -> (a -> b) -> a -> c.(CharcChar -> ShowSforall a. a -> [a] -> [a]:))elselets :: Strings=ShowSfString""inLexeme -> ReadP Lexemeforall (m :: * -> *) a. Monad m => a -> m areturn(String -> LexemeStringStrings)lexStrItem :: ReadP (Char, Bool)lexStrItem=(ReadP ()lexEmptyReadP () -> ReadP (Char, Bool) -> ReadP (Char, Bool)forall (m :: * -> *) a b. Monad m => m a -> m b -> m b>>ReadP (Char, Bool)lexStrItem)ReadP (Char, Bool) -> ReadP (Char, Bool) -> ReadP (Char, Bool)forall a. ReadP a -> ReadP a -> ReadP a+++ReadP (Char, Bool)lexCharElexEmpty :: ReadP ()lexEmpty=doChar_<-Char -> ReadP CharcharChar'\\'Charc<-ReadP ChargetcaseCharcofChar'&'->do() -> ReadP ()forall (m :: * -> *) a. Monad m => a -> m areturn()Char_|Char -> BoolisSpaceCharc->doReadP ()skipSpaces;Char_<-Char -> ReadP CharcharChar'\\';() -> ReadP ()forall (m :: * -> *) a. Monad m => a -> m areturn()Char_->doReadP ()forall a. ReadP apfail-- -----------------------------------------------------------------------------  Lexing numberstypeBase=InttypeDigits=[Int]lexNumber::ReadPLexemelexNumber :: ReadP LexemelexNumber=ReadP LexemelexHexOctReadP Lexeme -> ReadP Lexeme -> ReadP Lexemeforall a. ReadP a -> ReadP a -> ReadP a<++-- First try for hex or octal 0x, 0o etc-- If that fails, try for a decimal numberReadP LexemelexDecNumber-- Start with ordinary digitslexHexOct::ReadPLexemelexHexOct :: ReadP LexemelexHexOct=doChar_<-Char -> ReadP CharcharChar'0'Intbase<-ReadP IntlexBaseCharDigitsdigits<-Int -> ReadP DigitslexDigitsIntbaseLexeme -> ReadP Lexemeforall (m :: * -> *) a. Monad m => a -> m areturn(Number -> LexemeNumber(Int -> Digits -> NumberMkNumberIntbaseDigitsdigits))lexBaseChar::ReadPInt-- Lex a single character indicating the base; fail if not therelexBaseChar :: ReadP IntlexBaseChar=do{Charc<-ReadP Charget;caseCharcofChar'o'->Int -> ReadP Intforall (m :: * -> *) a. Monad m => a -> m areturnInt8Char'O'->Int -> ReadP Intforall (m :: * -> *) a. Monad m => a -> m areturnInt8Char'x'->Int -> ReadP Intforall (m :: * -> *) a. Monad m => a -> m areturnInt16Char'X'->Int -> ReadP Intforall (m :: * -> *) a. Monad m => a -> m areturnInt16Char_->ReadP Intforall a. ReadP apfail}lexDecNumber::ReadPLexemelexDecNumber :: ReadP LexemelexDecNumber=doDigitsxs<-Int -> ReadP DigitslexDigitsInt10Maybe DigitsmFrac<-ReadP (Maybe Digits)lexFracReadP (Maybe Digits)-> ReadP (Maybe Digits) -> ReadP (Maybe Digits)forall a. ReadP a -> ReadP a -> ReadP a<++Maybe Digits -> ReadP (Maybe Digits)forall (m :: * -> *) a. Monad m => a -> m areturnMaybe Digitsforall a. Maybe aNothingMaybe IntegermExp<-ReadP (Maybe Integer)lexExpReadP (Maybe Integer)-> ReadP (Maybe Integer) -> ReadP (Maybe Integer)forall a. ReadP a -> ReadP a -> ReadP a<++Maybe Integer -> ReadP (Maybe Integer)forall (m :: * -> *) a. Monad m => a -> m areturnMaybe Integerforall a. Maybe aNothingLexeme -> ReadP Lexemeforall (m :: * -> *) a. Monad m => a -> m areturn(Number -> LexemeNumber(Digits -> Maybe Digits -> Maybe Integer -> NumberMkDecimalDigitsxsMaybe DigitsmFracMaybe IntegermExp))lexFrac::ReadP(MaybeDigits)-- Read the fractional part; fail if it doesn't-- start ".d" where d is a digitlexFrac :: ReadP (Maybe Digits)lexFrac=doChar_<-Char -> ReadP CharcharChar'.'Digitsfraction<-Int -> ReadP DigitslexDigitsInt10Maybe Digits -> ReadP (Maybe Digits)forall (m :: * -> *) a. Monad m => a -> m areturn(Digits -> Maybe Digitsforall a. a -> Maybe aJustDigitsfraction)lexExp::ReadP(MaybeInteger)lexExp :: ReadP (Maybe Integer)lexExp=doChar_<-Char -> ReadP CharcharChar'e'ReadP Char -> ReadP Char -> ReadP Charforall a. ReadP a -> ReadP a -> ReadP a+++Char -> ReadP CharcharChar'E'Integerexp<-ReadP IntegersignedExpReadP Integer -> ReadP Integer -> ReadP Integerforall a. ReadP a -> ReadP a -> ReadP a+++Int -> ReadP IntegerlexIntegerInt10Maybe Integer -> ReadP (Maybe Integer)forall (m :: * -> *) a. Monad m => a -> m areturn(Integer -> Maybe Integerforall a. a -> Maybe aJustIntegerexp)wheresignedExp :: ReadP IntegersignedExp=doCharc<-Char -> ReadP CharcharChar'-'ReadP Char -> ReadP Char -> ReadP Charforall a. ReadP a -> ReadP a -> ReadP a+++Char -> ReadP CharcharChar'+'Integern<-Int -> ReadP IntegerlexIntegerInt10Integer -> ReadP Integerforall (m :: * -> *) a. Monad m => a -> m areturn(ifCharcChar -> Char -> Boolforall a. Eq a => a -> a -> Bool==Char'-'then-IntegernelseIntegern)lexDigits::Int->ReadPDigits-- Lex a non-empty sequence of digits in specified baselexDigits :: Int -> ReadP DigitslexDigitsIntbase=doStrings<-ReadP StringlookDigitsxs<-String -> (Digits -> Digits) -> ReadP Digitsforall a. String -> (Digits -> a) -> ReadP ascanStringsDigits -> Digitsforall a. a -> aidBool -> ReadP ()forall (m :: * -> *). MonadPlus m => Bool -> m ()guard(Bool -> Boolnot(Digits -> Boolforall a. [a] -> BoolnullDigitsxs))Digits -> ReadP Digitsforall (m :: * -> *) a. Monad m => a -> m areturnDigitsxswherescan :: String -> (Digits -> a) -> ReadP ascan(Charc:Stringcs)Digits -> af=caseInt -> Char -> Maybe Intforall a. (Eq a, Num a) => a -> Char -> Maybe IntvalDigIntbaseCharcofJustIntn->doChar_<-ReadP Charget;String -> (Digits -> a) -> ReadP ascanStringcs(Digits -> af(Digits -> a) -> (Digits -> Digits) -> Digits -> aforall b c a. (b -> c) -> (a -> b) -> a -> c.(IntnInt -> Digits -> Digitsforall a. a -> [a] -> [a]:))Maybe IntNothing->doa -> ReadP aforall (m :: * -> *) a. Monad m => a -> m areturn(Digits -> af[])scan[]Digits -> af=doa -> ReadP aforall (m :: * -> *) a. Monad m => a -> m areturn(Digits -> af[])lexInteger::Base->ReadPIntegerlexInteger :: Int -> ReadP IntegerlexIntegerIntbase=doDigitsxs<-Int -> ReadP DigitslexDigitsIntbaseInteger -> ReadP Integerforall (m :: * -> *) a. Monad m => a -> m areturn(Integer -> Digits -> Integerforall a. Num a => a -> Digits -> aval(Int -> Integerforall a b. (Integral a, Num b) => a -> bfromIntegralIntbase)Digitsxs)val::Numa=>a->Digits->aval :: a -> Digits -> aval=a -> Digits -> aforall a d. (Num a, Integral d) => a -> [d] -> avalSimple{-# RULES"val/Integer"val=valInteger#-}{-# INLINE[1]val#-}-- The following algorithm is only linear for types whose Num operations-- are in constant time.valSimple::(Numa,Integrald)=>a->[d]->avalSimple :: a -> [d] -> avalSimpleabase=a -> [d] -> aforall a. Integral a => a -> [a] -> agoa0wherego :: a -> [a] -> agoar[]=argoar(ad:[a]ds)=ar'a -> a -> a`seq`a -> [a] -> agoar'[a]dswherer' :: ar'=ara -> a -> aforall a. Num a => a -> a -> a*abasea -> a -> aforall a. Num a => a -> a -> a+a -> aforall a b. (Integral a, Num b) => a -> bfromIntegralad{-# INLINEvalSimple#-}-- A sub-quadratic algorithm for Integer. Pairs of adjacent radix b-- digits are combined into a single radix b^2 digit. This process is-- repeated until we are left with a single digit. This algorithm-- performs well only on large inputs, so we use the simple algorithm-- for smaller inputs.valInteger::Integer->Digits->IntegervalInteger :: Integer -> Digits -> IntegervalIntegerIntegerb0Digitsds0=Integer -> Int -> [Integer] -> Integerforall t a. (Integral t, Integral a) => t -> a -> [t] -> tgoIntegerb0(Digits -> Intforall a. [a] -> IntlengthDigitsds0)([Integer] -> Integer) -> [Integer] -> Integerforall a b. (a -> b) -> a -> b$(Int -> Integer) -> Digits -> [Integer]forall a b. (a -> b) -> [a] -> [b]mapInt -> Integerforall a b. (Integral a, Num b) => a -> bfromIntegralDigitsds0wherego :: t -> a -> [t] -> tgot_a_[]=t0got_a_[td]=tdgotbal[t]ds|ala -> a -> Boolforall a. Ord a => a -> a -> Bool>a40=tb't -> t -> t`seq`t -> a -> [t] -> tgotb'al'(t -> [t] -> [t]forall a. Num a => a -> [a] -> [a]combinetb[t]ds')|Boolotherwise=t -> [t] -> tforall a d. (Num a, Integral d) => a -> [d] -> avalSimpletb[t]dswhere-- ensure that we have an even number of digits-- before we call combine:ds' :: [t]ds'=ifa -> Boolforall a. Integral a => a -> Boolevenalthen[t]dselset0t -> [t] -> [t]forall a. a -> [a] -> [a]:[t]dsb' :: tb'=tbt -> t -> tforall a. Num a => a -> a -> a*tbl' :: al'=(ala -> a -> aforall a. Num a => a -> a -> a+a1)a -> a -> aforall a. Integral a => a -> a -> a`quot`a2combine :: a -> [a] -> [a]combineab(ad1:ad2:[a]ds)=ada -> [a] -> [a]`seq`(ada -> [a] -> [a]forall a. a -> [a] -> [a]:a -> [a] -> [a]combineab[a]ds)whered :: ad=ad1a -> a -> aforall a. Num a => a -> a -> a*aba -> a -> aforall a. Num a => a -> a -> a+ad2combinea_[]=[]combinea_[a_]=String -> [a]forall a. String -> aerrorWithoutStackTraceString"this should not happen"-- Calculate a Rational from the exponent [of 10 to multiply with],-- the integral part of the mantissa and the digits of the fractional-- part. Leaving the calculation of the power of 10 until the end,-- when we know the effective exponent, saves multiplications.-- More importantly, this way we need at most one gcd instead of three.---- frac was never used with anything but Integer and base 10, so-- those are hardcoded now (trivial to change if necessary).fracExp::Integer->Integer->Digits->RationalfracExp :: Integer -> Integer -> Digits -> RationalfracExpIntegerexpIntegermant[]|IntegerexpInteger -> Integer -> Boolforall a. Ord a => a -> a -> Bool<Integer0=IntegermantInteger -> Integer -> Rationalforall a. Integral a => a -> a -> Ratio a%(Integer10Integer -> Integer -> Integerforall a b. (Num a, Integral b) => a -> b -> a^(-Integerexp))|Boolotherwise=Integer -> Rationalforall a. Num a => Integer -> afromInteger(IntegermantInteger -> Integer -> Integerforall a. Num a => a -> a -> a*Integer10Integer -> Integer -> Integerforall a b. (Num a, Integral b) => a -> b -> a^Integerexp)fracExpIntegerexpIntegermant(Intd:Digitsds)=Integerexp'Integer -> Rational -> Rational`seq`Integermant'Integer -> Rational -> Rational`seq`Integer -> Integer -> Digits -> RationalfracExpIntegerexp'Integermant'Digitsdswhereexp' :: Integerexp'=IntegerexpInteger -> Integer -> Integerforall a. Num a => a -> a -> a-Integer1mant' :: Integermant'=IntegermantInteger -> Integer -> Integerforall a. Num a => a -> a -> a*Integer10Integer -> Integer -> Integerforall a. Num a => a -> a -> a+Int -> Integerforall a b. (Integral a, Num b) => a -> bfromIntegralIntdvalDig::(Eqa,Numa)=>a->Char->MaybeIntvalDig :: a -> Char -> Maybe IntvalDiga8Charc|Char'0'Char -> Char -> Boolforall a. Ord a => a -> a -> Bool<=CharcBool -> Bool -> Bool&&CharcChar -> Char -> Boolforall a. Ord a => a -> a -> Bool<=Char'7'=Int -> Maybe Intforall a. a -> Maybe aJust(Char -> IntordCharcInt -> Int -> Intforall a. Num a => a -> a -> a-Char -> IntordChar'0')|Boolotherwise=Maybe Intforall a. Maybe aNothingvalDiga10Charc=Char -> Maybe IntvalDecDigCharcvalDiga16Charc|Char'0'Char -> Char -> Boolforall a. Ord a => a -> a -> Bool<=CharcBool -> Bool -> Bool&&CharcChar -> Char -> Boolforall a. Ord a => a -> a -> Bool<=Char'9'=Int -> Maybe Intforall a. a -> Maybe aJust(Char -> IntordCharcInt -> Int -> Intforall a. Num a => a -> a -> a-Char -> IntordChar'0')|Char'a'Char -> Char -> Boolforall a. Ord a => a -> a -> Bool<=CharcBool -> Bool -> Bool&&CharcChar -> Char -> Boolforall a. Ord a => a -> a -> Bool<=Char'f'=Int -> Maybe Intforall a. a -> Maybe aJust(Char -> IntordCharcInt -> Int -> Intforall a. Num a => a -> a -> a-Char -> IntordChar'a'Int -> Int -> Intforall a. Num a => a -> a -> a+Int10)|Char'A'Char -> Char -> Boolforall a. Ord a => a -> a -> Bool<=CharcBool -> Bool -> Bool&&CharcChar -> Char -> Boolforall a. Ord a => a -> a -> Bool<=Char'F'=Int -> Maybe Intforall a. a -> Maybe aJust(Char -> IntordCharcInt -> Int -> Intforall a. Num a => a -> a -> a-Char -> IntordChar'A'Int -> Int -> Intforall a. Num a => a -> a -> a+Int10)|Boolotherwise=Maybe Intforall a. Maybe aNothingvalDiga_Char_=String -> Maybe Intforall a. String -> aerrorWithoutStackTraceString"valDig: Bad base"valDecDig::Char->MaybeIntvalDecDig :: Char -> Maybe IntvalDecDigCharc|Char'0'Char -> Char -> Boolforall a. Ord a => a -> a -> Bool<=CharcBool -> Bool -> Bool&&CharcChar -> Char -> Boolforall a. Ord a => a -> a -> Bool<=Char'9'=Int -> Maybe Intforall a. a -> Maybe aJust(Char -> IntordCharcInt -> Int -> Intforall a. Num a => a -> a -> a-Char -> IntordChar'0')|Boolotherwise=Maybe Intforall a. Maybe aNothing-- ------------------------------------------------------------------------ other numeric lexing functionsreadIntP::Numa=>a->(Char->Bool)->(Char->Int)->ReadPareadIntP :: a -> (Char -> Bool) -> (Char -> Int) -> ReadP areadIntPabaseChar -> BoolisDigitChar -> IntvalDigit=doStrings<-(Char -> Bool) -> ReadP Stringmunch1Char -> BoolisDigita -> ReadP aforall (m :: * -> *) a. Monad m => a -> m areturn(a -> Digits -> aforall a. Num a => a -> Digits -> avalabase((Char -> Int) -> String -> Digitsforall a b. (a -> b) -> [a] -> [b]mapChar -> IntvalDigitStrings)){-# SPECIALISEreadIntP::Integer->(Char->Bool)->(Char->Int)->ReadPInteger#-}readIntP'::(Eqa,Numa)=>a->ReadPareadIntP' :: a -> ReadP areadIntP'abase=a -> (Char -> Bool) -> (Char -> Int) -> ReadP aforall a. Num a => a -> (Char -> Bool) -> (Char -> Int) -> ReadP areadIntPabaseChar -> BoolisDigitChar -> IntvalDigitwhereisDigit :: Char -> BoolisDigitCharc=Bool -> (Int -> Bool) -> Maybe Int -> Boolforall b a. b -> (a -> b) -> Maybe a -> bmaybeBoolFalse(Bool -> Int -> Boolforall a b. a -> b -> aconstBoolTrue)(a -> Char -> Maybe Intforall a. (Eq a, Num a) => a -> Char -> Maybe IntvalDigabaseCharc)valDigit :: Char -> IntvalDigitCharc=Int -> (Int -> Int) -> Maybe Int -> Intforall b a. b -> (a -> b) -> Maybe a -> bmaybeInt0Int -> Intforall a. a -> aid(a -> Char -> Maybe Intforall a. (Eq a, Num a) => a -> Char -> Maybe IntvalDigabaseCharc){-# SPECIALISEreadIntP'::Integer->ReadPInteger#-}readOctP,readDecP,readHexP::(Eqa,Numa)=>ReadPareadOctP :: ReadP areadOctP=a -> ReadP aforall a. (Eq a, Num a) => a -> ReadP areadIntP'a8readDecP :: ReadP areadDecP=a -> ReadP aforall a. (Eq a, Num a) => a -> ReadP areadIntP'a10readHexP :: ReadP areadHexP=a -> ReadP aforall a. (Eq a, Num a) => a -> ReadP areadIntP'a16{-# SPECIALISEreadOctP::ReadPInteger#-}{-# SPECIALISEreadDecP::ReadPInteger#-}{-# SPECIALISEreadHexP::ReadPInteger#-}

[8]ページ先頭

©2009-2025 Movatter.jp