From 8ea220ea4fdbca5e763440b3ffb2341200c788f1 Mon Sep 17 00:00:00 2001 From: Luca Bruno Date: Mon, 7 Jul 2014 11:29:25 +0200 Subject: [PATCH] Use a type to express rec sets instead of a bool --- Nix/Parser.hs | 2 +- Nix/Types.hs | 12 +++++++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/Nix/Parser.hs b/Nix/Parser.hs index c25ac43..34db9aa 100644 --- a/Nix/Parser.hs +++ b/Nix/Parser.hs @@ -149,7 +149,7 @@ setOrArgs = do then return True else try (lookAhead lookaheadForSet) if haveSet - then braces (Fix . NSet sawRec <$> nixBinders) "set" + then braces (Fix . NSet (if sawRec then Rec else NonRec) <$> nixBinders) "set" else do args <- argExpr "arguments" symbolic ':' *> fmap Fix (NAbs <$> pure args <*> nixApp) diff --git a/Nix/Types.hs b/Nix/Types.hs index 7bb1ff9..dd03460 100644 --- a/Nix/Types.hs +++ b/Nix/Types.hs @@ -92,6 +92,13 @@ instance Show f => Show (NOperF f) where show (NConcat r1 r2) = show r1 ++ " ++ " ++ show r2 +data NSetBind = Rec | NonRec + deriving (Ord, Eq, Generic, Typeable, Data) + +instance Show NSetBind where + show Rec = "rec" + show NonRec = "" + data NExprF r = NConstant NAtom @@ -100,7 +107,7 @@ data NExprF r | NList [r] -- ^ A "concat" is a list of things which must combine to form a string. | NArgSet (Map Text (Maybe r)) - | NSet Bool [(r, r)] + | NSet NSetBind [(r, r)] | NLet [(r, r)] r | NIf r r r @@ -139,8 +146,7 @@ instance Show f => Show (NExprF f) where showArg (k, Nothing) = unpack k showArg (k, Just v) = unpack k ++ " ? " ++ show v - show (NSet b xs) = (if b then "rec " else "") - ++ "{ " ++ concatMap go xs ++ " }" + show (NSet b xs) = show b ++ " { " ++ concatMap go xs ++ " }" where go (k, v) = show k ++ " = " ++ show v ++ "; "