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 Text.PrettyPrint as P
15import qualified Elm.Internal.Version as Version
18-- HELPFUL TYPE ALIASES
20type Interfaces = Map.Map String 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
41getName :: Module exs body -> String
43 nameToString (names modul)
45data Module exports body = Module
49 , imports :: [(String, ImportMethod)]
53data CanonicalBody = CanonicalBody
54 { program :: Canonical.Expr
56 , fixities :: [(Decl.Assoc, Int, String)]
65{-| Basic info needed to identify modules and determine dependencies. -}
66data HeaderAndImports = HeaderAndImports
68 , _exports :: Var.Listing Var.Value
69 , _imports :: [(Name, ImportMethod)]
72type Name = [String] -- must be non-empty
74nameToString :: Name -> String
75nameToString = List.intercalate "."
80{-| Key facts about a module, used when reading info from .elmi files. -}
81data Interface = Interface
82 { iVersion :: Version.Version
83 , iExports :: [Var.Value]
85 , iImports :: [(String, ImportMethod)]
88 , iFixities :: [(Decl.Assoc, Int, String)]
92toInterface :: CanonicalModule -> Interface
94 let body' = body modul in
96 { iVersion = Version.elmVersion
97 , iExports = exports modul
98 , iTypes = types body'
99 , iImports = imports modul
100 , iAdts = datatypes body'
101 , iAliases = aliases body'
102 , iFixities = fixities body'
103 , iPorts = ports body'
106instance Binary Interface where
107 get = Interface <$> get <*> get <*> get <*> get <*> get <*> get <*> get <*> get
115 put (iFixities modul)
123 | Open !(Var.Listing Var.Value)
126open = Open (Var.openListing)
128importing :: [Var.Value] -> ImportMethod
129importing xs = Open (Var.Listing xs False)
131instance Binary ImportMethod where
134 As alias -> putWord8 0 >> put alias
135 Open listing -> putWord8 1 >> put listing
137 get = do tag <- getWord8
141 _ -> error "Error reading valid ImportMethod type from serialized string"
146instance (Pretty exs, Pretty body) => Pretty (Module exs body) where
147 pretty (Module names _ exs ims body) =
148 P.vcat [modul, P.text "", prettyImports, P.text "", pretty body]
150 modul = P.text "module" <+> name <+> pretty exs <+> P.text "where"
151 name = P.text (List.intercalate "." names)
153 prettyImports = P.vcat $ map prettyMethod ims
155prettyMethod :: (String, ImportMethod) -> Doc
156prettyMethod (name, method) =
159 | name == alias -> P.empty
160 | otherwise -> P.text "as" <+> P.text alias
162 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