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
15import Text.PrettyPrint as P
17import qualified Elm.Internal.Version as Version
19data Module exs body = Module
23 , imports :: [(String, ImportMethod)]
27getName :: Module exs body -> String
29 List.intercalate "." (names modul)
31data CanonicalBody = CanonicalBody
32 { program :: Canonical.Expr
34 , fixities :: [(Decl.Assoc, Int, String)]
40type SourceModule = Module (Var.Listing Var.Value) [Decl.SourceDecl]
41type ValidModule = Module (Var.Listing Var.Value) [Decl.ValidDecl]
42type CanonicalModule = Module [Var.Value] CanonicalBody
44type Interfaces = Map.Map String Interface
46type Types = Map.Map String Type.CanonicalType
47type ADTs = Map.Map String ( [String], [(String, [Type.CanonicalType])] )
48type Aliases = Map.Map String ( [String], Type.CanonicalType )
50data Interface = Interface
51 { iVersion :: Version.Version
53 , iImports :: [(String, ImportMethod)]
56 , iFixities :: [(Decl.Assoc, Int, String)]
60toInterface :: CanonicalModule -> Interface
62 let body' = body modul in
64 { iVersion = Version.elmVersion
65 , iTypes = types body'
66 , iImports = imports modul
67 , iAdts = datatypes body'
68 , iAliases = aliases body'
69 , iFixities = fixities body'
70 , iPorts = ports body'
73instance Binary Interface where
74 get = Interface <$> get <*> get <*> get <*> get <*> get <*> get <*> get
86 | Open !(Var.Listing Var.Value)
89open = Open (Var.openListing)
91importing :: [String] -> ImportMethod
92importing xs = Open (Var.Listing (map Var.Value xs) False)
94instance Binary ImportMethod where
96 let put' n info = putWord8 n >> put info in
98 As alias -> put' 0 alias
99 Open listing -> put' 1 listing
101 get = do tag <- getWord8
105 _ -> error "Error reading valid ImportMethod type from serialized string"
107instance (Pretty exs, Pretty body) => Pretty (Module exs body) where
108 pretty (Module names _ exs ims body) =
109 P.vcat [modul, P.text "", prettyImports, P.text "", pretty body]
111 modul = P.text "module" <+> name <+> pretty exs <+> P.text "where"
112 name = P.text (List.intercalate "." names)
114 prettyImports = P.vcat $ map prettyMethod ims
116prettyMethod :: (String, ImportMethod) -> Doc
117prettyMethod (name, method) =
120 | name == alias -> P.empty
121 | otherwise -> P.text "as" <+> P.text alias
123 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