+% ------------------------------------------------------------------------------
+% $Id: PrelRead.lhs,v 1.17 2001/02/22 13:17:59 simonpj Exp $
%
-% (c) The AQUA Project, Glasgow University, 1994-1998
+% (c) The University of Glasgow, 1994-2000
%
\section[PrelRead]{Module @PrelRead@}
Instances of the Read class.
\begin{code}
-{-# OPTIONS -fcompiling-prelude -fno-implicit-prelude #-}
+{-# OPTIONS -fno-implicit-prelude #-}
module PrelRead where
import PrelErr ( error )
-import PrelEnum ( Enum(..) )
+import PrelEnum ( Enum(..), maxBound )
import PrelNum
import PrelReal
import PrelFloat
import PrelList
-import PrelTup
import PrelMaybe
import PrelShow -- isAlpha etc
import PrelBase
fromAsciiLab (x:y:ls) | isUpper y &&
[x,y] `elem` asciiEscTab = return ([x,y], ls)
fromAsciiLab _ = mzero
-
+
asciiEscTab = "DEL" : asciiTab
{-
-}
checkSize base f str = do
(num, res) <- f str
- -- Note: this is assumes that a Char is 8 bits long.
- if (toAnInt base num) > 255 then
+ if toAnInteger base num > toInteger (ord maxBound) then
mzero
else
case base of
16 -> return ('x':num, res)
_ -> return (num, res)
- toAnInt base xs = foldl (\ acc n -> acc*base + n) 0 (map digitToInt xs)
+ toAnInteger base = foldl (\ acc n -> acc*base + toInteger (digitToInt n)) 0
lexLitChar (c:s) = return ([c],s)
readInt :: (Integral a) => a -> (Char -> Bool) -> (Char -> Int) -> ReadS a
readInt radix isDig digToInt s = do
(ds,r) <- nonnull isDig s
- return (foldl1 (\n d -> n * radix + d) (map (fromInt . digToInt) ds), r)
+ return (foldl1 (\n d -> n * radix + d) (map (fromInteger . int2Integer . digToInt) ds), r)
{-# SPECIALISE readSigned ::
ReadS Int -> ReadS Int,