2module SourceSyntax.Module where
5import qualified Data.List as List
6import qualified Data.Map as Map
7import Control.Applicative ((<$>), (<*>))
8import Text.PrettyPrint as P
10import SourceSyntax.Expression (LExpr)
11import SourceSyntax.Declaration
12import SourceSyntax.PrettyPrint
13import SourceSyntax.Type
15import qualified Elm.Internal.Version as Version
18 Module [String] Exports Imports [def]
21type Exports = [String]
23type Imports = [(String, ImportMethod)]
24data ImportMethod = As String | Importing [String] | Hiding [String]
25 deriving (Eq, Ord, Show)
27instance (Pretty def) => Pretty (Module def) where
28 pretty (Module modNames exports imports decls) =
29 P.vcat [modul, P.text "", prettyImports, P.text "", prettyDecls]
31 prettyDecls = P.sep $ map pretty decls
33 modul = P.text "module" <+> moduleName <+> where'
34 moduleName = P.text $ List.intercalate "." modNames
38 _ -> P.parens (commaCat $ map P.text exports) <+> P.text "where"
40 prettyImports = P.vcat $ map prettyImport imports
42 prettyImport (name, method) =
46 P.text $ name ++ (if name == alias then "" else " as " ++ alias)
49 P.text name <+> P.parens (commaCat (map P.text values))
51 Hiding [] -> P.text ("open " ++ name)
52 Hiding _ -> error "invalid import declaration"
54instance Binary ImportMethod where
56 let put' n info = putWord8 n >> put info in
59 Importing ss -> put' 1 ss
60 Hiding ss -> put' 2 ss
62 get = do tag <- getWord8
65 1 -> Importing <$> get
67 _ -> error "Error reading valid ImportMethod type from serialized string"
74 , imports :: [(String, ImportMethod)]
76 , types :: Map.Map String Type
77 , fixities :: [(Assoc, Int, String)]
83type Interfaces = Map.Map String ModuleInterface
84type ADT = (String, [String], [(String,[Type])])
85type Alias = (String, [String], Type)
89 { iVersion :: Version.Version
90 , iTypes :: Map.Map String Type
91 , iImports :: [(String, ImportMethod)]
94 , iFixities :: [(Assoc, Int, String)]
98metaToInterface :: MetadataModule -> ModuleInterface
99metaToInterface metaModule =
101 { iVersion = Version.elmVersion
102 , iTypes = types metaModule
103 , iImports = imports metaModule
104 , iAdts = datatypes metaModule
105 , iAliases = aliases metaModule
106 , iFixities = fixities metaModule
107 , iPorts = ports metaModule
110instance Binary ModuleInterface where
111 get = ModuleInterface <$> get <*> get <*> get <*> get <*> get <*> get <*> get
118 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