mirror of
https://github.com/ilyakooo0/ormolu.git
synced 2024-10-27 11:41:17 +03:00
Handle “prefixed blocks” when they go after an operator
The change is obvious from the examples.
This commit is contained in:
parent
99a345b919
commit
f937aa7aaf
@ -20,3 +20,9 @@ baz = do
|
||||
bar c
|
||||
let d = c + 2
|
||||
return d
|
||||
|
||||
quux =
|
||||
something $ do
|
||||
foo
|
||||
bar
|
||||
baz
|
||||
|
@ -16,3 +16,8 @@ baz = do
|
||||
bar c
|
||||
let d = c + 2
|
||||
return d
|
||||
|
||||
quux = something $ do
|
||||
foo
|
||||
bar
|
||||
baz
|
||||
|
@ -55,10 +55,8 @@ p_pat = \case
|
||||
Nothing -> txt ".."
|
||||
Just x -> located x p_hsRecField
|
||||
inci . braces . velt . withSep comma f $ case dotdot of
|
||||
Nothing ->
|
||||
Just <$> fields
|
||||
Just n -> do
|
||||
(Just <$> take n fields) ++ [Nothing]
|
||||
Nothing -> Just <$> fields
|
||||
Just n -> (Just <$> take n fields) ++ [Nothing]
|
||||
InfixCon x y -> do
|
||||
located x p_pat
|
||||
space
|
||||
|
@ -231,7 +231,9 @@ p_hsExpr = \case
|
||||
located x p_hsExpr
|
||||
space
|
||||
located op p_hsExpr
|
||||
breakpoint
|
||||
if isPrefixBlockExpr (unL y)
|
||||
then space
|
||||
else breakpoint
|
||||
inci (located y p_hsExpr)
|
||||
NegApp NoExt e _ -> do
|
||||
txt "-"
|
||||
@ -437,10 +439,14 @@ getGRHSSpan (XGRHS NoExt) = notImplemented "XGRHS"
|
||||
-- case expressions.
|
||||
|
||||
isPrefixBlock :: [LGRHS GhcPs (LHsExpr GhcPs)] -> Bool
|
||||
isPrefixBlock [(L _ (GRHS NoExt _ (L _ e)))] =
|
||||
case e of
|
||||
HsLam NoExt _ -> True
|
||||
HsDo NoExt _ _ -> True
|
||||
HsLamCase NoExt _ -> True
|
||||
_ -> False
|
||||
isPrefixBlock [(L _ (GRHS NoExt _ (L _ e)))] = isPrefixBlockExpr e
|
||||
isPrefixBlock _ = False
|
||||
|
||||
-- | Similar to 'isPrefixBlock', but just for checking 'HsExpr' directly.
|
||||
|
||||
isPrefixBlockExpr :: HsExpr GhcPs -> Bool
|
||||
isPrefixBlockExpr = \case
|
||||
HsLam NoExt _ -> True
|
||||
HsDo NoExt _ _ -> True
|
||||
HsLamCase NoExt _ -> True
|
||||
_ -> False
|
||||
|
Loading…
Reference in New Issue
Block a user