@@ -1,12 +1,15 @@
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 ((<$>), (<*>))
8+import Text.PrettyPrint as P
8import SourceSyntax.Expression (LExpr)
10import SourceSyntax.Expression (LExpr)
9import SourceSyntax.Declaration
11import SourceSyntax.Declaration
12+import SourceSyntax.PrettyPrint
10import SourceSyntax.Type
13import SourceSyntax.Type
12import qualified Elm.Internal.Version as Version
15import qualified Elm.Internal.Version as Version
@@ -21,6 +24,33 @@ type Imports = [(String, ImportMethod)]
21data ImportMethod = As String | Importing [String] | Hiding [String]
24data ImportMethod = As String | Importing [String] | Hiding [String]
22 deriving (Eq, Ord, Show)
25 deriving (Eq, Ord, Show)
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]
31+ prettyDecls = P.sep $ map pretty decls
33+ modul = P.text "module" <+> moduleName <+> where'
34+ moduleName = P.text $ List.intercalate "." modNames
38+ _ -> P.parens (commaCat $ map P.text exports) <+> P.text "where"
40+ prettyImports = P.vcat $ map prettyImport imports
42+ prettyImport (name, method) =
46+ P.text $ name ++ (if name == alias then "" else " as " ++ alias)
49+ P.text name <+> P.parens (commaCat (map P.text values))
51+ Hiding [] -> P.text ("open " ++ name)
52+ Hiding _ -> error "invalid import declaration"
24instance Binary ImportMethod where
54instance Binary ImportMethod where
25 put method =
55 put method =
26 let put' n info = putWord8 n >> put info in
56 let put' n info = putWord8 n >> put info in