2013-07-25 18:53:22 +00:00
|
|
|
module Metadata.Prelude (interfaces, add) where
|
2013-03-17 05:24:18 +00:00
|
|
|
|
|
|
|
import qualified Data.Map as Map
|
2013-07-25 18:39:23 +00:00
|
|
|
import qualified Control.Exception as E
|
|
|
|
import qualified Paths_Elm as Path
|
|
|
|
import System.Directory
|
|
|
|
import System.Exit
|
|
|
|
import System.FilePath
|
|
|
|
import System.IO.Unsafe (unsafePerformIO)
|
2013-06-14 03:45:12 +00:00
|
|
|
import SourceSyntax.Module
|
2013-07-28 00:24:17 +00:00
|
|
|
import qualified Data.Binary as Binary
|
2013-07-25 18:39:23 +00:00
|
|
|
|
2013-03-17 05:24:18 +00:00
|
|
|
|
2013-07-25 18:53:22 +00:00
|
|
|
add :: Module t v -> Module t v
|
|
|
|
add (Module name exs ims stmts) = Module name exs (customIms ++ ims) stmts
|
2013-07-25 18:39:23 +00:00
|
|
|
where
|
|
|
|
customIms = concatMap addModule prelude
|
2013-04-04 17:37:43 +00:00
|
|
|
|
2013-07-25 18:39:23 +00:00
|
|
|
addModule (n, method) = case lookup n ims of
|
|
|
|
Nothing -> [(n, method)]
|
|
|
|
Just (As m) -> [(n, method)]
|
|
|
|
Just _ -> []
|
2013-04-04 17:37:43 +00:00
|
|
|
|
2013-07-25 18:39:23 +00:00
|
|
|
prelude :: [(String, ImportMethod)]
|
2013-08-01 06:47:29 +00:00
|
|
|
prelude = text ++ map (\n -> (n, Hiding [])) modules
|
2013-04-04 08:09:35 +00:00
|
|
|
where
|
2013-08-01 06:47:29 +00:00
|
|
|
text = map ((,) "Text") [ As "Text", Hiding ["link", "color", "height"] ]
|
2013-07-28 00:35:52 +00:00
|
|
|
modules = [ "Basics", "Signal", "List", "Maybe", "Time"
|
2013-04-29 03:57:48 +00:00
|
|
|
, "Graphics.Element", "Color", "Graphics.Collage" ]
|
2013-04-04 08:09:35 +00:00
|
|
|
|
2013-07-25 18:39:23 +00:00
|
|
|
{-# NOINLINE interfaces #-}
|
|
|
|
interfaces :: Interfaces
|
|
|
|
interfaces =
|
|
|
|
unsafePerformIO (safeReadDocs =<< Path.getDataFileName "interfaces.data")
|
|
|
|
|
|
|
|
safeReadDocs :: FilePath -> IO Interfaces
|
|
|
|
safeReadDocs name =
|
|
|
|
E.catch (readDocs name) $ \err -> do
|
2013-08-02 08:53:40 +00:00
|
|
|
let _ = err :: IOError
|
2013-07-25 18:39:23 +00:00
|
|
|
putStrLn $ unlines [ "Error reading types for standard library!"
|
2013-08-02 08:53:40 +00:00
|
|
|
, " The file should be at " ++ name
|
|
|
|
, " If you are using a stable version of Elm,"
|
|
|
|
, " please report an issue at github.com/evancz/Elm"
|
|
|
|
, " and specify your versions of Elm and your OS" ]
|
2013-07-25 18:39:23 +00:00
|
|
|
exitFailure
|
|
|
|
|
|
|
|
readDocs :: FilePath -> IO Interfaces
|
|
|
|
readDocs name = do
|
|
|
|
exists <- doesFileExist name
|
2013-07-28 00:24:17 +00:00
|
|
|
if exists then Map.fromList `fmap` Binary.decodeFile name
|
2013-07-25 18:39:23 +00:00
|
|
|
else ioError . userError $ "File Not Found"
|