on master help sign in
Nicer pretty printing and a special variable to "Save the Environment"
commitc942afea6a61aaf2506e417c95da969b5c72bc91 authorEvan Czaplicki <info@elm-lang.org> dateFri 19 Jul 2013, 17:45 (13 years ago) parentc1aef78
3 files changed+12−5
compiler/SourceSyntax/Expression.hs+6−4 compiler/SourceSyntax/PrettyPrint.hs+1 compiler/SourceSyntax/Type.hs+5−1
compiler/SourceSyntax/Expression.hs+6−4
@@ -43,8 +43,10 @@ tuple es = Data ("_Tuple" ++ show (length es)) es
4343delist (Location.L _ _ (Data "::" [h,t])) = h : delist t
4444delist _ = []
4545
46+saveEnvName = "_save_the_environment!!!"
47+
4648dummyLet defs =
47− Location.none $ Let defs (Location.none . Literal $ Literal.IntNum 42)
49+ Location.none $ Let defs (Location.none $ Var saveEnvName)
4850
4951instance Pretty (Expr t v) where
5052 pretty expr =
@@ -82,12 +84,12 @@ instance Pretty (Expr t v) where
8284 Modify e fs ->
8385 P.braces $ P.hang (pretty e <+> P.text "|")
8486 4
85− (P.sep . P.punctuate P.comma $ map field fs)
87+ (commaSep $ map field fs)
8688 where
8789 field (x,e) = P.text x <+> P.text "<-" <+> pretty e
8890
8991 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)
9193 where
9294 field (x,e) = P.text x <+> P.text "=" <+> pretty e
9395
@@ -97,7 +99,7 @@ instance Pretty (Def t v) where
9799 pretty def =
98100 case def of
99101 TypeAnnotation name tipe ->
100− P.text name <+> P.text ":" <+> P.text (show tipe)
102+ P.text name <+> P.text ":" <+> pretty tipe
101103 Def pattern expr ->
102104 pretty pattern <+> P.text "=" <+> pretty expr
103105
compiler/SourceSyntax/PrettyPrint.hs+1
@@ -14,5 +14,6 @@ instance Pretty () where
1414 pretty () = empty
1515
1616commaCat docs = cat (punctuate comma docs)
17+commaSep docs = sep (punctuate comma docs)
1718
1819parensIf bool doc = if bool then parens doc else doc
compiler/SourceSyntax/Type.hs+5−1
@@ -3,6 +3,7 @@ module SourceSyntax.Type where
33
44import Data.Data
55import qualified Data.Map as Map
6+import qualified SourceSyntax.Helpers as Help
67import SourceSyntax.PrettyPrint
78import Text.PrettyPrint as P
89
@@ -33,7 +34,10 @@ instance Pretty Type where
3334 Lambda t1 t2 -> P.sep [ t, P.sep (map (P.text "->" <+>) ts) ]
3435 where t:ts = collectLambdas tipe
3536 Var x -> P.text x
36− Data name tipes -> P.hang (P.text name) 2 (P.sep $ map prettyParens tipes)
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
40+ | otherwise -> P.hang (P.text name) 2 (P.sep $ map prettyParens tipes)
3741 EmptyRecord -> P.braces P.empty
3842 Record fields ext -> error "not done yet"
3943