hnix 0.3.2 → 0.3.3
raw patch · 3 files changed
+48/−11 lines, 3 filesdep +deriving-compatdep ~base
Dependencies added: deriving-compat
Dependency ranges changed: base
Files
- Nix/Expr/Types.hs +41/−6
- Nix/Expr/Types/Annotated.hs +4/−3
- hnix.cabal +3/−2
Nix/Expr/Types.hs view
@@ -6,6 +6,7 @@ {-# LANGUAGE DeriveFunctor #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE LambdaCase #-}+{-# LANGUAGE TemplateHaskell #-} -- | The nix expression type and supporting types. module Nix.Expr.Types where @@ -13,8 +14,8 @@ import Data.Data import Data.Fix import Data.Foldable-import Data.Functor.Classes (Show1(..))-import Data.Map (Map)+import Data.Functor.Classes (Show1(..), showsUnaryWith, liftShowsPrec2)+import Data.Map (Map, toList) import Data.Text (Text, pack) import Data.Traversable import GHC.Exts@@ -22,6 +23,7 @@ import Nix.Atoms import Prelude hiding (readFile, concat, concatMap, elem, mapM, sequence, minimum, foldr)+import Text.Show.Deriving -- | The main nix expression type. This is polymorphic so that it can be made -- a functor, which allows us to traverse expressions and map functions over@@ -72,14 +74,12 @@ -- ^ Assert that the first returns true before evaluating the second. deriving (Ord, Eq, Generic, Typeable, Data, Functor, Foldable, Traversable, Show) -instance Show1 NExprF where- showsPrec1 = showsPrec- -- | We make an `IsString` for expressions, where the string is interpreted -- as an identifier. This is the most common use-case... instance IsString NExpr where fromString = Fix . NSym . fromString + -- | The monomorphic expression type is a fixed point of the polymorphic one. type NExpr = Fix NExprF @@ -116,6 +116,27 @@ deriving (Ord, Eq, Generic, Typeable, Data, Functor, Show, Foldable, Traversable) +-- It's not possible to derive this automatically as there is no Show1 instance+-- for Map. We define one locally here.+instance Show1 ParamSet where+ liftShowsPrec sp sl p =+ let liftShowsPrecMap :: (Int -> a -> ShowS)+ -> ([a] -> ShowS)+ -> Int+ -> Map Text a+ -> ShowS+ liftShowsPrecMap spMap slMap pMap m =+ showsUnaryWith (liftShowsPrec (liftShowsPrec spMap slMap)+ (liftShowList spMap slMap))+ "fromList" pMap (Data.Map.toList m)+ showNamedMap s =+ showsUnaryWith (liftShowsPrecMap (liftShowsPrec sp sl)+ (liftShowList sp sl))+ s p+ in \case+ FixedParamSet m -> showNamedMap "FixedParamSet" m+ VariadicParamSet m -> showNamedMap "VariadicParamSet" m+ -- | 'Antiquoted' represents an expression that is either -- antiquoted (surrounded by ${...}) or plain (not antiquoted). data Antiquoted v r = Plain !v | Antiquoted !r@@ -166,8 +187,15 @@ instance IsString (NKeyName r) where fromString = StaticKey . fromString --- | Deriving this instance automatically is not possible because @r@+-- Deriving this instance automatically is not possible because @r@ -- occurs not only as last argument in @Antiquoted (NString r) r@+instance Show1 NKeyName where+ liftShowsPrec sp sl p = \case+ DynamicKey a -> showsUnaryWith (liftShowsPrec2 (liftShowsPrec sp sl) (liftShowList sp sl) sp sl) "DynamicKey" p a+ StaticKey t -> showsUnaryWith showsPrec "StaticKey" p t++-- Deriving this instance automatically is not possible because @r@+-- occurs not only as last argument in @Antiquoted (NString r) r@ instance Functor NKeyName where fmap = fmapDefault @@ -215,3 +243,10 @@ paramName :: Params r -> Maybe Text paramName (Param n) = Just n paramName (ParamSet _ n) = n++$(deriveShow1 ''NExprF)+$(deriveShow1 ''NString)+$(deriveShow1 ''Params)+$(deriveShow1 ''Binding)+$(deriveShow1 ''Antiquoted)+$(deriveShow2 ''Antiquoted)
Nix/Expr/Types/Annotated.hs view
@@ -7,6 +7,8 @@ {-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE LambdaCase #-} {-# LANGUAGE OverloadedStrings #-}+{-# LANGUAGE TemplateHaskell #-}+ -- | The source location annotated nix expression type and supporting types. -- module Nix.Expr.Types.Annotated@@ -18,7 +20,6 @@ import Data.Data import Data.Fix import Data.Function (on)-import Data.Functor.Classes (Show1(..)) import Data.Functor.Compose import Data.Semigroup import GHC.Generics@@ -26,6 +27,7 @@ import Nix.Parser.Library (Delta(..)) import Prelude hiding (concat, concatMap, elem, foldr, mapM, minimum, readFile, sequence)+import Text.Show.Deriving -- | A location in a source file data SrcSpan = SrcSpan{ spanBegin :: Delta@@ -42,8 +44,7 @@ } deriving (Ord, Eq, Data, Generic, Typeable, Functor, Foldable, Traversable, Read, Show) -instance Show ann => Show1 (Ann ann) where- showsPrec1 = showsPrec+$(deriveShow1 ''Ann) instance Semigroup SrcSpan where s1 <> s2 = SrcSpan ((min `on` spanBegin) s1 s2)
hnix.cabal view
@@ -1,5 +1,5 @@ Name: hnix-Version: 0.3.2+Version: 0.3.3 Synopsis: Haskell implementation of the Nix language Description: Haskell implementation of the Nix language.@@ -51,9 +51,10 @@ RankNTypes TupleSections Build-depends:- base >= 4.6 && < 5+ base >= 4.9 && < 5 , ansi-wl-pprint , containers+ , deriving-compat >= 0.3 && < 0.4 , text , transformers , parsers >= 0.10