on master help sign in
Prettier printing for infix functions like `div`
abb6dc1Evan Czaplicki
compiler/SourceSyntax/Expression.hs+3−2
@@ -55,11 +55,12 @@ instance Pretty (Expr t v) where
55 Var x -> variable x
55 Var x -> variable x
56 Range e1 e2 -> P.brackets (pretty e1 <> P.text ".." <> pretty e2)
56 Range e1 e2 -> P.brackets (pretty e1 <> P.text ".." <> pretty e2)
57 ExplicitList es -> P.brackets (commaCat (map pretty es))
57 ExplicitList es -> P.brackets (commaCat (map pretty es))
58− Binop op e1 e2 -> P.sep [ prettyParens e1 <+> P.text op, prettyParens e2 ]
58+ Binop op e1 e2 -> P.sep [ prettyParens e1 <+> P.text op', prettyParens e2 ]
59+ where op' = if Help.isOp op then op else "`" ++ op ++ "`"
59 Lambda p e -> let (ps,body) = collectLambdas (Location.none $ Lambda p e)
60 Lambda p e -> let (ps,body) = collectLambdas (Location.none $ Lambda p e)
60 in P.text "\\" <> P.sep ps <+> P.text "->" <+> pretty body
61 in P.text "\\" <> P.sep ps <+> P.text "->" <+> pretty body
61 App _ _ -> P.hang func 2 (P.sep args)
62 App _ _ -> P.hang func 2 (P.sep args)
62− where func:args = map prettyParens (collectApps (Location.none expr))
63+ where func:args = map prettyParens (collectApps (Location.none expr))
63 MultiIf branches -> P.text "if" $$ nest 3 (vcat $ map iff branches)
64 MultiIf branches -> P.text "if" $$ nest 3 (vcat $ map iff branches)
64 where
65 where
65 iff (b,e) = P.text "|" <+> P.hang (pretty b <+> P.text "->") 2 (pretty e)
66 iff (b,e) = P.text "|" <+> P.hang (pretty b <+> P.text "->") 2 (pretty e)