Fix printing of ifs with multiline conditions

Pretty-printing ifs with multiline conditions previously would not break
the line before the then, leading to roundtripping errors. For example:
```
if
  a = b
  a
then foo
else bar
```
would print as:
```
if
  a = b
  a then foo else bar
```

This fixes the term printer to add a new case for when the condition is
multiline.
This commit is contained in:
Nicole Prindle 2022-01-20 17:57:15 -05:00
parent 3336bbbb43
commit ca6dd75a66
No known key found for this signature in database
GPG Key ID: 56E908E54EC7B88E

View File

@ -263,14 +263,20 @@ pretty0
<> optSpace <> (fmt S.DelimiterChar $ l "]")
where optSpace = PP.orElse "" " "
If' cond t f -> paren (p >= 2) $
if PP.isMultiLine pt || PP.isMultiLine pf then PP.lines [
(fmt S.ControlKeyword "if ") <> pcond <> (fmt S.ControlKeyword " then") `PP.hang` pt,
(fmt S.ControlKeyword "else") `PP.hang` pf
]
else PP.spaced [
((fmt S.ControlKeyword "if") `PP.hang` pcond) <> ((fmt S.ControlKeyword " then") `PP.hang` pt),
if PP.isMultiLine pcond then PP.lines [
(fmt S.ControlKeyword "if") `PP.hang` pcond,
(fmt S.ControlKeyword "then") `PP.hang` pt,
(fmt S.ControlKeyword "else") `PP.hang` pf
]
else
if PP.isMultiLine pt || PP.isMultiLine pf then PP.lines [
(fmt S.ControlKeyword "if ") <> pcond <> (fmt S.ControlKeyword " then") `PP.hang` pt,
(fmt S.ControlKeyword "else") `PP.hang` pf
]
else PP.spaced [
((fmt S.ControlKeyword "if") `PP.hang` pcond) <> ((fmt S.ControlKeyword " then") `PP.hang` pt),
(fmt S.ControlKeyword "else") `PP.hang` pf
]
where
pcond = pretty0 n (ac 2 Block im doc) cond
pt = branch t