on cca69cf help sign in
84 lines 2.4 kB history raw
1{-# OPTIONS_GHC -Wall #-}
2module SourceSyntax.Module where
4import Data.Binary
5import qualified Data.Map as Map
6import Control.Applicative ((<$>), (<*>))
8import SourceSyntax.Expression (LExpr)
9import SourceSyntax.Declaration
10import SourceSyntax.Type
12import qualified Elm.Internal.Version as Version
14data Module def =
15 Module [String] Exports Imports [def]
16 deriving (Show)
18type Exports = [String]
20type Imports = [(String, ImportMethod)]
21data ImportMethod = As String | Importing [String] | Hiding [String]
22 deriving (Eq, Ord, Show)
24instance Binary ImportMethod where
25 put method =
26 let put' n info = putWord8 n >> put info in
27 case method of
28 As s -> put' 0 s
29 Importing ss -> put' 1 ss
30 Hiding ss -> put' 2 ss
32 get = do tag <- getWord8
33 case tag of
34 0 -> As <$> get
35 1 -> Importing <$> get
36 2 -> Hiding <$> get
37 _ -> error "Error reading valid ImportMethod type from serialized string"
39data MetadataModule =
40 MetadataModule
41 { names :: [String]
42 , path :: FilePath
43 , exports :: [String]
44 , imports :: [(String, ImportMethod)]
45 , program :: LExpr
46 , types :: Map.Map String Type
47 , fixities :: [(Assoc, Int, String)]
48 , aliases :: [Alias]
49 , datatypes :: [ADT]
50 } deriving Show
52type Interfaces = Map.Map String ModuleInterface
53type ADT = (String, [String], [(String,[Type])], [Derivation])
54type Alias = (String, [String], Type, [Derivation])
56data ModuleInterface = ModuleInterface {
57 iVersion :: Version.Version,
58 iTypes :: Map.Map String Type,
59 iImports :: [(String, ImportMethod)],
60 iAdts :: [ADT],
61 iAliases :: [Alias],
62 iFixities :: [(Assoc, Int, String)]
63} deriving Show
65metaToInterface :: MetadataModule -> ModuleInterface
66metaToInterface metaModule =
67 ModuleInterface
68 { iVersion = Version.elmVersion
69 , iTypes = types metaModule
70 , iImports = imports metaModule
71 , iAdts = datatypes metaModule
72 , iAliases = aliases metaModule
73 , iFixities = fixities metaModule
74 }
76instance Binary ModuleInterface where
77 get = ModuleInterface <$> get <*> get <*> get <*> get <*> get <*> get
78 put modul = do
79 put (iVersion modul)
80 put (iTypes modul)
81 put (iImports modul)
82 put (iAdts modul)
83 put (iAliases modul)
84 put (iFixities modul)