X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=Text%2FRead.hs;h=bcb2d0930ab395ab8f70bc0cfc99c723b5a906f9;hb=b0f8af46ab1a89f107f2d678d17b765cd97ff59f;hp=16a4d158eeb701b09d543019d768c866bbc4d0e5;hpb=eb05059d83b1c23cb5754b46f0ba5010ba80912d;p=haskell-directory.git 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