portability fixes, plus marking these as non-portable (uses forall).
--
-- Maintainer : libraries@haskell.org
-- Stability : provisional
--- Portability : portable
+-- Portability : non-portable (local universal quantification)
--
-- This is a library of parser combinators, originally written by Koen Claessen.
-- It parses all alternatives in parallel, so it never keeps hold of
where
import Control.Monad( MonadPlus(..) )
+#ifdef __GLASGOW_HASKELL__
import GHC.Show( isSpace )
import GHC.Base
+#else
+import Data.Char( isSpace )
+#endif
infixr 5 +++, <++
+#ifdef __GLASGOW_HASKELL__
-- We define a local version of ReadS here,
-- because its "real" definition site is in GHC.Read
type ReadS a = String -> [(a,String)]
+#endif
-- ---------------------------------------------------------------------------
-- The P type
-- ^ Local, exclusive, left-biased choice: If left parser
-- locally produces any result at all, then right parser is
-- not used.
+#ifdef __GLASGOW_HASKELL__
R f <++ q =
do s <- look
probe (f return) s 0#
discard 0# = return ()
discard n = get >> discard (n-#1#)
+#else
+R f <++ q =
+ do s <- look
+ probe (f return) s 0
+ where
+ probe (Get f) (c:s) n = probe (f c) s (n+1)
+ probe (Look f) s n = probe (f s) s n
+ probe p@(Result _ _) _ n = discard n >> R (p >>=)
+ probe (Final r) _ _ = R (Final r >>=)
+ probe _ _ _ = q
+
+ discard 0 = return ()
+ discard n = get >> discard (n-1)
+#endif
gather :: ReadP a -> ReadP (String, a)
-- ^ Transforms a parser into one that does the same, but
--
-- Maintainer : libraries@haskell.org
-- Stability : provisional
--- Portability : portable
+-- Portability : non-portable (uses Text.ParserCombinators.ReadP)
--
-- This library defines parser combinators for precedence parsing.
)
import Control.Monad( MonadPlus(..) )
+#ifdef __GLASGOW_HASKELL__
import GHC.Num( Num(..) )
import GHC.Base
+#endif
-- ---------------------------------------------------------------------------
-- The readPrec type
-- ---------------------------------------------------------------------------
-- Converting between ReadPrec and Read
+#ifdef __GLASGOW_HASKELL__
-- We define a local version of ReadS here,
-- because its "real" definition site is in GHC.Read
type ReadS a = String -> [(a,String)]
+#endif
readPrec_to_P :: ReadPrec a -> (Int -> ReadP a)
readPrec_to_P (P f) = f
--
-- Maintainer : libraries@haskell.org
-- Stability : provisional
--- Portability : portable
+-- Portability : non-portable (uses Text.ParserCombinators.ReadP)
--
-- The cut-down Haskell lexer, used by Text.Read
--
import Text.ParserCombinators.ReadP
+#ifdef __GLASGOW_HASKELL__
import GHC.Base
import GHC.Num( Num(..), Integer )
import GHC.Show( Show(.. ), isSpace, isAlpha, isAlphaNum )
toInteger, (^), (^^), infinity, notANumber )
import GHC.List
import GHC.Enum( maxBound )
+#else
+import Prelude hiding ( lex )
+import Data.Char( chr, ord, isSpace, isAlpha, isAlphaNum )
+import Data.Ratio( Ratio, (%) )
+#endif
+#ifdef __HUGS__
+import Hugs.Prelude( Ratio(..) )
+#endif
import Data.Maybe
import Control.Monad
isIdsChar c = isAlpha c || c == '_'
isIdfChar c = isAlphaNum c || c `elem` "_'"
+#ifndef __GLASGOW_HASKELL__
+infinity, notANumber :: Rational
+infinity = 1 :% 0
+notANumber = 0 :% 0
+#endif
+
-- ---------------------------------------------------------------------------
-- Lexing character literals