Update OpApp layouting options

- Allow par-spacing for single-operator 1+n-line layout
- Tweak when to flatten operators, i.e. when to allow a flat one-line-each
  layout for the operator sequence "$ $ $ + +".
ghc92
Lennart Spitzner 2023-04-21 12:22:30 +00:00
parent 99e5aacb5e
commit 7ab6a207ae
4 changed files with 34 additions and 15 deletions

View File

@ -2,13 +2,10 @@
#test monad-comprehension-case-of
func =
foooooo
$ [ case
foooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo
of
_ -> True
]
func = foooooo
$ [ case foooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo of
_ -> True
]
#test operatorprefixalignment-even-with-multiline-alignbreak
func =

View File

@ -164,12 +164,14 @@ doop =
#expected
-- brittany { lconfig_fixityBasedAddAlignParens: True }
doop =
( some long invocation == loooooooooongman + (third nested expression) - 4
( ( some long invocation == loooooooooongman + (third nested expression) - 4
&& {- meow -} 5 - 6 > 7 `mod` loooooooooongwoman
)
|| ill just invoke a function with these args
|| ( foo
&& dooasdoiaosdoi ** oaisdoioasido
&& ( dooasdoiaosdoi ** oaisdoioasido
<= asduiuaisduiasdu + asdahjsd + ahsjdhjhasd
)
)
)

View File

@ -319,10 +319,9 @@ parserCompactLocation =
]
#test opapp-specialcasing-1
func =
fooooooooooooooooooooooooooooooooo
$ foooooooooooooooooooooooooooooooo foooooooooooooooooooooooooooooooo
foooooooooooooooooooooooooooooooo
func = fooooooooooooooooooooooooooooooooo
$ foooooooooooooooooooooooooooooooo foooooooooooooooooooooooooooooooo
foooooooooooooooooooooooooooooooo
#test opapp-specialcasing-2
func =

View File

@ -222,6 +222,7 @@ layoutOpTree allowSinglelinePar = \case
-> ToBriDocM BriDocNumbered
coreAlternative hasParen locO locC fixity docL sharedOps sharedOpsFlat lastWrap
= do
indentPolicy <- askLayoutConf _lconfig_indentPolicy
let wrapParenIfSl x inner = if x then wrapParenSl inner else docSetParSpacing inner
wrapParenSl inner = docAlt
[ docSeq
@ -253,6 +254,8 @@ layoutOpTree allowSinglelinePar = \case
Nothing -> False
Just (Fixity _ prec _) -> prec > 0
let isSingleOp = length sharedOps == 1 && length sharedOpsFlat == 1
runFilteredAlternative $ do
-- > one + two + three
-- or
@ -262,7 +265,7 @@ layoutOpTree allowSinglelinePar = \case
$ wrapParenIfSl hasParen
$ docSetParSpacing
$ docSeq
([docForceSingleline docL] ++ case splitFirstLast sharedOps of
([docForceSingleline docL] ++ case splitFirstLast sharedOpsFlat of
FirstLastEmpty -> []
FirstLastSingleton (od, ed) ->
[docSeparator, docForceSingleline od, docSeparator, lastWrap ed]
@ -289,11 +292,29 @@ layoutOpTree allowSinglelinePar = \case
)
-- this case rather leads to some unfortunate layouting than to anything
-- useful; disabling for now. (it interfers with cols stuff.)
addAlternativeCond (not hasParen) $ docPar
-- one
-- + two
-- + three
addAlternativeCond (not hasParen && not isSingleOp) $ docPar
(docHandleComms locO $ docForceSingleline $ docL)
(docFlushCommsPost False locC $ docLines $ sharedOps <&> \(od, ed) ->
docCols ColOpPrefix [appSep od, docForceSingleline ed]
)
let singlelineUnlessFree = case indentPolicy of
IndentPolicyLeft -> docForceSingleline
IndentPolicyMultiple -> docForceSingleline
IndentPolicyFree -> id
let curIsPrec0 = case fixity of
Nothing -> False
Just (Fixity _ prec _) -> prec == 0
case sharedOps of
[(od, ed)] | curIsPrec0 ->
addAlternativeCond (not hasParen && isSingleOp)
$ docSetParSpacing
$ docPar
(docHandleComms locO $ docForceSingleline $ docL)
(docSeq [od, docSeparator, singlelineUnlessFree ed])
_ -> pure ()
-- > ( one
-- > + two
-- > + three