Skip to content
This repository was archived by the owner on Mar 2, 2025. It is now read-only.

Commit

Permalink
Improve pretty printing of unary minus sign
Browse files Browse the repository at this point in the history
  • Loading branch information
sharkdp committed Apr 6, 2017
1 parent be1000a commit 3eb2bb4
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
3 changes: 1 addition & 2 deletions src/Insect/PrettyPrint.purs
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,7 @@ pretty ∷ Expression → Markup
pretty (Scalar n) = prettyScalar n
pretty (Unit u) = prettyUnit u
pretty (Variable name) = prettyVariable name
pretty (Negate (Scalar s)) = F.text "-" : prettyScalar s
pretty (Negate x) = F.text "-(" : pretty x <> [ F.text ")" ]
pretty (Negate x) = F.text "-" : withParens x
pretty (Apply fn x) = prettyApply fn x
-- ConvertTo (->) never needs parens, it has the lowest precedence:
pretty (BinOp ConvertTo x y) = pretty x <> prettyOp ConvertTo <> pretty y
Expand Down
3 changes: 3 additions & 0 deletions test/Main.purs
Original file line number Diff line number Diff line change
Expand Up @@ -635,6 +635,9 @@ main = runTest do
prettyPrintCheck "(2m)^3"
prettyPrintCheck "(2m)^(3kg)"
prettyPrintCheck "(2m)^(3kg)^((4in)^(5ft))^(6s)"
prettyPrintCheck "-sqrt(-30m^3)"
prettyPrintCheck "-3^4"
prettyPrintCheck "(-3)^4"

test "Format" do
equalPretty "2 + 3" "2+3"
Expand Down

0 comments on commit 3eb2bb4

Please sign in to comment.