Add several more JSON related instances
This commit is contained in:
parent
d8828bfe56
commit
a21d88657a
|
@ -27,6 +27,7 @@ import Codec.Serialise (Serialise)
|
|||
import qualified Codec.Serialise as Ser
|
||||
import Control.DeepSeq
|
||||
import Data.Aeson
|
||||
import Data.Aeson.TH
|
||||
import Data.Binary (Binary)
|
||||
import qualified Data.Binary as Bin
|
||||
import Data.Data
|
||||
|
@ -232,6 +233,7 @@ instance Generic1 NKeyName where
|
|||
type Rep1 NKeyName = NKeyName -- jww (2018-04-09): wrong
|
||||
from1 = id
|
||||
to1 = id
|
||||
|
||||
instance NFData1 NKeyName where
|
||||
liftRnf _ (StaticKey !_ !_) = ()
|
||||
liftRnf _ (DynamicKey (Plain !_)) = ()
|
||||
|
@ -338,6 +340,13 @@ $(deriveShow1 ''Binding)
|
|||
$(deriveShow1 ''Antiquoted)
|
||||
$(deriveShow2 ''Antiquoted)
|
||||
|
||||
-- $(deriveJSON1 defaultOptions ''NExprF)
|
||||
$(deriveJSON1 defaultOptions ''NString)
|
||||
$(deriveJSON1 defaultOptions ''Params)
|
||||
-- $(deriveJSON1 defaultOptions ''Binding)
|
||||
$(deriveJSON1 defaultOptions ''Antiquoted)
|
||||
$(deriveJSON2 defaultOptions ''Antiquoted)
|
||||
|
||||
instance (Binary v, Binary a) => Binary (Antiquoted v a)
|
||||
instance Binary a => Binary (NString a)
|
||||
instance Binary a => Binary (Binding a)
|
||||
|
|
|
@ -21,13 +21,14 @@ module Nix.Expr.Types.Annotated
|
|||
|
||||
import Codec.Serialise
|
||||
import Control.DeepSeq
|
||||
import Data.Aeson (ToJSON(..), FromJSON(..))
|
||||
import Data.Aeson.TH
|
||||
import Data.Binary (Binary(..))
|
||||
import Data.Data
|
||||
import Data.Eq.Deriving
|
||||
import Data.Fix
|
||||
import Data.Function (on)
|
||||
import Data.Functor.Compose
|
||||
import Data.List.NonEmpty
|
||||
import Data.Hashable
|
||||
import Data.Hashable.Lifted
|
||||
import Data.Ord.Deriving
|
||||
|
@ -57,8 +58,8 @@ data Ann ann a = Ann
|
|||
, annotated :: a
|
||||
}
|
||||
deriving (Ord, Eq, Data, Generic, Generic1, Typeable, Functor, Foldable,
|
||||
Traversable, Read, Show, NFData, NFData1, NFData2, Serialise,
|
||||
Hashable, Hashable1, Hashable2)
|
||||
Traversable, Read, Show, NFData, NFData1, Serialise,
|
||||
Hashable, Hashable1)
|
||||
|
||||
$(deriveEq1 ''Ann)
|
||||
$(deriveEq2 ''Ann)
|
||||
|
@ -68,6 +69,8 @@ $(deriveRead1 ''Ann)
|
|||
$(deriveRead2 ''Ann)
|
||||
$(deriveShow1 ''Ann)
|
||||
$(deriveShow2 ''Ann)
|
||||
$(deriveJSON1 defaultOptions ''Ann)
|
||||
$(deriveJSON2 defaultOptions ''Ann)
|
||||
|
||||
instance Semigroup SrcSpan where
|
||||
s1 <> s2 = SrcSpan ((min `on` spanBegin) s1 s2)
|
||||
|
@ -92,6 +95,9 @@ instance (Binary ann, Binary a) => Binary (Ann ann a)
|
|||
instance Binary r => Binary (NExprLocF r)
|
||||
instance Binary NExprLoc
|
||||
|
||||
instance ToJSON SrcSpan
|
||||
instance FromJSON SrcSpan
|
||||
|
||||
instance Serialise r => Serialise (Compose (Ann SrcSpan) NExprF r) where
|
||||
encode (Compose (Ann ann a)) = encode ann <> encode a
|
||||
decode = (Compose .) . Ann <$> decode <*> decode
|
||||
|
|
Loading…
Reference in a new issue