Skip to content

Commit 1a3c8e2

Browse files
committed
Pretty: refactor
1 parent f3e6887 commit 1a3c8e2

File tree

1 file changed

+9
-12
lines changed

1 file changed

+9
-12
lines changed

src/Nix/Pretty.hs

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ import Nix.Parser
4141
import Nix.String
4242
import Nix.Thunk
4343
import Nix.Value
44-
import Prettyprinter
44+
import Prettyprinter hiding ( list )
4545
import Text.Read ( readMaybe )
4646
import Nix.Utils
4747

@@ -212,18 +212,12 @@ exprFNixDoc :: NExprF (NixDoc ann) -> NixDoc ann
212212
exprFNixDoc = \case
213213
NConstant atom -> prettyAtom atom
214214
NStr str -> simpleExpr $ prettyString str
215-
NList [] -> simpleExpr "[]"
216215
NList xs ->
217-
prettyContainer $
218-
["["] <> (wrapParens appOpNonAssoc <$> xs) <> ["]"]
219-
NSet NNonRecursive [] -> simpleExpr "{}"
216+
prettyContainer "[" (wrapParens appOpNonAssoc) "]" xs
220217
NSet NNonRecursive xs ->
221-
prettyContainer $
222-
["{"] <> (prettyBind <$> xs) <> ["}"]
223-
NSet NRecursive [] -> simpleExpr "rec {}"
218+
prettyContainer "{" prettyBind "}" xs
224219
NSet NRecursive xs ->
225-
prettyContainer $
226-
["rec {"] <> (prettyBind <$> xs) <> ["}"]
220+
prettyContainer "rec {" prettyBind "}" xs
227221
NAbs args body ->
228222
leastPrecedence $
229223
nest 2 $
@@ -302,8 +296,11 @@ exprFNixDoc = \case
302296
["assert " <> withoutParens cond <> ";", align $ withoutParens body]
303297
NSynHole name -> simpleExpr $ pretty ("^" <> name)
304298
where
305-
prettyContainer =
306-
simpleExpr . group . nest 2 . vsep
299+
prettyContainer h f t c =
300+
list
301+
(simpleExpr (h <> t))
302+
(const $ simpleExpr $ group $ nest 2 $ vsep $ [h] <> (f <$> c) <> [t])
303+
c
307304

308305

309306
valueToExpr :: forall t f m . MonadDataContext f m => NValue t f m -> NExpr

0 commit comments

Comments
 (0)