@@ -21,7 +21,7 @@ module Language.PureScript.Pretty.Values (
21import Data.Maybe (fromMaybe)
21import Data.Maybe (fromMaybe)
22import Data.List (intercalate)
22import Data.List (intercalate)
24−import Control.Arrow ((<+>), runKleisli)
24+import Control.Arrow ((<+>), runKleisli, second)
25import Control.PatternArrows
25import Control.PatternArrows
26import Control.Monad.State
26import Control.Monad.State
27import Control.Applicative
27import Control.Applicative
@@ -38,33 +38,28 @@ literals = mkPattern' match
38 match (StringLiteral s) = return $ show s
38 match (StringLiteral s) = return $ show s
39 match (BooleanLiteral True) = return "true"
39 match (BooleanLiteral True) = return "true"
40 match (BooleanLiteral False) = return "false"
40 match (BooleanLiteral False) = return "false"
41− match (ArrayLiteral xs) = fmap concat $ sequence
41+ match (ArrayLiteral xs) = concat <$> sequence
42 [ return "[ "
42 [ return "[ "
43 , withIndent $ prettyPrintMany prettyPrintValue' xs
43 , withIndent $ prettyPrintMany prettyPrintValue' xs
44 , return " ]"
44 , return " ]"
46− match (ObjectLiteral []) = return "{}"
46+ match (ObjectLiteral ps) = prettyPrintObject' $ second Just `map` ps
47− match (ObjectLiteral ps) = fmap concat $ sequence
47+ match (ObjectConstructor ps) = prettyPrintObject' ps
48− [ return "{\n"
48+ match (ObjectGetter prop) = return $ "(." ++ prop ++ ")"
49− , withIndent $ prettyPrintMany prettyPrintObjectProperty ps
54− match (TypeClassDictionaryConstructorApp className ps) = fmap concat $ sequence
49+ match (TypeClassDictionaryConstructorApp className ps) = concat <$> sequence
55− [ return ((show className) ++ "(\n")
50+ [ return (show className ++ "(\n")
56 , match ps
51 , match ps
57 , return ")"
52 , return ")"
59 match (Constructor name) = return $ show name
54 match (Constructor name) = return $ show name
60− match (Case values binders) = fmap concat $ sequence
55+ match (Case values binders) = concat <$> sequence
61 [ return "case "
56 [ return "case "
62 , unwords <$> forM values prettyPrintValue'
57 , unwords <$> forM values prettyPrintValue'
63 , return " of\n"
58 , return " of\n"
64 , withIndent $ prettyPrintMany prettyPrintCaseAlternative binders
59 , withIndent $ prettyPrintMany prettyPrintCaseAlternative binders
65 , currentIndent
60 , currentIndent
67− match (Let ds val) = fmap concat $ sequence
62+ match (Let ds val) = concat <$> sequence
68 [ return "let\n"
63 [ return "let\n"
69 , withIndent $ prettyPrintMany prettyPrintDeclaration ds
64 , withIndent $ prettyPrintMany prettyPrintDeclaration ds
70 , return "\n"
65 , return "\n"
@@ -73,7 +68,7 @@ literals = mkPattern' match
73 , prettyPrintValue' val
68 , prettyPrintValue' val
75 match (Var ident) = return $ show ident
70 match (Var ident) = return $ show ident
76− match (Do els) = fmap concat $ sequence
71+ match (Do els) = concat <$> sequence
77 [ return "do "
72 [ return "do "
78 , withIndent $ prettyPrintMany prettyPrintDoNotationElement els
73 , withIndent $ prettyPrintMany prettyPrintDoNotationElement els
79 , currentIndent
74 , currentIndent
@@ -86,7 +81,7 @@ literals = mkPattern' match
87prettyPrintDeclaration :: Declaration -> StateT PrinterState Maybe String
82prettyPrintDeclaration :: Declaration -> StateT PrinterState Maybe String
88prettyPrintDeclaration (TypeDeclaration ident ty) = return $ show ident ++ " :: " ++ prettyPrintType ty
83prettyPrintDeclaration (TypeDeclaration ident ty) = return $ show ident ++ " :: " ++ prettyPrintType ty
89−prettyPrintDeclaration (ValueDeclaration ident _ [] (Right val)) = fmap concat $ sequence
84+prettyPrintDeclaration (ValueDeclaration ident _ [] (Right val)) = concat <$> sequence
90 [ return $ show ident ++ " = "
85 [ return $ show ident ++ " = "
91 , prettyPrintValue' val
86 , prettyPrintValue' val
@@ -95,7 +90,7 @@ prettyPrintDeclaration _ = error "Invalid argument to prettyPrintDeclaration"
96prettyPrintCaseAlternative :: CaseAlternative -> StateT PrinterState Maybe String
91prettyPrintCaseAlternative :: CaseAlternative -> StateT PrinterState Maybe String
97prettyPrintCaseAlternative (CaseAlternative binders result) =
92prettyPrintCaseAlternative (CaseAlternative binders result) =
98− fmap concat $ sequence
93+ concat <$> sequence
99 [ intercalate ", " <$> forM binders prettyPrintBinder'
94 [ intercalate ", " <$> forM binders prettyPrintBinder'
100 , prettyPrintResult result
95 , prettyPrintResult result
@@ -104,7 +99,7 @@ prettyPrintCaseAlternative (CaseAlternative binders result) =
104 prettyPrintResult (Right v) = (" -> " ++) <$> prettyPrintValue' v
99 prettyPrintResult (Right v) = (" -> " ++) <$> prettyPrintValue' v
106 prettyPrintGuardedValue (grd, val) =
101 prettyPrintGuardedValue (grd, val) =
107− fmap concat $ sequence
102+ concat <$> sequence
108 [ return "| "
103 [ return "| "
109 , prettyPrintValue' grd
104 , prettyPrintValue' grd
110 , return " -> "
105 , return " -> "
@@ -116,18 +111,28 @@ prettyPrintDoNotationElement :: DoNotationElement -> StateT PrinterState Maybe S
116prettyPrintDoNotationElement (DoNotationValue val) =
111prettyPrintDoNotationElement (DoNotationValue val) =
117 prettyPrintValue' val
112 prettyPrintValue' val
118prettyPrintDoNotationElement (DoNotationBind binder val) =
113prettyPrintDoNotationElement (DoNotationBind binder val) =
119− fmap concat $ sequence
114+ concat <$> sequence
120 [ prettyPrintBinder' binder
115 [ prettyPrintBinder' binder
121 , return " <- "
116 , return " <- "
122 , prettyPrintValue' val
117 , prettyPrintValue' val
124prettyPrintDoNotationElement (DoNotationLet ds) =
119prettyPrintDoNotationElement (DoNotationLet ds) =
125− fmap concat $ sequence
120+ concat <$> sequence
126 [ return "let "
121 [ return "let "
127 , withIndent $ prettyPrintMany prettyPrintDeclaration ds
122 , withIndent $ prettyPrintMany prettyPrintDeclaration ds
129prettyPrintDoNotationElement (PositionedDoNotationElement _ _ el) = prettyPrintDoNotationElement el
124prettyPrintDoNotationElement (PositionedDoNotationElement _ _ el) = prettyPrintDoNotationElement el
126+prettyPrintObject' :: [(String, Maybe Expr)] -> StateT PrinterState Maybe String
127+prettyPrintObject' [] = return "{}"
128+prettyPrintObject' ps = concat <$> sequence
130+ , withIndent $ prettyPrintMany prettyPrintObjectProperty ps
131ifThenElse :: Pattern PrinterState Expr ((Expr, Expr), Expr)
136ifThenElse :: Pattern PrinterState Expr ((Expr, Expr), Expr)
132ifThenElse = mkPattern match
137ifThenElse = mkPattern match
@@ -144,6 +149,7 @@ objectUpdate :: Pattern PrinterState Expr ([String], Expr)
144objectUpdate = mkPattern match
149objectUpdate = mkPattern match
146 match (ObjectUpdate o ps) = Just (flip map ps $ \(key, val) -> key ++ " = " ++ prettyPrintValue val, o)
151 match (ObjectUpdate o ps) = Just (flip map ps $ \(key, val) -> key ++ " = " ++ prettyPrintValue val, o)
152+ match (ObjectUpdater o ps) = Just (flip map ps $ \(key, val) -> key ++ " = " ++ maybe "_" prettyPrintValue val, o)
147 match _ = Nothing
153 match _ = Nothing
149app :: Pattern PrinterState Expr (String, Expr)
155app :: Pattern PrinterState Expr (String, Expr)
@@ -188,17 +194,17 @@ prettyPrintBinderAtom = mkPattern' match
188 match (BooleanBinder True) = return "true"
194 match (BooleanBinder True) = return "true"
189 match (BooleanBinder False) = return "false"
195 match (BooleanBinder False) = return "false"
190 match (VarBinder ident) = return $ show ident
196 match (VarBinder ident) = return $ show ident
191− match (ConstructorBinder ctor args) = fmap concat $ sequence
197+ match (ConstructorBinder ctor args) = concat <$> sequence
192 [ return $ show ctor ++ " "
198 [ return $ show ctor ++ " "
193 , unwords <$> forM args match
199 , unwords <$> forM args match
195− match (ObjectBinder bs) = fmap concat $ sequence
201+ match (ObjectBinder bs) = concat <$> sequence
196 [ return "{\n"
202 [ return "{\n"
197 , withIndent $ prettyPrintMany prettyPrintObjectPropertyBinder bs
203 , withIndent $ prettyPrintMany prettyPrintObjectPropertyBinder bs
198 , currentIndent
204 , currentIndent
199 , return "}"
205 , return "}"
201− match (ArrayBinder bs) = fmap concat $ sequence
207+ match (ArrayBinder bs) = concat <$> sequence
202 [ return "["
208 [ return "["
203 , unwords <$> mapM prettyPrintBinder' bs
209 , unwords <$> mapM prettyPrintBinder' bs
204 , return "]"
210 , return "]"
@@ -229,13 +235,13 @@ matchConsBinder = mkPattern match'
229 match' _ = Nothing
235 match' _ = Nothing
231prettyPrintObjectPropertyBinder :: (String, Binder) -> StateT PrinterState Maybe String
237prettyPrintObjectPropertyBinder :: (String, Binder) -> StateT PrinterState Maybe String
232−prettyPrintObjectPropertyBinder (key, binder) = fmap concat $ sequence
238+prettyPrintObjectPropertyBinder (key, binder) = concat <$> sequence
233 [ return $ prettyPrintObjectKey key ++ ": "
239 [ return $ prettyPrintObjectKey key ++ ": "
234 , prettyPrintBinder' binder
240 , prettyPrintBinder' binder
237−prettyPrintObjectProperty :: (String, Expr) -> StateT PrinterState Maybe String
243+prettyPrintObjectProperty :: (String, Maybe Expr) -> StateT PrinterState Maybe String
238−prettyPrintObjectProperty (key, value) = fmap concat $ sequence
244+prettyPrintObjectProperty (key, value) = concat <$> sequence
239 [ return $ prettyPrintObjectKey key ++ ": "
245 [ return $ prettyPrintObjectKey key ++ ": "
240− , prettyPrintValue' value
246+ , maybe (pure "_") prettyPrintValue' value