parent
dddfb1a8ea
commit
e177d9bdfa
|
@ -382,26 +382,49 @@ prettyExprB a0@(Lam _ _ _) = arrows (fmap duplicate (docs a0))
|
|||
docs (Note _ c) = docs c
|
||||
docs c = [ prettyExprB c ]
|
||||
prettyExprB a0@(BoolIf _ _ _) =
|
||||
enclose' "" " " (space <> keyword "else" <> space) (Pretty.hardline <> keyword "else" <> " ") (fmap duplicate (docs a0))
|
||||
Pretty.group (Pretty.flatAlt long short)
|
||||
where
|
||||
docs (BoolIf a b c) =
|
||||
Pretty.group (Pretty.flatAlt long short) : docs c
|
||||
where
|
||||
long =
|
||||
Pretty.align
|
||||
( (keyword "if" <> " ")
|
||||
<> prettyExprA a
|
||||
<> Pretty.hardline
|
||||
<> (keyword "then" <> " ")
|
||||
<> prettyExprA b
|
||||
)
|
||||
prefixesLong =
|
||||
" "
|
||||
: cycle
|
||||
[ Pretty.hardline <> keyword "then" <> " "
|
||||
, Pretty.hardline <> keyword "else" <> " "
|
||||
]
|
||||
|
||||
prefixesShort =
|
||||
""
|
||||
: cycle
|
||||
[ space <> keyword "then" <> space
|
||||
, space <> keyword "else" <> space
|
||||
]
|
||||
|
||||
longLines = zipWith (<>) prefixesLong (docsLong a0)
|
||||
|
||||
long =
|
||||
Pretty.align (mconcat (Data.List.intersperse Pretty.hardline longLines))
|
||||
|
||||
short = mconcat (zipWith (<>) prefixesShort (docsShort a0))
|
||||
|
||||
docsLong (BoolIf a b c) =
|
||||
docLong ++ docsLong c
|
||||
where
|
||||
docLong =
|
||||
[ keyword "if" <> " " <> prettyExprA a
|
||||
, prettyExprA b
|
||||
]
|
||||
docsLong (Note _ c) = docsLong c
|
||||
docsLong c = [ prettyExprB c ]
|
||||
|
||||
docsShort (BoolIf a b c) =
|
||||
docShort ++ docsShort c
|
||||
where
|
||||
docShort =
|
||||
[ keyword "if" <> " " <> prettyExprA a
|
||||
, prettyExprA b
|
||||
]
|
||||
docsShort (Note _ c) = docsShort c
|
||||
docsShort c = [ prettyExprB c ]
|
||||
|
||||
short = (keyword "if" <> " ")
|
||||
<> prettyExprA a
|
||||
<> (space <> keyword "then" <> space)
|
||||
<> prettyExprA b
|
||||
docs (Note _ c) = docs c
|
||||
docs c = [ prettyExprB c ]
|
||||
prettyExprB a0@(Pi _ _ _) =
|
||||
arrows (fmap duplicate (docs a0))
|
||||
where
|
||||
|
|
|
@ -36,6 +36,9 @@ formatTests =
|
|||
, should
|
||||
"correctly format the empty record literal"
|
||||
"emptyRecord"
|
||||
, should
|
||||
"indent then/else to the same column"
|
||||
"ifThenElse"
|
||||
]
|
||||
|
||||
opts :: Data.Text.Prettyprint.Doc.LayoutOptions
|
||||
|
|
2
tests/format/ifThenElseA.dhall
Normal file
2
tests/format/ifThenElseA.dhall
Normal file
|
@ -0,0 +1,2 @@
|
|||
if True then if True then if True then 1 else 2 else if True then 3 else 4
|
||||
else if True then if True then 5 else 6 else if True then 7 else 8
|
13
tests/format/ifThenElseB.dhall
Normal file
13
tests/format/ifThenElseB.dhall
Normal file
|
@ -0,0 +1,13 @@
|
|||
if True
|
||||
|
||||
then if True then if True then 1 else 2 else if True then 3 else 4
|
||||
|
||||
else if True
|
||||
|
||||
then if True then 5 else 6
|
||||
|
||||
else if True
|
||||
|
||||
then 7
|
||||
|
||||
else 8
|
Loading…
Reference in New Issue
Block a user