@@ -4,12 +4,16 @@ module SourceSyntax.Module where
4import Data.Binary
4import Data.Binary
5import qualified Data.Map as Map
5import qualified Data.Map as Map
6import Control.Applicative ((<$>), (<*>))
6import Control.Applicative ((<$>), (<*>))
7+import Text.PrettyPrint as P
8import SourceSyntax.Expression (LExpr)
9import SourceSyntax.Expression (LExpr)
9import SourceSyntax.Declaration
10import SourceSyntax.Declaration
10import SourceSyntax.Type
11import SourceSyntax.Type
12+import Data.List (intercalate)
12import qualified Elm.Internal.Version as Version
14import qualified Elm.Internal.Version as Version
15+import SourceSyntax.PrettyPrint
14data Module def =
18data Module def =
15 Module [String] Exports Imports [def]
19 Module [String] Exports Imports [def]
@@ -21,6 +25,31 @@ type Imports = [(String, ImportMethod)]
21data ImportMethod = As String | Importing [String] | Hiding [String]
25data ImportMethod = As String | Importing [String] | Hiding [String]
22 deriving (Eq, Ord, Show)
26 deriving (Eq, Ord, Show)
28+instance (Pretty def ) => Pretty (Module def) where
29+ pretty (Module modNames exportList importList decs) =
31+ exportPret = case exportList of
33+ _ -> P.parens $ commaCat $ map P.text exportList
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
42+ prettyImport (name, method) =
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)
51+ in P.sep [modPret, importPret, decPret]
24instance Binary ImportMethod where
53instance Binary ImportMethod where
25 put method =
54 put method =
26 let put' n info = putWord8 n >> put info in
55 let put' n info = putWord8 n >> put info in