Handle “prefixed blocks” when they go after an operator

The change is obvious from the examples.
This commit is contained in:
mrkkrp 2019-06-06 22:07:40 +02:00 committed by Mark Karpov
parent 99a345b919
commit f937aa7aaf
4 changed files with 26 additions and 11 deletions

View File

@ -20,3 +20,9 @@ baz = do
bar c
let d = c + 2
return d
quux =
something $ do
foo
bar
baz

View File

@ -16,3 +16,8 @@ baz = do
bar c
let d = c + 2
return d
quux = something $ do
foo
bar
baz

View File

@ -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

View File

@ -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