Skip to content

Commit

Permalink
More parens around do blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
runarorama committed Aug 23, 2024
1 parent eefacbf commit 8a70414
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 36 deletions.
19 changes: 6 additions & 13 deletions parser-typechecker/src/Unison/Syntax/TermPrinter.hs
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ pretty0
| Match' _ _ <- x -> do
px <- pretty0 (ac Annotation Block im doc) x
let hang = if isSoftHangable x then PP.softHang else PP.hang
pure . paren (p >= Application) $
pure . paren (p > Control) $
fmt S.ControlKeyword "do" `hang` px
| otherwise -> do
let (im0', uses0) = calcImports im x
Expand All @@ -325,7 +325,7 @@ pretty0
-- this makes sure we get proper indentation if `px` spills onto
-- multiple lines, since `do` introduces layout block
let indent = PP.Width (if soft then 2 else 0) + (if soft && p < Application then 1 else 0)
pure . paren (p >= Application) $
pure . paren (p > Control) $
fmt S.ControlKeyword "do" `hang` PP.lines (uses <> [PP.indentNAfterNewline indent px])
List' xs -> do
let listLink p = fmt (S.TypeReference Type.listRef) p
Expand Down Expand Up @@ -487,21 +487,21 @@ pretty0
let prec = termPrecedence f
prettyF <- pretty0 (AmbientContext Application Normal Infix im doc False) f
prettyA <- pretty0 (ac (fromMaybe (InfixOp Lowest) prec) Normal im doc) a
prettyB <- pretty0 (ac (fromMaybe (InfixOp Lowest) prec) Normal im doc) b
prettyB <- pretty0 (ac (fromMaybe (InfixOp Highest) prec) Normal im doc) b
pure . parenNoGroup (p > fromMaybe (InfixOp Lowest) prec) $
(prettyA <> " " <> prettyF <> " " <> prettyB) `PP.orElse` (prettyA `PP.hangUngrouped` (PP.column2 [(prettyF, prettyB)]))
(And' a b, _) -> do
let prec = operatorPrecedence "&&"
prettyF = fmt S.ControlKeyword "&&"
prettyA <- pretty0 (ac (fromMaybe (InfixOp Lowest) prec) Normal im doc) a
prettyB <- pretty0 (ac (fromMaybe (InfixOp Lowest) prec) Normal im doc) b
prettyB <- pretty0 (ac (fromMaybe (InfixOp Highest) prec) Normal im doc) b
pure . parenNoGroup (p > fromMaybe (InfixOp Lowest) prec) $
(prettyA <> " " <> prettyF <> " " <> prettyB) `PP.orElse` (prettyA `PP.hangUngrouped` (PP.column2 [(prettyF, prettyB)]))
(Or' a b, _) -> do
let prec = operatorPrecedence "||"
prettyF = fmt S.ControlKeyword "||"
prettyA <- pretty0 (ac (fromMaybe (InfixOp Lowest) prec) Normal im doc) a
prettyB <- pretty0 (ac (fromMaybe (InfixOp Lowest) prec) Normal im doc) b
prettyB <- pretty0 (ac (fromMaybe (InfixOp Highest) prec) Normal im doc) b
pure . parenNoGroup (p > fromMaybe (InfixOp Lowest) prec) $
PP.group (prettyA <> " " <> prettyF <> " " <> prettyB)
`PP.orElse` (prettyA `PP.hangUngrouped` prettyF <> " " <> prettyB)
Expand Down Expand Up @@ -538,14 +538,6 @@ pretty0
pure . paren (p >= (InfixOp Lowest)) $
PP.group (PP.group (PP.group (PP.sep softTab (fun : args') <> softTab)) <> lastArg')
_other -> case (term, nonForcePred) of
-- OverappliedBinaryAppPred' f a b r
-- | binaryOpsPred f ->
-- -- Special case for overapplied binary op
-- do
-- prettyB <- pretty0 (ac (InfixOp Lowest) Normal im doc) b
-- prettyR <- PP.spacedTraverse (pretty0 (ac Application Normal im doc)) r
-- prettyA <- binaryApps [(f, a)] prettyB
-- pure $ paren True $ PP.hang prettyA prettyR
AppsPred' f args ->
paren (p >= Application) <$> do
f' <- pretty0 (ac Application Normal im doc) f
Expand Down Expand Up @@ -1567,6 +1559,7 @@ isBlock tm =
Match' _ _ -> True
LetBlock _ _ -> True
DDelay' _ -> True
Delay' _ -> True
_ -> False

pattern LetBlock ::
Expand Down
26 changes: 3 additions & 23 deletions unison-src/transcripts-round-trip/main.output.md
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,7 @@ fixity =
fix_1035 : Text
fix_1035 =
use Text ++
"aaaaaaaaaaaaaaaaaaaaaa"
++ "bbbbbbbbbbbbbbbbbbbbbb"
"aaaaaaaaaaaaaaaaaaaaaa" ++ "bbbbbbbbbbbbbbbbbbbbbb"
++ "cccccccccccccccccccccc"
++ "dddddddddddddddddddddd"
Expand Down Expand Up @@ -665,15 +664,7 @@ softhang28 =
n ->
forkAt
0
(n
Nat.+ n
Nat.+ n
Nat.+ n
Nat.+ n
Nat.+ n
Nat.+ n
Nat.+ n
Nat.+ n
(n Nat.+ n Nat.+ n Nat.+ n Nat.+ n Nat.+ n Nat.+ n Nat.+ n Nat.+ n
Nat.+ n
Nat.+ n)
Expand All @@ -693,18 +684,7 @@ softhang_b x =
a = 1
b = 2
softhang
(100
+ 200
+ 300
+ 400
+ 500
+ 600
+ 700
+ 800
+ 900
+ 1000
+ 1100
+ 1200
(100 + 200 + 300 + 400 + 500 + 600 + 700 + 800 + 900 + 1000 + 1100 + 1200
+ 1300
+ 1400
+ 1500)
Expand Down

0 comments on commit 8a70414

Please sign in to comment.