@@ -95,7 +95,7 @@ prettyPrintDeclaration _ = error "Invalid argument to prettyPrintDeclaration"
95prettyPrintCaseAlternative :: CaseAlternative -> StateT PrinterState Maybe String
95prettyPrintCaseAlternative :: CaseAlternative -> StateT PrinterState Maybe String
96prettyPrintCaseAlternative (CaseAlternative binders result) =
96prettyPrintCaseAlternative (CaseAlternative binders result) =
97 concat <$> sequence
97 concat <$> sequence
98− [ intercalate ", " <$> forM binders prettyPrintBinder'
98+ [ return (unwords (map prettyPrintBinderAtom binders))
99 , prettyPrintResult result
99 , prettyPrintResult result
@@ -118,7 +118,7 @@ prettyPrintDoNotationElement (DoNotationValue val) =
118 prettyPrintValue' val
118 prettyPrintValue' val
119prettyPrintDoNotationElement (DoNotationBind binder val) =
119prettyPrintDoNotationElement (DoNotationBind binder val) =
120 concat <$> sequence
120 concat <$> sequence
121− [ prettyPrintBinder' binder
121+ [ return (prettyPrintBinder binder)
122 , return " <- "
122 , return " <- "
123 , prettyPrintValue' val
123 , prettyPrintValue' val
@@ -131,13 +131,10 @@ prettyPrintDoNotationElement (PositionedDoNotationElement _ _ el) = prettyPrintD
132prettyPrintObject' :: [(String, Maybe Expr)] -> StateT PrinterState Maybe String
132prettyPrintObject' :: [(String, Maybe Expr)] -> StateT PrinterState Maybe String
133prettyPrintObject' [] = return "{}"
133prettyPrintObject' [] = return "{}"
134−prettyPrintObject' ps = concat <$> sequence
134+prettyPrintObject' ps = return $ "{ " ++ intercalate ", " (map prettyPrintObjectProperty ps) ++ "}"
135− [ return "{\n"
135+ where
136− , withIndent $ prettyPrintMany prettyPrintObjectProperty ps
136+ prettyPrintObjectProperty :: (String, Maybe Expr) -> String
137− , return "\n"
137+ prettyPrintObjectProperty (key, value) = prettyPrintObjectKey key ++ ": " ++ maybe "_" prettyPrintValue value
142ifThenElse :: Pattern PrinterState Expr ((Expr, Expr), Expr)
139ifThenElse :: Pattern PrinterState Expr ((Expr, Expr), Expr)
143ifThenElse = mkPattern match
140ifThenElse = mkPattern match
@@ -190,55 +187,35 @@ prettyPrintValue' = runKleisli $ runPattern matchValue
190 , [ Wrap ifThenElse $ \(th, el) cond -> "if " ++ cond ++ " then " ++ prettyPrintValue th ++ " else " ++ prettyPrintValue el ]
187 , [ Wrap ifThenElse $ \(th, el) cond -> "if " ++ cond ++ " then " ++ prettyPrintValue th ++ " else " ++ prettyPrintValue el ]
193−prettyPrintBinderAtom :: Pattern PrinterState Binder String
190+prettyPrintBinderAtom :: Binder -> String
194−prettyPrintBinderAtom = mkPattern' match
191+prettyPrintBinderAtom NullBinder = "_"
192+prettyPrintBinderAtom (StringBinder str) = show str
193+prettyPrintBinderAtom (CharBinder c) = show c
194+prettyPrintBinderAtom (NumberBinder num) = either show show num
195+prettyPrintBinderAtom (BooleanBinder True) = "true"
196+prettyPrintBinderAtom (BooleanBinder False) = "false"
197+prettyPrintBinderAtom (VarBinder ident) = show ident
198+prettyPrintBinderAtom (ConstructorBinder ctor []) = show ctor
199+prettyPrintBinderAtom (ObjectBinder bs) =
201+ ++ intercalate ", " (map prettyPrintObjectPropertyBinder bs)
196− match :: Binder -> StateT PrinterState Maybe String
204+ prettyPrintObjectPropertyBinder :: (String, Binder) -> String
197− match NullBinder = return "_"
205+ prettyPrintObjectPropertyBinder (key, binder) = prettyPrintObjectKey key ++ ": " ++ prettyPrintBinder binder
198− match (StringBinder str) = return $ show str
206+prettyPrintBinderAtom (ArrayBinder bs) =
199− match (CharBinder c) = return $ show c
207+ "[ "
200− match (NumberBinder num) = return $ either show show num
201− match (BooleanBinder True) = return "true"
202− match (BooleanBinder False) = return "false"
203− match (VarBinder ident) = return $ show ident
204− match (ConstructorBinder ctor args) = concat <$> sequence
205− [ return $ show ctor ++ " "
206− , unwords <$> forM args match
208− match (ObjectBinder bs) = concat <$> sequence
210− , withIndent $ prettyPrintMany prettyPrintObjectPropertyBinder bs
214− match (ArrayBinder bs) = concat <$> sequence
216− , unwords <$> mapM prettyPrintBinder' bs
208+ ++ intercalate ", " (map prettyPrintBinder bs)
217− , return "]"
209+ ++ " ]"
219− match (NamedBinder ident binder) = ((show ident ++ "@") ++) <$> prettyPrintBinder' binder
210+prettyPrintBinderAtom (NamedBinder ident binder) = show ident ++ "@" ++ prettyPrintBinder binder
220− match (PositionedBinder _ _ binder) = prettyPrintBinder' binder
211+prettyPrintBinderAtom (PositionedBinder _ _ binder) = prettyPrintBinderAtom binder
212+prettyPrintBinderAtom b = parens (prettyPrintBinder b)
223-- Generate a pretty-printed string representing a Binder
215-- Generate a pretty-printed string representing a Binder
225prettyPrintBinder :: Binder -> String
217prettyPrintBinder :: Binder -> String
226−prettyPrintBinder = fromMaybe (error "Incomplete pattern") . flip evalStateT (PrinterState 0) . prettyPrintBinder'
218+prettyPrintBinder (ConstructorBinder ctor []) = show ctor
227−
219+prettyPrintBinder (ConstructorBinder ctor args) = show ctor ++ " " ++ unwords (map prettyPrintBinderAtom args)
228−prettyPrintBinder' :: Binder -> StateT PrinterState Maybe String
229−prettyPrintBinder' = runKleisli $ runPattern matchBinder
231− matchBinder :: Pattern PrinterState Binder String
232− matchBinder = prettyPrintBinderAtom <+> fmap parens matchBinder
234−prettyPrintObjectPropertyBinder :: (String, Binder) -> StateT PrinterState Maybe String
235−prettyPrintObjectPropertyBinder (key, binder) = concat <$> sequence
236− [ return $ prettyPrintObjectKey key ++ ": "
237− , prettyPrintBinder' binder
220+prettyPrintBinder (PositionedBinder _ _ binder) = prettyPrintBinder binder
238− ]
221+prettyPrintBinder b = prettyPrintBinderAtom b
240−prettyPrintObjectProperty :: (String, Maybe Expr) -> StateT PrinterState Maybe String
241−prettyPrintObjectProperty (key, value) = concat <$> sequence
242− [ return $ prettyPrintObjectKey key ++ ": "
243− , maybe (pure "_") prettyPrintValue' value