@@ -21,17 +21,19 @@ import Data.Data hiding (Infix, Prefix)
21import Data.List (intersperse, sortOn)
21import Data.List (intersperse, sortOn)
22import Data.List.NonEmpty (NonEmpty ((:|)))
22import Data.List.NonEmpty (NonEmpty ((:|)))
23import Data.Text (Text)
23import Data.Text (Text)
24−import qualified Data.Text as Text
25+import OccName (mkVarOcc)
26import Ormolu.Printer.Combinators
26import Ormolu.Printer.Combinators
27import Ormolu.Printer.Meat.Common
27import Ormolu.Printer.Meat.Common
28import Ormolu.Printer.Meat.Declaration.Signature
28import Ormolu.Printer.Meat.Declaration.Signature
29import Ormolu.Printer.Meat.Type
29import Ormolu.Printer.Meat.Type
30import Ormolu.Printer.Operators
30import Ormolu.Printer.Operators
31import Ormolu.Utils
31import Ormolu.Utils
32+import RdrName (RdrName (..))
32import RdrName (rdrNameOcc)
33import RdrName (rdrNameOcc)
33import SrcLoc (combineSrcSpans, isOneLineSpan)
34import SrcLoc (combineSrcSpans, isOneLineSpan)
34import qualified Data.List.NonEmpty as NE
35import qualified Data.List.NonEmpty as NE
36+import qualified Data.Text as Text
35import {-# SOURCE #-} Ormolu.Printer.Meat.Declaration
37import {-# SOURCE #-} Ormolu.Printer.Meat.Declaration
37-- | Style of a group of equations.
39-- | Style of a group of equations.
@@ -549,10 +551,7 @@ p_hsExpr' s = \case
549 located (hswc_body a) p_hsType
551 located (hswc_body a) p_hsType
550 OpApp NoExt x op y -> do
552 OpApp NoExt x op y -> do
551 let opTree = OpBranch (exprOpTree x) op (exprOpTree y)
553 let opTree = OpBranch (exprOpTree x) op (exprOpTree y)
553− HsVar NoExt (L _ a) -> Just a
555− p_exprOpTree s (reassociateOpTree getOpName opTree)
554+ p_exprOpTree True s (reassociateOpTree getOpName opTree)
556 NegApp NoExt e _ -> do
555 NegApp NoExt e _ -> do
@@ -1145,9 +1144,18 @@ exprOpTree :: LHsExpr GhcPs -> OpTree (LHsExpr GhcPs) (LHsExpr GhcPs)
1145exprOpTree (L _ (OpApp NoExt x op y)) = OpBranch (exprOpTree x) op (exprOpTree y)
1144exprOpTree (L _ (OpApp NoExt x op y)) = OpBranch (exprOpTree x) op (exprOpTree y)
1146exprOpTree n = OpNode n
1145exprOpTree n = OpNode n
1147+getOpName :: HsExpr GhcPs -> Maybe RdrName
1149+ HsVar NoExt (L _ a) -> Just a
1153+ :: Bool -- ^ Can use special handling of dollar?
1154+ -> BracketStyle -- ^ Bracket style to use
1148−p_exprOpTree :: BracketStyle -> OpTree (LHsExpr GhcPs) (LHsExpr GhcPs) -> R ()
1155+ -> OpTree (LHsExpr GhcPs) (LHsExpr GhcPs)
1149−p_exprOpTree s (OpNode x) = located x (p_hsExpr' s)
1157+p_exprOpTree _ s (OpNode x) = located x (p_hsExpr' s)
1150−p_exprOpTree s (OpBranch x op y) = do
1158+p_exprOpTree isDollarSpecial s (OpBranch x op y) = do
1151 -- NOTE If the beginning of the first argument and the second argument
1159 -- NOTE If the beginning of the first argument and the second argument
1152 -- are on the same line, and the second argument has a hanging form, use
1160 -- are on the same line, and the second argument has a hanging form, use
1153 -- hanging placement.
1161 -- hanging placement.
@@ -1167,13 +1175,24 @@ p_exprOpTree s (OpBranch x op y) = do
1167 MultiLine -> case placement of
1175 MultiLine -> case placement of
1168 Hanging -> useBraces
1176 Hanging -> useBraces
1169 Normal -> dontUseBraces
1177 Normal -> dontUseBraces
1178+ gotDollar = case getOpName (unLoc op) of
1179+ Just rname -> mkVarOcc "$" == (rdrNameOcc rname)
1170 switchLayout [opTreeLoc x] $
1181 switchLayout [opTreeLoc x] $
1171− ub $ p_exprOpTree s x
1182+ ub $ p_exprOpTree (not gotDollar) s x
1172− placeHanging placement $ do
1173− located op (opWrapper . p_hsExpr)
1183+ let p_op = located op (opWrapper . p_hsExpr)
1175− switchLayout [opTreeLoc y] $
1184+ p_y = switchLayout [opTreeLoc y] (p_exprOpTree True N y)
1176− p_exprOpTree N y
1185+ if isDollarSpecial && gotDollar && placement == Normal && isOneLineSpan (opTreeLoc x)
1192+ placeHanging placement $ do
1178-- | Get annotations for the enclosing element.
1197-- | Get annotations for the enclosing element.