5import qualified Data.Map as Map
6import Control.Applicative ((<$>),(<*>))
8import qualified AST.Expression.Canonical as Canonical
9import qualified AST.Type as Type
10import qualified AST.Variable as Var
11import qualified SourceSyntax.Declaration as Decl
13import qualified Elm.Internal.Version as Version
15data Module exs body = Module
19 , imports :: [(String, ImportMethod)]
23data CanonicalBody = CanonicalBody
24 { program :: Canonical.Expr
26 , fixities :: [(Decl.Assoc, Int, String)]
32type SourceModule = Module (Var.Listing Var.Value) [Decl.SourceDecl]
33type ValidModule = Module (Var.Listing Var.Value) [Decl.ValidDecl]
34type CanonicalModule = Module [Var.Value] CanonicalBody
36type Interfaces = Map.Map String Interface
38type Types = Map.Map String (Type.Type Var.Canonical)
39type ADT = ( String, [String], [(String, [Type.Type Var.Canonical])] )
40type Alias = (String, [String], Type.Type Var.Canonical )
42data Interface = Interface
43 { iVersion :: Version.Version
45 , iImports :: [(String, ImportMethod)]
48 , iFixities :: [(Decl.Assoc, Int, String)]
52toInterface :: CanonicalModule -> Interface
54 let body' = body modul in
56 { iVersion = Version.elmVersion
57 , iTypes = types body'
58 , iImports = imports modul
59 , iAdts = datatypes body'
60 , iAliases = aliases body'
61 , iFixities = fixities body'
62 , iPorts = ports body'
65instance Binary Interface where
66 get = Interface <$> get <*> get <*> get <*> get <*> get <*> get <*> get
78 | Open !(Var.Listing Var.Value)
81open = Open (Var.openListing)
83importing :: [String] -> ImportMethod
84importing xs = Open (Var.Listing (map Var.Value xs) False)
86instance Binary ImportMethod where
88 let put' n info = putWord8 n >> put info in
90 As alias -> put' 0 alias
91 Open listing -> put' 1 listing
93 get = do tag <- getWord8
97 _ -> error "Error reading valid ImportMethod type from serialized string"
100data Module port def = Module
102 , exports :: Var.Listing Var.Value
103 , imports :: [(String, ImportMethod)]
104 , decls :: [Declaration' port def]
107instance (Pretty port, Pretty def) => Pretty (Module port def) where
108 pretty (Module names exs ims decls) =
109 P.vcat [modul, P.text "", prettyImports, P.text "", prettyDecls]
111 modul = P.text "module" <+> name <+> prettyExports <+> P.text "where"
112 name = P.text (List.intercalate "." names)
115 | Var._open exs = P.empty
116 | otherwise = pretty exs
118 prettyImports = P.vcat $ map prettyMethod ims
120 prettyDecls = P.sep $ map pretty decls
122prettyMethod :: (String, ImportMethod) -> Doc
123prettyMethod (name, method) =
126 | name == alias -> P.empty
127 | otherwise -> P.text "as" <+> P.text alias
129 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