Skip to content

Commit 607e00f

Browse files
committed
Pretty: precedenceWrap: m refactor
1 parent c140222 commit 607e00f

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

src/Nix/Pretty.hs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -89,25 +89,26 @@ hasAttrOp = getSpecialOperator NHasAttrOp
8989
-- | Determine if to return doc wraped into parens,
9090
-- according the given operator.
9191
precedenceWrap :: OperatorInfo -> NixDoc ann -> Doc ann
92-
precedenceWrap op sub =
93-
maybeWrap (getDoc sub)
92+
precedenceWrap op subExpr =
93+
maybeWrap $ getDoc subExpr
9494
where
9595
maybeWrap :: Doc ann -> Doc ann
9696
maybeWrap =
9797
bool
9898
parens
9999
id
100100
needsParens
101+
where
102+
needsParens :: Bool
103+
needsParens =
104+
precedence root < precedence op
105+
|| ( precedence root == precedence op
106+
&& associativity root == associativity op
107+
&& associativity op /= NAssocNone
108+
)
101109

102-
root = rootOp sub
110+
root = rootOp subExpr
103111

104-
needsParens :: Bool
105-
needsParens =
106-
precedence root < precedence op
107-
|| (precedence root == precedence op
108-
&& associativity root == associativity op
109-
&& associativity op /= NAssocNone
110-
)
111112

112113
-- Used in the selector case to print a path in a selector as
113114
-- "${./abc}"

0 commit comments

Comments
 (0)