@@ -1,19 +1,18 @@
1−{-# OPTIONS_GHC -Wall #-}
1+{-# OPTIONS_GHC -W #-}
2module SourceSyntax.Module where
2module SourceSyntax.Module where
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 ((<$>), (<*>))
7import Text.PrettyPrint as P
8import Text.PrettyPrint as P
9import SourceSyntax.Expression (LExpr)
10import SourceSyntax.Expression (LExpr)
10import SourceSyntax.Declaration
11import SourceSyntax.Declaration
12+import SourceSyntax.PrettyPrint
11import SourceSyntax.Type
13import SourceSyntax.Type
12−import Data.List (intercalate)
14import qualified Elm.Internal.Version as Version
15import qualified Elm.Internal.Version as Version
15−import SourceSyntax.PrettyPrint
18data Module def =
17data Module def =
19 Module [String] Exports Imports [def]
18 Module [String] Exports Imports [def]
@@ -25,30 +24,32 @@ type Imports = [(String, ImportMethod)]
25data ImportMethod = As String | Importing [String] | Hiding [String]
24data ImportMethod = As String | Importing [String] | Hiding [String]
26 deriving (Eq, Ord, Show)
25 deriving (Eq, Ord, Show)
28−instance (Pretty def ) => Pretty (Module def) where
27+instance (Pretty def) => Pretty (Module def) where
29− pretty (Module modNames exportList importList decs) =
28+ pretty (Module modNames exports imports decls) =
30− let
29+ P.vcat [modul, P.text "", prettyImports, P.text "", prettyDecls]
31− exportPret = case exportList of
30+ where
31+ prettyDecls = P.sep $ map pretty decls
33+ modul = P.text "module" <+> moduleName <+> where'
34+ moduleName = P.text $ List.intercalate "." modNames
32− [] -> P.text " "
37+ [] -> P.text "where"
33− _ -> P.parens $ commaCat $ map P.text exportList
38+ _ -> P.parens (commaCat $ map P.text exports) <+> P.text "where"
35− decPret = P.sep $ map pretty decs
36− modName = P.text $ intercalate "." modNames
37− modPret = (P.text "module" <+> modName <+> exportPret <+> P.text "where")
40− importPret = P.vcat $ map prettyImport importList
40+ prettyImports = P.vcat $ map prettyImport imports
42− prettyImport (name, method) =
42+ prettyImport (name, method) =
43 case method of
44 case method of
44− As s -> if name == s
45+ As alias ->
45− then P.text $ "import " ++ name
46+ P.text $ name ++ (if name == alias then "" else " as " ++ alias)
46− else P.text $ "import " ++ name ++ " as " ++ s
47+
47− Importing strs -> (P.text $ "import " ++ name ++ " ") <+> (commaCat $ map P.text strs)
49+ P.text name <+> P.parens (commaCat (map P.text values))
48− Hiding [] -> (P.text $ "import open " ++ name ++ " ")
51+ Hiding [] -> P.text ("open " ++ name)
49− Hiding strs -> (P.text $ "import open " ++ name ++ " ") <+> (commaCat $ map P.text strs)
52+ Hiding _ -> error "invalid import declaration"
51− in P.sep [modPret, importPret, decPret]
53instance Binary ImportMethod where
54instance Binary ImportMethod where
54 put method =
55 put method =