never executed always true always false
    1 {-# LANGUAGE DeriveGeneric, DeriveDataTypeable, DeriveFunctor, DeriveTraversable, DeriveFoldable #-}
    2 
    3 module Conjure.Language.Expression.Op.AttributeAsConstraint where
    4 
    5 import Conjure.Prelude
    6 import Conjure.Language.Expression.Op.Internal.Common
    7 
    8 import qualified Data.Aeson as JSON             -- aeson
    9 import qualified Data.Aeson.KeyMap as KM
   10 
   11 import qualified Data.Vector as V               -- vector
   12 
   13 
   14 data OpAttributeAsConstraint x = OpAttributeAsConstraint x
   15                                                          AttrName   -- attribute name
   16                                                          (Maybe x)  -- it's value
   17     deriving (Eq, Ord, Show, Data, Functor, Traversable, Foldable, Typeable, Generic)
   18 
   19 instance Serialize x => Serialize (OpAttributeAsConstraint x)
   20 instance Hashable  x => Hashable  (OpAttributeAsConstraint x)
   21 instance ToJSON    x => ToJSON    (OpAttributeAsConstraint x) where toJSON = genericToJSON jsonOptions
   22 instance FromJSON  x => FromJSON  (OpAttributeAsConstraint x) where parseJSON = genericParseJSON jsonOptions
   23 
   24 instance TypeOf (OpAttributeAsConstraint x) where
   25     -- can check more here
   26     typeOf OpAttributeAsConstraint{} = return TypeBool
   27 
   28 instance SimplifyOp OpAttributeAsConstraint x where
   29     simplifyOp _ = na "simplifyOp{OpAttributeAsConstraint}"
   30 
   31 instance Pretty x => Pretty (OpAttributeAsConstraint x) where
   32     prettyPrec _ (OpAttributeAsConstraint x attr Nothing   ) = pretty attr <> prParens (pretty x)
   33     prettyPrec _ (OpAttributeAsConstraint x attr (Just val)) = pretty attr <> prettyList prParens "," [x, val]
   34 
   35 instance VarSymBreakingDescription x => VarSymBreakingDescription (OpAttributeAsConstraint x) where
   36     varSymBreakingDescription (OpAttributeAsConstraint a b c) = JSON.Object $ KM.fromList
   37         [ ("type", JSON.String "OpAttributeAsConstraint")
   38         , ("children", JSON.Array $ V.fromList
   39             [ varSymBreakingDescription a
   40             , toJSON b
   41             , maybe JSON.Null varSymBreakingDescription c
   42             ])
   43         ]