4import qualified Data.List as List
5import qualified Data.Map as Map
6import Control.Applicative ((<$>),(<*>))
8import qualified AST.Expression.Canonical as Canonical
9import qualified AST.Declaration as Decl
10import qualified AST.Type as Type
11import qualified AST.Variable as Var
13import qualified Elm.Compiler.Version as Compiler
14import Text.PrettyPrint as P
17-- HELPFUL TYPE ALIASES
19type Interfaces = Map.Map Name Interface
21type Types = Map.Map String Type.CanonicalType
22type Aliases = Map.Map String ([String], Type.CanonicalType)
23type ADTs = Map.Map String (AdtInfo String)
25type AdtInfo v = ( [String], [(v, [Type.CanonicalType])] )
26type CanonicalAdt = (Var.Canonical, AdtInfo Var.Canonical)
32 Module (Var.Listing Var.Value) [Decl.SourceDecl]
35 Module (Var.Listing Var.Value) [Decl.ValidDecl]
38 Module [Var.Value] CanonicalBody
41data Module exports body = Module
45 , imports :: [(Name, ImportMethod)]
49data CanonicalBody = CanonicalBody
50 { program :: Canonical.Expr
52 , fixities :: [(Decl.Assoc, Int, String)]
61{-| Basic info needed to identify modules and determine dependencies. -}
62data HeaderAndImports = HeaderAndImports
64 , _exports :: Var.Listing Var.Value
65 , _imports :: [(Name, ImportMethod)]
68type Name = [String] -- must be non-empty
70nameToString :: Name -> String
71nameToString = List.intercalate "."
73nameIsNative :: Name -> Bool
83{-| Key facts about a module, used when reading info from .elmi files. -}
84data Interface = Interface
86 , iExports :: [Var.Value]
88 , iImports :: [(Name, ImportMethod)]
91 , iFixities :: [(Decl.Assoc, Int, String)]
95toInterface :: CanonicalModule -> Interface
97 let body' = body modul in
99 { iVersion = Compiler.version
100 , iExports = exports modul
101 , iTypes = types body'
102 , iImports = imports modul
103 , iAdts = datatypes body'
104 , iAliases = aliases body'
105 , iFixities = fixities body'
106 , iPorts = ports body'
109instance Binary Interface where
110 get = Interface <$> get <*> get <*> get <*> get <*> get <*> get <*> get <*> get
118 put (iFixities modul)
126 | Open !(Var.Listing Var.Value)
129open = Open (Var.openListing)
131importing :: [Var.Value] -> ImportMethod
132importing xs = Open (Var.Listing xs False)
134instance Binary ImportMethod where
137 As alias -> putWord8 0 >> put alias
138 Open listing -> putWord8 1 >> put listing
140 get = do tag <- getWord8
144 _ -> error "Error reading valid ImportMethod type from serialized string"
149instance (Pretty exs, Pretty body) => Pretty (Module exs body) where
150 pretty (Module names _ exs ims body) =
151 P.vcat [modul, P.text "", prettyImports, P.text "", pretty body]
153 modul = P.text "module" <+> name <+> pretty exs <+> P.text "where"
154 name = P.text (List.intercalate "." names)
157 P.vcat $ map prettyMethod ims
160prettyMethod :: (Name, ImportMethod) -> Doc
161prettyMethod import' =
164 | name == alias -> P.empty
166 (_, As alias) -> P.text "as" <+> P.text alias
168 (_, 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