1{-# OPTIONS_GHC -Wall #-}
2module SourceSyntax.Module where
5import qualified Data.Map as Map
6import Control.Applicative ((<$>), (<*>))
7import Text.PrettyPrint as P
9import SourceSyntax.Expression (LExpr)
10import SourceSyntax.Declaration
11import SourceSyntax.Type
12import Data.List (intercalate)
14import qualified Elm.Internal.Version as Version
15import SourceSyntax.PrettyPrint
19 Module [String] Exports Imports [def]
22type Exports = [String]
24type Imports = [(String, ImportMethod)]
25data ImportMethod = As String | Importing [String] | Hiding [String]
26 deriving (Eq, Ord, Show)
28instance (Pretty def ) => Pretty (Module def) where
29 pretty (Module modNames exportList importList decs) =
31 exportPret = case exportList of
33 _ -> P.parens $ commaCat $ map P.text exportList
35 decPret = P.sep $ map pretty decs
36 modName = P.text $ intercalate "." modNames
37 modPret = (P.text "module" <+> modName <+> exportPret <+> P.text "where")
40 importPret = P.vcat $ map prettyImport importList
42 prettyImport (name, method) =
45 then P.text $ "import " ++ name
46 else P.text $ "import " ++ name ++ " as " ++ s
47 Importing strs -> (P.text $ "import " ++ name ++ " ") <+> (commaCat $ map P.text strs)
48 Hiding [] -> (P.text $ "import open " ++ name ++ " ")
49 Hiding strs -> (P.text $ "import open " ++ name ++ " ") <+> (commaCat $ map P.text strs)
51 in P.sep [modPret, importPret, decPret]
53instance Binary ImportMethod where
55 let put' n info = putWord8 n >> put info in
58 Importing ss -> put' 1 ss
59 Hiding ss -> put' 2 ss
61 get = do tag <- getWord8
64 1 -> Importing <$> get
66 _ -> error "Error reading valid ImportMethod type from serialized string"
73 , imports :: [(String, ImportMethod)]
75 , types :: Map.Map String Type
76 , fixities :: [(Assoc, Int, String)]
82type Interfaces = Map.Map String ModuleInterface
83type ADT = (String, [String], [(String,[Type])])
84type Alias = (String, [String], Type)
88 { iVersion :: Version.Version
89 , iTypes :: Map.Map String Type
90 , iImports :: [(String, ImportMethod)]
93 , iFixities :: [(Assoc, Int, String)]
97metaToInterface :: MetadataModule -> ModuleInterface
98metaToInterface metaModule =
100 { iVersion = Version.elmVersion
101 , iTypes = types metaModule
102 , iImports = imports metaModule
103 , iAdts = datatypes metaModule
104 , iAliases = aliases metaModule
105 , iFixities = fixities metaModule
106 , iPorts = ports metaModule
109instance Binary ModuleInterface where
110 get = ModuleInterface <$> get <*> get <*> get <*> get <*> get <*> get <*> get
117 put (iFixities modul)
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list