never executed always true always false
1 {-# LANGUAGE DeriveGeneric, DeriveDataTypeable, DeriveFunctor, DeriveTraversable, DeriveFoldable #-}
2
3 module Conjure.Language.Expression.Op.Subsequence 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 OpSubsequence x = OpSubsequence x x
15 deriving (Eq, Ord, Show, Data, Functor, Traversable, Foldable, Typeable, Generic)
16
17 instance Serialize x => Serialize (OpSubsequence x)
18 instance Hashable x => Hashable (OpSubsequence x)
19 instance ToJSON x => ToJSON (OpSubsequence x) where toJSON = genericToJSON jsonOptions
20 instance FromJSON x => FromJSON (OpSubsequence x) where parseJSON = genericParseJSON jsonOptions
21
22 instance BinaryOperator (OpSubsequence x) where
23 opLexeme _ = L_subsequence
24
25 instance (TypeOf x, Pretty x) => TypeOf (OpSubsequence x) where
26 typeOf p@(OpSubsequence a b) = do
27 tya <- typeOf a
28 tyb <- typeOf b
29 case (tya, tyb) of
30 (TypeSequence{}, TypeSequence{}) -> return TypeBool
31 _ -> raiseTypeError $ vcat [ pretty p
32 , "Unexpected types for operands:"
33 , " - " <> pretty tya
34 , " - " <> pretty tyb
35 ]
36
37 instance SimplifyOp OpSubsequence x where
38 simplifyOp _ = na "simplifyOp{OpSubsequence}"
39
40 instance Pretty x => Pretty (OpSubsequence x) where
41 prettyPrec prec op@(OpSubsequence a b) = prettyPrecBinOp prec [op] a b
42
43 instance VarSymBreakingDescription x => VarSymBreakingDescription (OpSubsequence x) where
44 varSymBreakingDescription (OpSubsequence a b) = JSON.Object $ KM.fromList
45 [ ("type", JSON.String "OpSubsequence")
46 , ("children", JSON.Array $ V.fromList
47 [ varSymBreakingDescription a
48 , varSymBreakingDescription b
49 ])
50 ]