From f64f7990f55929d02ab4f0db8655c9de027ff2dd Mon Sep 17 00:00:00 2001 From: Willem Van Onsem Date: Tue, 29 Dec 2020 16:48:42 +0100 Subject: [PATCH 1/2] improve the parseFromFile functions --- src/Text/Parsec/ByteString.hs | 4 +--- src/Text/Parsec/ByteString/Lazy.hs | 4 +--- src/Text/Parsec/String.hs | 4 +--- src/Text/Parsec/Text.hs | 4 +--- src/Text/Parsec/Text/Lazy.hs | 4 +--- 5 files changed, 5 insertions(+), 15 deletions(-) diff --git a/src/Text/Parsec/ByteString.hs b/src/Text/Parsec/ByteString.hs index e65dee14..064cb0d8 100644 --- a/src/Text/Parsec/ByteString.hs +++ b/src/Text/Parsec/ByteString.hs @@ -37,6 +37,4 @@ type GenParser t st = Parsec C.ByteString st -- > } parseFromFile :: Parser a -> FilePath -> IO (Either ParseError a) -parseFromFile p fname - = do input <- C.readFile fname - return (runP p () fname input) +parseFromFile p fname = runP p () fname <$> C.readFile fname diff --git a/src/Text/Parsec/ByteString/Lazy.hs b/src/Text/Parsec/ByteString/Lazy.hs index 2a457814..1b328099 100644 --- a/src/Text/Parsec/ByteString/Lazy.hs +++ b/src/Text/Parsec/ByteString/Lazy.hs @@ -37,6 +37,4 @@ type GenParser t st = Parsec C.ByteString st -- > } parseFromFile :: Parser a -> FilePath -> IO (Either ParseError a) -parseFromFile p fname - = do input <- C.readFile fname - return (runP p () fname input) +parseFromFile p fname = runP p () fname <$> C.readFile fname diff --git a/src/Text/Parsec/String.hs b/src/Text/Parsec/String.hs index 67efa537..898afc62 100644 --- a/src/Text/Parsec/String.hs +++ b/src/Text/Parsec/String.hs @@ -34,6 +34,4 @@ type GenParser tok st = Parsec [tok] st -- > Right xs -> print (sum xs) -- > } parseFromFile :: Parser a -> FilePath -> IO (Either ParseError a) -parseFromFile p fname - = do input <- readFile fname - return (runP p () fname input) +parseFromFile p fname = runP p () fname <$> readFile fname diff --git a/src/Text/Parsec/Text.hs b/src/Text/Parsec/Text.hs index 0e609686..9acbdbfb 100644 --- a/src/Text/Parsec/Text.hs +++ b/src/Text/Parsec/Text.hs @@ -39,6 +39,4 @@ type GenParser st = Parsec Text.Text st -- @since 3.1.14.0 parseFromFile :: Parser a -> FilePath -> IO (Either ParseError a) -parseFromFile p fname - = do input <- T.readFile fname - return (runP p () fname input) +parseFromFile p fname = runP p () fname <$> T.readFile fname diff --git a/src/Text/Parsec/Text/Lazy.hs b/src/Text/Parsec/Text/Lazy.hs index 3cddb675..53f991bb 100644 --- a/src/Text/Parsec/Text/Lazy.hs +++ b/src/Text/Parsec/Text/Lazy.hs @@ -39,6 +39,4 @@ type GenParser st = Parsec Text.Text st -- @since 3.1.14.0 parseFromFile :: Parser a -> FilePath -> IO (Either ParseError a) -parseFromFile p fname - = do input <- TL.readFile fname - return (runP p () fname input) +parseFromFile p fname = runP p () fname <$> TL.readFile fname From 4b5d7e69acde686c602d70fad6919b8529917325 Mon Sep 17 00:00:00 2001 From: Willem Van Onsem Date: Tue, 29 Dec 2020 20:09:33 +0100 Subject: [PATCH 2/2] conditional import of (<$>) --- src/Text/Parsec/ByteString.hs | 5 +++++ src/Text/Parsec/ByteString/Lazy.hs | 5 +++++ src/Text/Parsec/String.hs | 5 +++++ src/Text/Parsec/Text.hs | 5 +++++ src/Text/Parsec/Text/Lazy.hs | 5 +++++ 5 files changed, 25 insertions(+) diff --git a/src/Text/Parsec/ByteString.hs b/src/Text/Parsec/ByteString.hs index 064cb0d8..ccd6d41f 100644 --- a/src/Text/Parsec/ByteString.hs +++ b/src/Text/Parsec/ByteString.hs @@ -1,3 +1,4 @@ +{-# LANGUAGE CPP #-} {-# LANGUAGE Safe #-} ----------------------------------------------------------------------------- @@ -18,6 +19,10 @@ module Text.Parsec.ByteString ( Parser, GenParser, parseFromFile ) where +#if __GLASGOW_HASKELL__ < 710 +import Data.Functor((<$>)) +#endif + import Text.Parsec.Error import Text.Parsec.Prim diff --git a/src/Text/Parsec/ByteString/Lazy.hs b/src/Text/Parsec/ByteString/Lazy.hs index 1b328099..ba4b4308 100644 --- a/src/Text/Parsec/ByteString/Lazy.hs +++ b/src/Text/Parsec/ByteString/Lazy.hs @@ -1,3 +1,4 @@ +{-# LANGUAGE CPP #-} {-# LANGUAGE Safe #-} ----------------------------------------------------------------------------- @@ -18,6 +19,10 @@ module Text.Parsec.ByteString.Lazy ( Parser, GenParser, parseFromFile ) where +#if __GLASGOW_HASKELL__ < 710 +import Data.Functor((<$>)) +#endif + import Text.Parsec.Error import Text.Parsec.Prim diff --git a/src/Text/Parsec/String.hs b/src/Text/Parsec/String.hs index 898afc62..935a148e 100644 --- a/src/Text/Parsec/String.hs +++ b/src/Text/Parsec/String.hs @@ -1,3 +1,4 @@ +{-# LANGUAGE CPP #-} {-# LANGUAGE Safe #-} ----------------------------------------------------------------------------- @@ -18,6 +19,10 @@ module Text.Parsec.String ( Parser, GenParser, parseFromFile ) where +#if __GLASGOW_HASKELL__ < 710 +import Data.Functor((<$>)) +#endif + import Text.Parsec.Error import Text.Parsec.Prim diff --git a/src/Text/Parsec/Text.hs b/src/Text/Parsec/Text.hs index 9acbdbfb..349961fa 100644 --- a/src/Text/Parsec/Text.hs +++ b/src/Text/Parsec/Text.hs @@ -1,3 +1,4 @@ +{-# LANGUAGE CPP #-} {-# LANGUAGE Safe #-} ----------------------------------------------------------------------------- @@ -18,6 +19,10 @@ module Text.Parsec.Text ( Parser, GenParser, parseFromFile ) where +#if __GLASGOW_HASKELL__ < 710 +import Data.Functor((<$>)) +#endif + import qualified Data.Text as Text import Text.Parsec.Prim import Text.Parsec.Error diff --git a/src/Text/Parsec/Text/Lazy.hs b/src/Text/Parsec/Text/Lazy.hs index 53f991bb..124e7ce4 100644 --- a/src/Text/Parsec/Text/Lazy.hs +++ b/src/Text/Parsec/Text/Lazy.hs @@ -1,3 +1,4 @@ +{-# LANGUAGE CPP #-} {-# LANGUAGE Safe #-} ----------------------------------------------------------------------------- @@ -18,6 +19,10 @@ module Text.Parsec.Text.Lazy ( Parser, GenParser, parseFromFile ) where +#if __GLASGOW_HASKELL__ < 710 +import Data.Functor((<$>)) +#endif + import qualified Data.Text.Lazy as Text import Text.Parsec.Prim import Text.Parsec.Error