@@ -143,19 +143,38 @@ prettyPrintValue = fromMaybe (error "Incomplete pattern") . pattern matchValue (
143143 , [ binary Or "||" ]
144144 ]
145145
146+prettyPrintBinderAtom :: Pattern () Binder String
147+prettyPrintBinderAtom = mkPattern match
148+ where
149+ match :: Binder -> Maybe String
150+ match NullBinder = Just "_"
151+ match (StringBinder str) = Just $ show str
152+ match (NumberBinder num) = Just $ either show show num
153+ match (BooleanBinder True) = Just "true"
154+ match (BooleanBinder False) = Just "false"
155+ match (VarBinder ident) = Just $ show ident
156+ match (NullaryBinder ctor) = Just $ show ctor
157+ match (UnaryBinder ctor b) = Just $ show ctor ++ " " ++ prettyPrintBinder b
158+ match (ObjectBinder bs) = Just $ "{ " ++ intercalate ", " (map (uncurry prettyPrintObjectPropertyBinder) bs) ++ " }"
159+ match (ArrayBinder bs) = Just $ "[ " ++ intercalate ", " (map prettyPrintBinder bs) ++ " ]"
160+ match (NamedBinder ident binder) = Just $ show ident ++ "@" ++ prettyPrintBinder binder
161+ match (GuardedBinder cond binder) = Just $ prettyPrintBinder binder ++ " | " ++ prettyPrintValue cond
162+ match _ = Nothing
163+
146164prettyPrintBinder :: Binder -> String
147−prettyPrintBinder NullBinder = "_"
148−prettyPrintBinder (StringBinder str) = show str
149−prettyPrintBinder (NumberBinder num) = either show show num
150−prettyPrintBinder (BooleanBinder True) = "true"
151−prettyPrintBinder (BooleanBinder False) = "false"
152−prettyPrintBinder (VarBinder ident) = show ident
153−prettyPrintBinder (NullaryBinder ctor) = show ctor
154−prettyPrintBinder (UnaryBinder ctor b) = show ctor ++ " " ++ prettyPrintBinder b
155−prettyPrintBinder (ObjectBinder bs) = "{ " ++ intercalate ", " (map (uncurry prettyPrintObjectPropertyBinder) bs) ++ " }"
156−prettyPrintBinder (ArrayBinder bs rest) = "[ " ++ intercalate ", " (map prettyPrintBinder bs) ++ maybe "" (("; " ++) . prettyPrintBinder) rest ++ " ]"
157−prettyPrintBinder (NamedBinder ident binder) = show ident ++ "@" ++ prettyPrintBinder binder
158−prettyPrintBinder (GuardedBinder cond binder) = prettyPrintBinder binder ++ " | " ++ prettyPrintValue cond
165+prettyPrintBinder = fromMaybe (error "Incomplete pattern") . pattern matchBinder ()
166+ where
167+ matchBinder :: Pattern () Binder String
168+ matchBinder = buildPrettyPrinter operators (prettyPrintBinderAtom <+> fmap parens matchBinder)
169+ operators :: OperatorTable () Binder String
170+ operators =
171+ OperatorTable [ [ AssocR matchConsBinder (\b1 b2 -> b1 ++ " : " ++ b2) ] ]
172+
173+matchConsBinder :: Pattern () Binder (Binder, Binder)
174+matchConsBinder = mkPattern match'
175+ where
176+ match' (ConsBinder b1 b2) = Just (b1, b2)
177+ match' _ = Nothing
159178
160179prettyPrintObjectPropertyBinder :: String -> Binder -> String
161180prettyPrintObjectPropertyBinder key binder = key ++ ": " ++ prettyPrintBinder binder