From 92cf6eecf90c6c525cbc609b1b651f8cb7f2fbb4 Mon Sep 17 00:00:00 2001 From: John Wiegley Date: Fri, 18 Jul 2014 04:42:06 -0500 Subject: [PATCH] Switch from pretty to ansi-wl-pprint --- Nix.hs | 5 +++-- Nix/Pretty.hs | 27 +++++++++++++-------------- default.nix | 3 +-- hnix.cabal | 2 -- 4 files changed, 17 insertions(+), 20 deletions(-) diff --git a/Nix.hs b/Nix.hs index dfeefd9..9ce67fe 100644 --- a/Nix.hs +++ b/Nix.hs @@ -5,8 +5,9 @@ import Nix.Eval import Nix.Parser import Nix.Pretty import Nix.Types -import Text.PrettyPrint.HughesPJ +import Text.PrettyPrint.ANSI.Leijen import System.Environment +import System.IO nix :: FilePath -> IO () nix path = do @@ -14,7 +15,7 @@ nix path = do case res of Failure e -> error $ "Parse failed: " ++ show e Success n -> do - putStrLn $ render (prettyNix n) + displayIO stdout $ renderPretty 0.4 80 (prettyNix n) top <- evalExpr n (Fix (NVSet Map.empty)) -- evaluate top level print top diff --git a/Nix/Pretty.hs b/Nix/Pretty.hs index b86de93..66fbc30 100644 --- a/Nix/Pretty.hs +++ b/Nix/Pretty.hs @@ -1,9 +1,9 @@ module Nix.Pretty where -import Text.PrettyPrint.HughesPJ -import Nix.Types import Data.Map (toList) import Data.Text (Text, unpack) +import Nix.Types +import Text.PrettyPrint.ANSI.Leijen prettyBind :: (NExpr, NExpr) -> Doc prettyBind (n, v) = prettyNix n <+> equals <+> prettyNix v <> semi @@ -39,32 +39,31 @@ prettyOper (NDiv r1 r2) = infixOper r1 "/" r2 prettyOper (NConcat r1 r2) = infixOper r1 "++" r2 prettyAtom :: NAtom -> Doc -prettyAtom (NStr s) = doubleQuotes $ text $ unpack $ s +prettyAtom (NStr s) = dquotes $ text $ unpack s prettyAtom atom = text $ unpack $ atomText atom prettyNix :: NExpr -> Doc prettyNix (Fix expr) = go expr where go (NConstant atom) = prettyAtom atom - go (NOper oper) = prettyOper oper - go (NList list) = lbrack <+> (fsep $ map prettyNix list) <+> rbrack + go (NOper oper) = prettyOper oper + go (NList xs) = lbracket <+> fillSep (map prettyNix xs) <+> rbracket - go (NArgSet args) = lbrace <+> (vcat $ map prettySetArg $ toList args) <+> rbrace + go (NArgSet args) = lbrace <+> vcat (map prettySetArg $ toList args) <+> rbrace - go (NSet rec list) = + go (NSet rec xs) = (case rec of Rec -> "rec"; NonRec -> empty) - <+> lbrace <+> (vcat $ map prettyBind list) <+> rbrace + <+> lbrace <+> vcat (map prettyBind xs) <+> rbrace - go (NLet binds body) = text "let" + go (NLet _binds _body) = text "let" go (NIf cond trueBody falseBody) = (text "if" <+> prettyNix cond) - $$ (text "then" <+> prettyNix trueBody) - $$ (text "else" <+> prettyNix falseBody) + <$$> (text "then" <+> prettyNix trueBody) + <$$> (text "else" <+> prettyNix falseBody) go (NWith scope body) = text "with" <+> prettyNix scope <> semi <+> prettyNix body go (NAssert cond body) = text "assert" <+> prettyNix cond <> semi <+> prettyNix body - go (NInherit attrs) = text "inherit" + go (NInherit _attrs) = text "inherit" go (NVar e) = prettyNix e go (NApp fun arg) = prettyNix fun <+> parens (prettyNix arg) - go (NAbs args body) = (prettyNix args <> colon) $$ prettyNix body - + go (NAbs args body) = (prettyNix args <> colon) <$$> prettyNix body diff --git a/default.nix b/default.nix index 55eb007..7ec70d0 100644 --- a/default.nix +++ b/default.nix @@ -1,5 +1,5 @@ { cabal, parsers, trifecta, text, ansiWlPprint, parsec, transformers -, pretty, useParsec ? true +, useParsec ? true }: cabal.mkDerivation (self: rec { @@ -11,7 +11,6 @@ cabal.mkDerivation (self: rec { noHaddock = true; buildDepends = [ ansiWlPprint - pretty text transformers ] ++ (if useParsec then [ parsec ] else [ parsers trifecta ]); diff --git a/hnix.cabal b/hnix.cabal index 9bbc8ef..5ed20ce 100644 --- a/hnix.cabal +++ b/hnix.cabal @@ -45,7 +45,6 @@ Library base >= 4.3 && < 5 , ansi-wl-pprint , containers - , pretty , text , transformers if flag(parsec) @@ -81,7 +80,6 @@ executable hnix , hnix , ansi-wl-pprint , containers - , pretty , text , transformers if flag(parsec)