Deny one layout for OpApp cases unless precedence<=1
Previously allowed: `foo = abc + def-as-par` Still allowed: `foo = abc $ def-as-par` Still allowed: `foo = abc <&> \x -> def-as-par`ghc92
parent
e7cdff440d
commit
7bf2879ac0
|
@ -329,11 +329,13 @@ func =
|
||||||
foooooooooooooooooooooooooooooooo
|
foooooooooooooooooooooooooooooooo
|
||||||
|
|
||||||
#test opapp-specialcasing-3
|
#test opapp-specialcasing-3
|
||||||
func = fooooooooooooooooooooooooooooooooo + foooooooooooooooooooooooooooooooo
|
func =
|
||||||
[ foooooooooooooooooooooooooooooooo
|
fooooooooooooooooooooooooooooooooo
|
||||||
, foooooooooooooooooooooooooooooooo
|
+ foooooooooooooooooooooooooooooooo
|
||||||
, foooooooooooooooooooooooooooooooo
|
[ foooooooooooooooooooooooooooooooo
|
||||||
]
|
, foooooooooooooooooooooooooooooooo
|
||||||
|
, foooooooooooooooooooooooooooooooo
|
||||||
|
]
|
||||||
|
|
||||||
#test opapp-indenting
|
#test opapp-indenting
|
||||||
parserPrim =
|
parserPrim =
|
||||||
|
@ -966,3 +968,8 @@ func =
|
||||||
)
|
)
|
||||||
<$> mylist
|
<$> mylist
|
||||||
)
|
)
|
||||||
|
|
||||||
|
#test operator newline behaviour
|
||||||
|
func =
|
||||||
|
fromIntegral aaaaaaaaaaaaaaaaaaa
|
||||||
|
/ fromIntegral (aaaaaaaaaaaaaaaaaaa + bbbbbbbbbbbbbbbbbb)
|
||||||
|
|
|
@ -1278,11 +1278,13 @@ func =
|
||||||
foooooooooooooooooooooooooooooooo
|
foooooooooooooooooooooooooooooooo
|
||||||
|
|
||||||
#test opapp-specialcasing-3
|
#test opapp-specialcasing-3
|
||||||
func = fooooooooooooooooooooooooooooooooo + foooooooooooooooooooooooooooooooo
|
func =
|
||||||
[ foooooooooooooooooooooooooooooooo
|
fooooooooooooooooooooooooooooooooo
|
||||||
, foooooooooooooooooooooooooooooooo
|
+ foooooooooooooooooooooooooooooooo
|
||||||
, foooooooooooooooooooooooooooooooo
|
[ foooooooooooooooooooooooooooooooo
|
||||||
]
|
, foooooooooooooooooooooooooooooooo
|
||||||
|
, foooooooooooooooooooooooooooooooo
|
||||||
|
]
|
||||||
|
|
||||||
#test opapp-indenting
|
#test opapp-indenting
|
||||||
parserPrim =
|
parserPrim =
|
||||||
|
|
|
@ -198,6 +198,9 @@ layoutOpTree allowSinglelinePar = \case
|
||||||
pure (pure op, subDoc)
|
pure (pure op, subDoc)
|
||||||
sharedOpsFlat <- flattenList docOps
|
sharedOpsFlat <- flattenList docOps
|
||||||
sharedOps <- simpleTransform docOps
|
sharedOps <- simpleTransform docOps
|
||||||
|
let lastWrap = if getPrec fixity <= 1
|
||||||
|
then docForceParSpacing
|
||||||
|
else docForceSingleline
|
||||||
coreAlternative hasParen
|
coreAlternative hasParen
|
||||||
locO
|
locO
|
||||||
locC
|
locC
|
||||||
|
@ -205,11 +208,12 @@ layoutOpTree allowSinglelinePar = \case
|
||||||
docL
|
docL
|
||||||
sharedOps
|
sharedOps
|
||||||
sharedOpsFlat
|
sharedOpsFlat
|
||||||
docForceParSpacing
|
lastWrap
|
||||||
OpLeaf l -> pure l
|
OpLeaf l -> pure l
|
||||||
where
|
where
|
||||||
isPrec0 = \case
|
isPrec0 x = getPrec x == 0
|
||||||
Fixity _ prec _ -> prec == 0
|
getPrec = \case
|
||||||
|
Fixity _ prec _ -> prec
|
||||||
coreAlternative
|
coreAlternative
|
||||||
:: Bool
|
:: Bool
|
||||||
-> Maybe GHC.RealSrcLoc
|
-> Maybe GHC.RealSrcLoc
|
||||||
|
@ -268,33 +272,35 @@ layoutOpTree allowSinglelinePar = \case
|
||||||
$ wrapParenIfSl hasParen
|
$ wrapParenIfSl hasParen
|
||||||
$ docSetParSpacing
|
$ docSetParSpacing
|
||||||
$ docSeq
|
$ docSeq
|
||||||
([docForceSingleline docL] ++ case splitFirstLast sharedOpsFlat of
|
([docForceSingleline docL] ++ case splitFirstLast sharedOpsFlat of
|
||||||
FirstLastEmpty -> []
|
FirstLastEmpty -> []
|
||||||
FirstLastSingleton (od, ed) ->
|
FirstLastSingleton (od, ed) ->
|
||||||
[docSeparator, docForceSingleline od, docSeparator, lastWrap ed]
|
[ docSeparator
|
||||||
FirstLast (od1, ed1) ems (odN, edN) ->
|
, docForceSingleline od
|
||||||
( [ docSeparator
|
, docSeparator
|
||||||
, docForceSingleline od1
|
, lastWrap ed
|
||||||
, docSeparator
|
]
|
||||||
, docForceSingleline ed1
|
FirstLast (od1, ed1) ems (odN, edN) ->
|
||||||
]
|
( [ docSeparator
|
||||||
++ join
|
, docForceSingleline od1
|
||||||
[ [ docSeparator
|
|
||||||
, docForceSingleline od
|
|
||||||
, docSeparator
|
, docSeparator
|
||||||
, docForceSingleline ed
|
, docForceSingleline ed1
|
||||||
]
|
]
|
||||||
| (od, ed) <- ems
|
++ join
|
||||||
]
|
[ [ docSeparator
|
||||||
++ [ docSeparator
|
, docForceSingleline od
|
||||||
, docForceSingleline odN
|
, docSeparator
|
||||||
, docSeparator
|
, docForceSingleline ed
|
||||||
, lastWrap edN
|
]
|
||||||
]
|
| (od, ed) <- ems
|
||||||
|
]
|
||||||
|
++ [ docSeparator
|
||||||
|
, docForceSingleline odN
|
||||||
|
, docSeparator
|
||||||
|
, lastWrap edN
|
||||||
|
]
|
||||||
|
)
|
||||||
)
|
)
|
||||||
)
|
|
||||||
-- this case rather leads to some unfortunate layouting than to anything
|
|
||||||
-- useful; disabling for now. (it interfers with cols stuff.)
|
|
||||||
-- one
|
-- one
|
||||||
-- + two
|
-- + two
|
||||||
-- + three
|
-- + three
|
||||||
|
@ -308,15 +314,14 @@ layoutOpTree allowSinglelinePar = \case
|
||||||
IndentPolicyMultiple -> docForceSingleline
|
IndentPolicyMultiple -> docForceSingleline
|
||||||
IndentPolicyFree -> id
|
IndentPolicyFree -> id
|
||||||
let curIsPrec0 = case fixity of
|
let curIsPrec0 = case fixity of
|
||||||
Nothing -> False
|
Nothing -> False
|
||||||
Just (Fixity _ prec _) -> prec == 0
|
Just (Fixity _ prec _) -> prec == 0
|
||||||
case sharedOps of
|
case sharedOps of
|
||||||
[(od, ed)] | curIsPrec0 ->
|
[(od, ed)] | curIsPrec0 ->
|
||||||
addAlternativeCond (not hasParen && isSingleOp)
|
addAlternativeCond (not hasParen && isSingleOp)
|
||||||
$ docSetParSpacing
|
$ docSetParSpacing
|
||||||
$ docPar
|
$ docPar (docHandleComms locO $ docForceSingleline $ docL)
|
||||||
(docHandleComms locO $ docForceSingleline $ docL)
|
(docSeq [od, docSeparator, singlelineUnlessFree ed])
|
||||||
(docSeq [od, docSeparator, singlelineUnlessFree ed])
|
|
||||||
_ -> pure ()
|
_ -> pure ()
|
||||||
-- > ( one
|
-- > ( one
|
||||||
-- > + two
|
-- > + two
|
||||||
|
@ -334,9 +339,9 @@ layoutOpTree allowSinglelinePar = \case
|
||||||
-- > + three
|
-- > + three
|
||||||
addAlternative
|
addAlternative
|
||||||
$ wrapParenMlIf
|
$ wrapParenMlIf
|
||||||
hasParen
|
hasParen
|
||||||
-- ((if not hasParen then docAddBaseY BrIndentRegular else id) docL)
|
-- ((if not hasParen then docAddBaseY BrIndentRegular else id) docL)
|
||||||
(if hasParen then docSetBaseY docL else docL)
|
(if hasParen then docSetBaseY docL else docL)
|
||||||
((if hasParen then sharedOps else sharedOpsFlat) <&> \(od, ed) ->
|
((if hasParen then sharedOps else sharedOpsFlat) <&> \(od, ed) ->
|
||||||
docCols ColOpPrefix [appSep od, docSetBaseY ed]
|
docCols ColOpPrefix [appSep od, docSetBaseY ed]
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in New Issue