From: ross Date: Fri, 21 Oct 2005 10:24:58 +0000 (+0000) Subject: [project @ 2005-10-21 10:24:58 by ross] X-Git-Tag: cmm-merge2~3 X-Git-Url: http://git.megacz.com/?a=commitdiff_plain;ds=sidebyside;h=b0f8af46ab1a89f107f2d678d17b765cd97ff59f;p=haskell-directory.git [project @ 2005-10-21 10:24:58 by ross] export parens, which is useful for writing Read instances. --- diff --git a/Text/Read.hs b/Text/Read.hs index 16a4d15..bcb2d09 100644 --- a/Text/Read.hs +++ b/Text/Read.hs @@ -35,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] @@ -56,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