on master help sign in
Nicer pretty printing and a special variable to "Save the Environment"
c942afeEvan Czaplicki
compiler/SourceSyntax/Expression.hs+6−4
@@ -43,8 +43,10 @@ tuple es = Data ("_Tuple" ++ show (length es)) es
43delist (Location.L _ _ (Data "::" [h,t])) = h : delist t
43delist (Location.L _ _ (Data "::" [h,t])) = h : delist t
44delist _ = []
44delist _ = []
45
45
46+saveEnvName = "_save_the_environment!!!"
47+
46dummyLet defs =
48dummyLet defs =
47− Location.none $ Let defs (Location.none . Literal $ Literal.IntNum 42)
49+ Location.none $ Let defs (Location.none $ Var saveEnvName)
48
50
49instance Pretty (Expr t v) where
51instance Pretty (Expr t v) where
50 pretty expr =
52 pretty expr =
@@ -82,12 +84,12 @@ instance Pretty (Expr t v) where
82 Modify e fs ->
84 Modify e fs ->
83 P.braces $ P.hang (pretty e <+> P.text "|")
85 P.braces $ P.hang (pretty e <+> P.text "|")
84 4
86 4
85− (P.sep . P.punctuate P.comma $ map field fs)
87+ (commaSep $ map field fs)
86 where
88 where
87 field (x,e) = P.text x <+> P.text "<-" <+> pretty e
89 field (x,e) = P.text x <+> P.text "<-" <+> pretty e
88
90
89 Record fs ->
91 Record fs ->
90− P.braces $ P.nest 2 (P.sep . P.punctuate P.comma $ map field fs)
92+ P.braces $ P.nest 2 (commaSep $ map field fs)
91 where
93 where
92 field (x,e) = P.text x <+> P.text "=" <+> pretty e
94 field (x,e) = P.text x <+> P.text "=" <+> pretty e
93
95
@@ -97,7 +99,7 @@ instance Pretty (Def t v) where
97 pretty def =
99 pretty def =
98 case def of
100 case def of
99 TypeAnnotation name tipe ->
101 TypeAnnotation name tipe ->
100− P.text name <+> P.text ":" <+> P.text (show tipe)
102+ P.text name <+> P.text ":" <+> pretty tipe
101 Def pattern expr ->
103 Def pattern expr ->
102 pretty pattern <+> P.text "=" <+> pretty expr
104 pretty pattern <+> P.text "=" <+> pretty expr
103
105
compiler/SourceSyntax/PrettyPrint.hs+1
@@ -14,5 +14,6 @@ instance Pretty () where
14 pretty () = empty
14 pretty () = empty
15
15
16commaCat docs = cat (punctuate comma docs)
16commaCat docs = cat (punctuate comma docs)
17+commaSep docs = sep (punctuate comma docs)
17
18
18parensIf bool doc = if bool then parens doc else doc
19parensIf bool doc = if bool then parens doc else doc
compiler/SourceSyntax/Type.hs+5−1
@@ -3,6 +3,7 @@ module SourceSyntax.Type where
3
3
4import Data.Data
4import Data.Data
5import qualified Data.Map as Map
5import qualified Data.Map as Map
6+import qualified SourceSyntax.Helpers as Help
6import SourceSyntax.PrettyPrint
7import SourceSyntax.PrettyPrint
7import Text.PrettyPrint as P
8import Text.PrettyPrint as P
8
9
@@ -33,7 +34,10 @@ instance Pretty Type where
33 Lambda t1 t2 -> P.sep [ t, P.sep (map (P.text "->" <+>) ts) ]
34 Lambda t1 t2 -> P.sep [ t, P.sep (map (P.text "->" <+>) ts) ]
34 where t:ts = collectLambdas tipe
35 where t:ts = collectLambdas tipe
35 Var x -> P.text x
36 Var x -> P.text x
37+ Data "_List" [t] -> P.brackets (pretty t)
38+ Data name tipes
39+ | Help.isTuple name -> P.parens . P.sep . P.punctuate P.comma $ map prettyParens tipes
36− Data name tipes -> P.hang (P.text name) 2 (P.sep $ map prettyParens tipes)
40+ | otherwise -> P.hang (P.text name) 2 (P.sep $ map prettyParens tipes)
37 EmptyRecord -> P.braces P.empty
41 EmptyRecord -> P.braces P.empty
38 Record fields ext -> error "not done yet"
42 Record fields ext -> error "not done yet"
39
43