@@ -1,26 +1,51 @@
1−module Metadata.Libraries (libraries, addPrelude) where
1+module Metadata.Libraries (interfaces, addPrelude) where
3−import Control.Applicative ((<$>),(<*>))
4import qualified Data.Map as Map
3import qualified Data.Map as Map
5−import Data.List (inits)
4+import qualified Control.Exception as E
6−import Text.JSON
5+import qualified Paths_Elm as Path
7−import Metadata.Load as Load
6+import System.Directory
9+import System.IO.Unsafe (unsafePerformIO)
8import SourceSyntax.Module
10import SourceSyntax.Module
10addPrelude :: Module t v -> Module t v
14addPrelude :: Module t v -> Module t v
11addPrelude (Module name exs ims stmts) = Module name exs (customIms ++ ims) stmts
15addPrelude (Module name exs ims stmts) = Module name exs (customIms ++ ims) stmts
12− where customIms = concatMap addModule prelude
17+ customIms = concatMap addModule prelude
14− addModule (n, method) = case lookup n ims of
19+ addModule (n, method) = case lookup n ims of
15− Nothing -> [(n, method)]
20+ Nothing -> [(n, method)]
16− Just (As m) -> [(n, method)]
21+ Just (As m) -> [(n, method)]
17− Just _ -> []
22+ Just _ -> []
24+prelude :: [(String, ImportMethod)]
19prelude = text : map (\n -> (n, Hiding [])) modules
25prelude = text : map (\n -> (n, Hiding [])) modules
21 text = ("Text", Hiding ["link", "color", "height"])
27 text = ("Text", Hiding ["link", "color", "height"])
22 modules = [ "Prelude", "Signal", "List", "Maybe", "Time"
28 modules = [ "Prelude", "Signal", "List", "Maybe", "Time"
23 , "Graphics.Element", "Color", "Graphics.Collage" ]
29 , "Graphics.Element", "Color", "Graphics.Collage" ]
25−libraries :: Map.Map String (Map.Map String String)
31+{-# NOINLINE interfaces #-}
26−libraries = Map.empty
32+interfaces :: Interfaces
34+ unsafePerformIO (safeReadDocs =<< Path.getDataFileName "interfaces.data")
36+safeReadDocs :: FilePath -> IO Interfaces
38+ E.catch (readDocs name) $ \err -> do
39+ putStrLn $ unlines [ "Error reading types for standard library!"
40+ , " " ++ show (err :: IOError)
41+ , "The file should be located here: " ++ name
42+ , " If you are using a stable version of Elm,"
43+ , " please report an issue at github.com/evancz/Elm"
44+ , " and specify your versions of Elm and your OS" ]
47+readDocs :: FilePath -> IO Interfaces
49+ exists <- doesFileExist name
50+ if exists then decodeFile name
51+ else ioError . userError $ "File Not Found"