on master help sign in
Tweak CanonicalBody and uncomment some Pretty code
64bcb0cEvan Czaplicki
compiler/AST/Module.hs+15−27
@@ -2,6 +2,7 @@
2module AST.Module where
2module AST.Module where
3
3
4import Data.Binary
4import Data.Binary
5+import qualified Data.List as List
5import qualified Data.Map as Map
6import qualified Data.Map as Map
6import Control.Applicative ((<$>),(<*>))
7import Control.Applicative ((<$>),(<*>))
7
8
@@ -10,6 +11,9 @@ import qualified AST.Declaration as Decl
10import qualified AST.Type as Type
11import qualified AST.Type as Type
11import qualified AST.Variable as Var
12import qualified AST.Variable as Var
12
13
14+import AST.PrettyPrint
15+import Text.PrettyPrint as P
16+
13import qualified Elm.Internal.Version as Version
17import qualified Elm.Internal.Version as Version
14
18
15data Module exs body = Module
19data Module exs body = Module
@@ -24,8 +28,8 @@ data CanonicalBody = CanonicalBody
24 { program :: Canonical.Expr
28 { program :: Canonical.Expr
25 , types :: Types
29 , types :: Types
26 , fixities :: [(Decl.Assoc, Int, String)]
30 , fixities :: [(Decl.Assoc, Int, String)]
27− , aliases :: [Alias]
31+ , aliases :: Aliases
28− , datatypes :: [ADT]
32+ , datatypes :: ADTs
29 , ports :: [String]
33 , ports :: [String]
30 }
34 }
31
35
@@ -35,16 +39,16 @@ type CanonicalModule = Module [Var.Value] CanonicalBody
35
39
36type Interfaces = Map.Map String Interface
40type Interfaces = Map.Map String Interface
37
41
38−type Types = Map.Map String (Type.Type Var.Canonical)
42+type Types = Map.Map String (Type.Type Var.Canonical)
39−type ADT = ( String, [String], [(String, [Type.Type Var.Canonical])] )
43+type ADTs = Map.Map String ( [String], [(String, [Type.Type Var.Canonical])] )
40−type Alias = (String, [String], Type.Type Var.Canonical )
44+type Aliases = Map.Map String ( [String], Type.Type Var.Canonical )
41
45
42data Interface = Interface
46data Interface = Interface
43 { iVersion :: Version.Version
47 { iVersion :: Version.Version
44 , iTypes :: Types
48 , iTypes :: Types
45 , iImports :: [(String, ImportMethod)]
49 , iImports :: [(String, ImportMethod)]
46− , iAdts :: [ADT]
50+ , iAdts :: ADTs
47− , iAliases :: [Alias]
51+ , iAliases :: Aliases
48 , iFixities :: [(Decl.Assoc, Int, String)]
52 , iFixities :: [(Decl.Assoc, Int, String)]
49 , iPorts :: [String]
53 , iPorts :: [String]
50 }
54 }
@@ -96,29 +100,15 @@ instance Binary ImportMethod where
96 1 -> Open <$> get
100 1 -> Open <$> get
97 _ -> error "Error reading valid ImportMethod type from serialized string"
101 _ -> error "Error reading valid ImportMethod type from serialized string"
98
102
99−{-
100−data Module port def = Module
101− { name :: [String]
102− , exports :: Var.Listing Var.Value
103− , imports :: [(String, ImportMethod)]
104− , decls :: [Declaration' port def]
105− }
106−
107−instance (Pretty port, Pretty def) => Pretty (Module port def) where
103+instance (Pretty exs, Pretty body) => Pretty (Module exs body) where
108− pretty (Module names exs ims decls) =
104+ pretty (Module names _ exs ims body) =
109− P.vcat [modul, P.text "", prettyImports, P.text "", prettyDecls]
105+ P.vcat [modul, P.text "", prettyImports, P.text "", pretty body]
110 where
106 where
111− modul = P.text "module" <+> name <+> prettyExports <+> P.text "where"
107+ modul = P.text "module" <+> name <+> pretty exs <+> P.text "where"
112 name = P.text (List.intercalate "." names)
108 name = P.text (List.intercalate "." names)
113
109
114− prettyExports
115− | Var._open exs = P.empty
116− | otherwise = pretty exs
117−
118 prettyImports = P.vcat $ map prettyMethod ims
110 prettyImports = P.vcat $ map prettyMethod ims
119
111
120− prettyDecls = P.sep $ map pretty decls
121−
122prettyMethod :: (String, ImportMethod) -> Doc
112prettyMethod :: (String, ImportMethod) -> Doc
123prettyMethod (name, method) =
113prettyMethod (name, method) =
124 case method of
114 case method of
@@ -127,5 +117,3 @@ prettyMethod (name, method) =
127 | otherwise -> P.text "as" <+> P.text alias
117 | otherwise -> P.text "as" <+> P.text alias
128
118
129 Open listing -> pretty listing
119 Open listing -> pretty listing
130−
131−-}