{-# LANGUAGE NoImplicitPrelude #-}
module Fay.Compiler.Prelude
( module Prelude.Compat
, module Control.Applicative
, module Control.Arrow
, module Control.Monad.Compat
, module Data.Char
, module Data.Data
, module Data.Either
, module Data.Function
, module Data.List.Compat
, module Data.Maybe
, module Data.Monoid
, module Data.Ord
, module Data.Traversable
, module Safe
, anyM
, io
, readAllFromProcess
) where
import Control.Applicative
import Control.Arrow (first, second, (&&&), (***), (+++), (|||))
import Control.Monad.Compat hiding (guard)
import Data.Char hiding (GeneralCategory (..))
import Data.Data (Data (..), Typeable)
import Data.Either
import Data.Function (on)
import Data.List.Compat
import Data.Maybe
import Data.Monoid (Monoid (..))
import Data.Ord
import Data.Traversable
import Prelude.Compat hiding (exp, mod)
import Safe
import Control.Monad.Except hiding (filterM)
import System.Exit
import System.Process
io :: MonadIO m => IO a -> m a
io :: IO a -> m a
io = IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO
anyM :: (Functor m, Applicative m, Monad m) => (a -> m Bool) -> [a] -> m Bool
anyM :: (a -> m Bool) -> [a] -> m Bool
anyM p :: a -> m Bool
p l :: [a]
l = Bool -> Bool
not (Bool -> Bool) -> ([a] -> Bool) -> [a] -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [a] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null ([a] -> Bool) -> m [a] -> m Bool
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (a -> m Bool) -> [a] -> m [a]
forall (m :: * -> *) a.
Applicative m =>
(a -> m Bool) -> [a] -> m [a]
filterM a -> m Bool
p [a]
l
readAllFromProcess :: FilePath -> [String] -> String -> IO (Either (String,String) (String,String))
readAllFromProcess :: FilePath
-> [FilePath]
-> FilePath
-> IO (Either (FilePath, FilePath) (FilePath, FilePath))
readAllFromProcess program :: FilePath
program flags :: [FilePath]
flags input :: FilePath
input = do
(code :: ExitCode
code,out :: FilePath
out,err :: FilePath
err) <- FilePath
-> [FilePath] -> FilePath -> IO (ExitCode, FilePath, FilePath)
readProcessWithExitCode FilePath
program [FilePath]
flags FilePath
input
Either (FilePath, FilePath) (FilePath, FilePath)
-> IO (Either (FilePath, FilePath) (FilePath, FilePath))
forall (m :: * -> *) a. Monad m => a -> m a
return (Either (FilePath, FilePath) (FilePath, FilePath)
-> IO (Either (FilePath, FilePath) (FilePath, FilePath)))
-> Either (FilePath, FilePath) (FilePath, FilePath)
-> IO (Either (FilePath, FilePath) (FilePath, FilePath))
forall a b. (a -> b) -> a -> b
$ case ExitCode
code of
ExitFailure 127 -> (FilePath, FilePath)
-> Either (FilePath, FilePath) (FilePath, FilePath)
forall a b. a -> Either a b
Left ("cannot find executable " FilePath -> FilePath -> FilePath
forall a. [a] -> [a] -> [a]
++ FilePath
program, "")
ExitFailure _ -> (FilePath, FilePath)
-> Either (FilePath, FilePath) (FilePath, FilePath)
forall a b. a -> Either a b
Left (FilePath
err, FilePath
out)
ExitSuccess -> (FilePath, FilePath)
-> Either (FilePath, FilePath) (FilePath, FilePath)
forall a b. b -> Either a b
Right (FilePath
err, FilePath
out)