add System.Posix.Types to default nhc98 build
[haskell-directory.git] / Text / Read.hs
index 5ba1fcb..bcb2d09 100644 (file)
@@ -1,4 +1,4 @@
-{-# OPTIONS -fno-implicit-prelude #-}
+{-# OPTIONS_GHC -fno-implicit-prelude #-}
 -----------------------------------------------------------------------------
 -- |
 -- Module      :  Text.Read
@@ -9,6 +9,8 @@
 -- Stability   :  provisional
 -- Portability :  non-portable (uses Text.ParserCombinators.ReadP)
 --
+-- Converting strings to values.
+--
 -- The "Text.Read" library is the canonical library to import for
 -- 'Read'-class facilities.  For GHC only, it offers an extended and much
 -- improved 'Read' class, which constitutes a proposed alternative to the 
@@ -33,6 +35,7 @@ module Text.Read (
    module Text.ParserCombinators.ReadPrec,
    L.Lexeme(..),       
    lexP,               -- :: ReadPrec Lexeme
+   parens,             -- :: ReadPrec a -> ReadPrec a
 #endif
 #ifdef __GLASGOW_HASKELL__
    readListDefault,    -- :: Read a => ReadS [a]
@@ -54,4 +57,14 @@ import qualified Text.Read.Lex as L
 
 lexP :: ReadPrec L.Lexeme
 lexP = lift L.lex
+
+parens :: ReadPrec a -> ReadPrec a
+parens p = optional
+ where
+  optional  = p +++ mandatory
+  mandatory = do
+    L.Punc "(" <- lexP
+    x          <- reset optional
+    L.Punc ")" <- lexP
+    return x
 #endif