X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=Text%2FParserCombinators%2FReadP.hs;h=d0743e7dbce5789398cd40cffdc192e83087ba91;hb=f8218e0dc6d2f354f89c1b4c0cc63f61844004c1;hp=b22290d9fcb4ec0b9c36b5d3244f64b76707d052;hpb=366ac66be9a6584887d9a7726d43ef83dbad799b;p=ghc-base.git diff --git a/Text/ParserCombinators/ReadP.hs b/Text/ParserCombinators/ReadP.hs index b22290d..d0743e7 100644 --- a/Text/ParserCombinators/ReadP.hs +++ b/Text/ParserCombinators/ReadP.hs @@ -1,4 +1,4 @@ -{-# OPTIONS -fglasgow-exts -fno-implicit-prelude #-} +{-# OPTIONS_GHC -fglasgow-exts -fno-implicit-prelude #-} ----------------------------------------------------------------------------- -- | -- Module : Text.ParserCombinators.ReadP @@ -20,7 +20,11 @@ module Text.ParserCombinators.ReadP ( -- * The 'ReadP' type +#ifndef __NHC__ ReadP, -- :: * -> *; instance Functor, Monad, MonadPlus +#else + ReadPN, -- :: * -> * -> *; instance Functor, Monad, MonadPlus +#endif -- * Primitive operations get, -- :: ReadP Char @@ -148,7 +152,12 @@ instance MonadPlus P where -- --------------------------------------------------------------------------- -- The ReadP type +#ifndef __NHC__ newtype ReadP a = R (forall b . (a -> P b) -> P b) +#else +#define ReadP (ReadPN b) +newtype ReadPN b a = R ((a -> P b) -> P b) +#endif -- Functor, Monad, MonadPlus @@ -200,7 +209,11 @@ pfail = R (\_ -> Fail) -- ^ Symmetric choice. R f1 +++ R f2 = R (\k -> f1 k `mplus` f2 k) +#ifndef __NHC__ (<++) :: ReadP a -> ReadP a -> ReadP a +#else +(<++) :: ReadPN a a -> ReadPN a a -> ReadPN a a +#endif -- ^ Local, exclusive, left-biased choice: If left parser -- locally produces any result at all, then right parser is -- not used. @@ -232,7 +245,11 @@ R f <++ q = discard n = get >> discard (n-1) #endif +#ifndef __NHC__ gather :: ReadP a -> ReadP (String, a) +#else +-- gather :: ReadPN (String->P b) a -> ReadPN (String->P b) (String, a) +#endif -- ^ Transforms a parser into one that does the same, but -- in addition returns the exact characters read. -- IMPORTANT NOTE: 'gather' gives a runtime error if its first argument @@ -385,7 +402,11 @@ chainl1 p op = p >>= rest rest (f x y) +++ return x +#ifndef __NHC__ manyTill :: ReadP a -> ReadP end -> ReadP [a] +#else +manyTill :: ReadPN [a] a -> ReadPN [a] end -> ReadPN [a] [a] +#endif -- ^ @manyTill p end@ parses zero or more occurrences of @p@, until @end@ -- succeeds. Returns a list of values returned by @p@. manyTill p end = scan @@ -394,7 +415,11 @@ manyTill p end = scan -- --------------------------------------------------------------------------- -- Converting between ReadP and Read +#ifndef __NHC__ readP_to_S :: ReadP a -> ReadS a +#else +readP_to_S :: ReadPN a a -> ReadS a +#endif -- ^ Converts a parser into a Haskell ReadS-style function. -- This is the main way in which you can \"run\" a 'ReadP' parser: -- the expanded type is