5import qualified Data.List as List
6import qualified Data.Map as Map
7import Control.Applicative ((<$>),(<*>))
9import qualified AST.Expression.Canonical as Canonical
10import qualified AST.Declaration as Decl
11import qualified AST.Type as Type
12import qualified AST.Variable as Var
14import qualified Elm.Compiler.Version as Compiler
15import Text.PrettyPrint as P
18-- HELPFUL TYPE ALIASES
20type Interfaces = Map.Map Name Interface
22type Types = Map.Map String Type.CanonicalType
23type Aliases = Map.Map String ([String], Type.CanonicalType)
24type ADTs = Map.Map String (AdtInfo String)
26type AdtInfo v = ( [String], [(v, [Type.CanonicalType])] )
27type CanonicalAdt = (Var.Canonical, AdtInfo Var.Canonical)
33 Module (Var.Listing Var.Value) [Decl.SourceDecl]
36 Module (Var.Listing Var.Value) [Decl.ValidDecl]
39 Module [Var.Value] CanonicalBody
42data Module exports body = Module
46 , imports :: [(Name, ImportMethod)]
50data CanonicalBody = CanonicalBody
51 { program :: Canonical.Expr
53 , fixities :: [(Decl.Assoc, Int, String)]
62{-| Basic info needed to identify modules and determine dependencies. -}
63data HeaderAndImports = HeaderAndImports
65 , _exports :: Var.Listing Var.Value
66 , _imports :: [(Name, ImportMethod)]
69type Name = [String] -- must be non-empty
71nameToString :: Name -> String
72nameToString = List.intercalate "."
74nameIsNative :: Name -> Bool
84{-| Key facts about a module, used when reading info from .elmi files. -}
85data Interface = Interface
87 , iExports :: [Var.Value]
89 , iImports :: [(Name, ImportMethod)]
92 , iFixities :: [(Decl.Assoc, Int, String)]
96toInterface :: CanonicalModule -> Interface
98 let body' = body modul in
100 { iVersion = Compiler.version
101 , iExports = exports modul
102 , iTypes = types body'
103 , iImports = imports modul
104 , iAdts = datatypes body'
105 , iAliases = aliases body'
106 , iFixities = fixities body'
107 , iPorts = ports body'
110instance Binary Interface where
111 get = Interface <$> get <*> get <*> get <*> get <*> get <*> get <*> get <*> get
119 put (iFixities modul)
127 | Open !(Var.Listing Var.Value)
130open = Open (Var.openListing)
132importing :: [Var.Value] -> ImportMethod
133importing xs = Open (Var.Listing xs False)
135instance Binary ImportMethod where
138 As alias -> putWord8 0 >> put alias
139 Open listing -> putWord8 1 >> put listing
141 get = do tag <- getWord8
145 _ -> error "Error reading valid ImportMethod type from serialized string"
150instance (Pretty exs, Pretty body) => Pretty (Module exs body) where
151 pretty (Module names _ exs ims body) =
152 P.vcat [modul, P.text "", prettyImports, P.text "", pretty body]
154 modul = P.text "module" <+> name <+> pretty exs <+> P.text "where"
155 name = P.text (List.intercalate "." names)
158 P.vcat $ map prettyMethod ims
161prettyMethod :: (Name, ImportMethod) -> Doc
162prettyMethod import' =
165 | name == alias -> P.empty
167 (_, As alias) -> P.text "as" <+> P.text alias
169 (_, Open listing) -> pretty listing
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