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)]
27data CanonicalBody = CanonicalBody
28 { program :: Canonical.Expr
30 , fixities :: [(Decl.Assoc, Int, String)]
36type SourceModule = Module (Var.Listing Var.Value) [Decl.SourceDecl]
37type ValidModule = Module (Var.Listing Var.Value) [Decl.ValidDecl]
38type CanonicalModule = Module [Var.Value] CanonicalBody
40type Interfaces = Map.Map String Interface
42type Types = Map.Map String Type.CanonicalType
43type ADTs = Map.Map String ( [String], [(String, [Type.CanonicalType])] )
44type Aliases = Map.Map String ( [String], Type.CanonicalType )
46data Interface = Interface
47 { iVersion :: Version.Version
49 , iImports :: [(String, ImportMethod)]
52 , iFixities :: [(Decl.Assoc, Int, String)]
56toInterface :: CanonicalModule -> Interface
58 let body' = body modul in
60 { iVersion = Version.elmVersion
61 , iTypes = types body'
62 , iImports = imports modul
63 , iAdts = datatypes body'
64 , iAliases = aliases body'
65 , iFixities = fixities body'
66 , iPorts = ports body'
69instance Binary Interface where
70 get = Interface <$> get <*> get <*> get <*> get <*> get <*> get <*> get
82 | Open !(Var.Listing Var.Value)
85open = Open (Var.openListing)
87importing :: [String] -> ImportMethod
88importing xs = Open (Var.Listing (map Var.Value xs) False)
90instance Binary ImportMethod where
92 let put' n info = putWord8 n >> put info in
94 As alias -> put' 0 alias
95 Open listing -> put' 1 listing
97 get = do tag <- getWord8
101 _ -> error "Error reading valid ImportMethod type from serialized string"
103instance (Pretty exs, Pretty body) => Pretty (Module exs body) where
104 pretty (Module names _ exs ims body) =
105 P.vcat [modul, P.text "", prettyImports, P.text "", pretty body]
107 modul = P.text "module" <+> name <+> pretty exs <+> P.text "where"
108 name = P.text (List.intercalate "." names)
110 prettyImports = P.vcat $ map prettyMethod ims
112prettyMethod :: (String, ImportMethod) -> Doc
113prettyMethod (name, method) =
116 | name == alias -> P.empty
117 | otherwise -> P.text "as" <+> P.text alias
119 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