on master help sign in
Making #486 more in line with the style of the rest of the codebase

Actual style guidelines coming soon!

commita5684ff356bfa89f78dcb800c8e0d46293e94798 authorEvan Czaplicki <info@elm-lang.org> dateSat 8 Feb 2014, 16:03 (13 years ago) parent3de2023
1 file changed+27−26
compiler/SourceSyntax/Module.hs+27−26
compiler/SourceSyntax/Module.hs+27−26
@@ -1,19 +1,18 @@
1−{-# OPTIONS_GHC -Wall #-}
1+{-# OPTIONS_GHC -W #-}
22module SourceSyntax.Module where
33
44import Data.Binary
5+import qualified Data.List as List
56import qualified Data.Map as Map
67import Control.Applicative ((<$>), (<*>))
78import Text.PrettyPrint as P
89
910import SourceSyntax.Expression (LExpr)
1011import SourceSyntax.Declaration
12+import SourceSyntax.PrettyPrint
1113import SourceSyntax.Type
12−import Data.List (intercalate)
1314
1415import qualified Elm.Internal.Version as Version
15−import SourceSyntax.PrettyPrint
16−
1716
1817data Module def =
1918 Module [String] Exports Imports [def]
@@ -25,30 +24,32 @@ type Imports = [(String, ImportMethod)]
2524data ImportMethod = As String | Importing [String] | Hiding [String]
2625 deriving (Eq, Ord, Show)
2726
28−instance (Pretty def ) => Pretty (Module def) where
29− pretty (Module modNames exportList importList decs) =
30− let
31− exportPret = case exportList of
32− [] -> P.text " "
33− _ -> P.parens $ commaCat $ map P.text exportList
34−
35− decPret = P.sep $ map pretty decs
36− modName = P.text $ intercalate "." modNames
37− modPret = (P.text "module" <+> modName <+> exportPret <+> P.text "where")
38−
39−
40− importPret = P.vcat $ map prettyImport importList
27+instance (Pretty def) => Pretty (Module def) where
28+ pretty (Module modNames exports imports decls) =
29+ P.vcat [modul, P.text "", prettyImports, P.text "", prettyDecls]
30+ where
31+ prettyDecls = P.sep $ map pretty decls
32+
33+ modul = P.text "module" <+> moduleName <+> where'
34+ moduleName = P.text $ List.intercalate "." modNames
35+ where' =
36+ case exports of
37+ [] -> P.text "where"
38+ _ -> P.parens (commaCat $ map P.text exports) <+> P.text "where"
39+
40+ prettyImports = P.vcat $ map prettyImport imports
4141
42− prettyImport (name, method) =
42+ prettyImport (name, method) =
43+ P.text "import" <+>
4344 case method of
44− As s -> if name == s
45− then P.text $ "import " ++ name
46− else P.text $ "import " ++ name ++ " as " ++ s
47− Importing strs -> (P.text $ "import " ++ name ++ " ") <+> (commaCat $ map P.text strs)
48− Hiding [] -> (P.text $ "import open " ++ name ++ " ")
49− Hiding strs -> (P.text $ "import open " ++ name ++ " ") <+> (commaCat $ map P.text strs)
50−
51− in P.sep [modPret, importPret, decPret]
45+ As alias ->
46+ P.text $ name ++ (if name == alias then "" else " as " ++ alias)
47+
48+ Importing values ->
49+ P.text name <+> P.parens (commaCat (map P.text values))
50+
51+ Hiding [] -> P.text ("open " ++ name)
52+ Hiding _ -> error "invalid import declaration"
5253
5354instance Binary ImportMethod where
5455 put method =