module Curry.FlatCurry.Files
( readTypedFlatCurry, readFlatCurry, readFlatInterface, writeFlatCurry
) where
import Control.Monad (liftM)
import Data.Char (isSpace)
import Curry.Files.Filenames (typedFlatName, flatName, flatIntName)
import Curry.Files.PathUtils (writeModule, readModule)
import Curry.FlatCurry.Type (Prog)
import Curry.FlatCurry.Annotated.Type (AProg, TypeExpr)
readTypedFlatCurry :: FilePath -> IO (Maybe (AProg TypeExpr))
readTypedFlatCurry :: FilePath -> IO (Maybe (AProg TypeExpr))
readTypedFlatCurry = FilePath -> IO (Maybe (AProg TypeExpr))
forall a. Read a => FilePath -> IO (Maybe a)
readFlat (FilePath -> IO (Maybe (AProg TypeExpr)))
-> (FilePath -> FilePath)
-> FilePath
-> IO (Maybe (AProg TypeExpr))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. FilePath -> FilePath
typedFlatName
readFlatCurry :: FilePath -> IO (Maybe Prog)
readFlatCurry :: FilePath -> IO (Maybe Prog)
readFlatCurry = FilePath -> IO (Maybe Prog)
forall a. Read a => FilePath -> IO (Maybe a)
readFlat (FilePath -> IO (Maybe Prog))
-> (FilePath -> FilePath) -> FilePath -> IO (Maybe Prog)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. FilePath -> FilePath
flatName
readFlatInterface :: FilePath -> IO (Maybe Prog)
readFlatInterface :: FilePath -> IO (Maybe Prog)
readFlatInterface = FilePath -> IO (Maybe Prog)
forall a. Read a => FilePath -> IO (Maybe a)
readFlat (FilePath -> IO (Maybe Prog))
-> (FilePath -> FilePath) -> FilePath -> IO (Maybe Prog)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. FilePath -> FilePath
flatIntName
readFlat :: Read a => FilePath -> IO (Maybe a)
readFlat :: FilePath -> IO (Maybe a)
readFlat = (Maybe FilePath -> Maybe a) -> IO (Maybe FilePath) -> IO (Maybe a)
forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
liftM ((FilePath -> a) -> Maybe FilePath -> Maybe a
forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
liftM (FilePath -> a
forall a. Read a => FilePath -> a
read (FilePath -> a) -> (FilePath -> FilePath) -> FilePath -> a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. FilePath -> FilePath
skipComment)) (IO (Maybe FilePath) -> IO (Maybe a))
-> (FilePath -> IO (Maybe FilePath)) -> FilePath -> IO (Maybe a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. FilePath -> IO (Maybe FilePath)
readModule where
skipComment :: FilePath -> FilePath
skipComment s :: FilePath
s = case (Char -> Bool) -> FilePath -> FilePath
forall a. (a -> Bool) -> [a] -> [a]
dropWhile Char -> Bool
isSpace FilePath
s of
'{' : '-' : s' :: FilePath
s' -> FilePath -> FilePath
dropComment FilePath
s'
s' :: FilePath
s' -> FilePath
s'
dropComment :: FilePath -> FilePath
dropComment ('-' : '}' : xs :: FilePath
xs) = FilePath
xs
dropComment (_ : xs :: FilePath
xs) = FilePath -> FilePath
dropComment FilePath
xs
dropComment [] = []
writeFlatCurry :: Show a => FilePath -> a -> IO ()
writeFlatCurry :: FilePath -> a -> IO ()
writeFlatCurry fn :: FilePath
fn = FilePath -> FilePath -> IO ()
writeModule FilePath
fn (FilePath -> IO ()) -> (a -> FilePath) -> a -> IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> FilePath
forall a. Show a => a -> FilePath
show