-{-# OPTIONS -fno-implicit-prelude #-}
+{-# OPTIONS_GHC -fno-implicit-prelude #-}
-----------------------------------------------------------------------------
-- |
-- Module : Text.Read
-- 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
module Text.ParserCombinators.ReadPrec,
L.Lexeme(..),
lexP, -- :: ReadPrec Lexeme
+ parens, -- :: ReadPrec a -> ReadPrec a
#endif
#ifdef __GLASGOW_HASKELL__
readListDefault, -- :: Read a => ReadS [a]
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