never executed always true always false
1 {-# LANGUAGE DeriveGeneric, DeriveDataTypeable, DeriveFunctor, DeriveTraversable, DeriveFoldable #-}
2
3 module Conjure.Language.Expression.Op.Slicing 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 OpSlicing x = OpSlicing x (Maybe x) (Maybe x)
15 deriving (Eq, Ord, Show, Data, Functor, Traversable, Foldable, Typeable, Generic)
16
17 instance Serialize x => Serialize (OpSlicing x)
18 instance Hashable x => Hashable (OpSlicing x)
19 instance ToJSON x => ToJSON (OpSlicing x) where toJSON = genericToJSON jsonOptions
20 instance FromJSON x => FromJSON (OpSlicing x) where parseJSON = genericParseJSON jsonOptions
21
22 instance (TypeOf x, Pretty x) => TypeOf (OpSlicing x) where
23 typeOf p@(OpSlicing m _ _) = do
24 ty <- typeOf m
25 case ty of
26 TypeMatrix{} -> return ()
27 TypeList{} -> return ()
28 _ -> raiseTypeError p
29 return ty
30
31 instance SimplifyOp OpSlicing x where
32 simplifyOp _ = na "simplifyOp{OpSlicing}"
33
34 instance Pretty x => Pretty (OpSlicing x) where
35 prettyPrec _ (OpSlicing m a b) = pretty m <> prBrackets (pretty a <> ".." <> pretty b)
36
37 instance VarSymBreakingDescription x => VarSymBreakingDescription (OpSlicing x) where
38 varSymBreakingDescription (OpSlicing a b c) = JSON.Object $ KM.fromList
39 [ ("type", JSON.String "OpSlicing")
40 , ("children", JSON.Array $ V.fromList
41 [ varSymBreakingDescription a
42 , maybe JSON.Null varSymBreakingDescription b
43 , maybe JSON.Null varSymBreakingDescription c
44 ])
45 ]