module Language.Thrift.Internal.Types
( Program(..)
, Header(..)
, _Include
, _Namespace
, Include(..)
, Namespace(..)
, Definition(..)
, _Const
, _Service
, _Type
, Const(..)
, Service(..)
, Type(..)
, _Typedef
, _Enum
, _Struct
, _Union
, _Exception
, _Senum
, Typedef(..)
, Enum(..)
, Struct(..)
, Union(..)
, Exception(..)
, Senum(..)
, FieldRequiredness(..)
, _Required
, _Optional
, Field(..)
, EnumDef(..)
, ConstValue(..)
, _ConstInt
, _ConstFloat
, _ConstLiteral
, _ConstIdentifier
, _ConstList
, _ConstMap
, TypeReference(..)
, _DefinedType
, _StringType
, _BinaryType
, _SListType
, _BoolType
, _ByteType
, _I16Type
, _I32Type
, _I64Type
, _DoubleType
, _MapType
, _SetType
, _ListType
, Function(..)
, TypeAnnotation(..)
, Docstring
, HasAnnotations(..)
, HasDefaultValue(..)
, HasDefinitions(..)
, HasDocstring(..)
, HasExceptions(..)
, HasExtends(..)
, HasFields(..)
, HasFunctions(..)
, HasHeaders(..)
, HasIdentifier(..)
, HasLanguage(..)
, HasName(..)
, HasOneWay(..)
, HasParameters(..)
, HasPath(..)
, HasRequiredness(..)
, HasReturnType(..)
, HasSrcAnnot(..)
, HasTargetType(..)
, HasValue(..)
, HasValues(..)
, HasValueType(..)
) where
import Data.Data (Data, Typeable)
import Data.Text (Text)
import GHC.Generics (Generic)
import Prelude hiding (Enum)
import qualified Control.Lens as L
data TypeAnnotation = TypeAnnotation
{ typeAnnotationName :: Text
, typeAnnotationValue :: Maybe Text
}
deriving (Show, Ord, Eq, Data, Typeable, Generic)
L.makeFields ''TypeAnnotation
type Docstring = Maybe Text
data ConstValue srcAnnot
= ConstInt Integer
| ConstFloat Double
| ConstLiteral Text
| ConstIdentifier Text srcAnnot
| ConstList [ConstValue srcAnnot]
| ConstMap [(ConstValue srcAnnot, ConstValue srcAnnot)]
deriving (Show, Ord, Eq, Data, Typeable, Generic)
L.makePrisms ''ConstValue
data TypeReference srcAnnot
= DefinedType Text srcAnnot
| StringType [TypeAnnotation]
| BinaryType [TypeAnnotation]
| SListType [TypeAnnotation]
| BoolType [TypeAnnotation]
| ByteType [TypeAnnotation]
| I16Type [TypeAnnotation]
| I32Type [TypeAnnotation]
| I64Type [TypeAnnotation]
| DoubleType [TypeAnnotation]
| MapType
(TypeReference srcAnnot)
(TypeReference srcAnnot)
[TypeAnnotation]
| SetType (TypeReference srcAnnot) [TypeAnnotation]
| ListType (TypeReference srcAnnot) [TypeAnnotation]
deriving (Show, Ord, Eq, Data, Typeable, Generic)
L.makePrisms ''TypeReference
data FieldRequiredness
= Required
| Optional
deriving (Show, Ord, Eq, Data, Typeable, Generic)
L.makePrisms ''FieldRequiredness
data Field srcAnnot = Field
{ fieldIdentifier :: Maybe Integer
, fieldRequiredness :: Maybe FieldRequiredness
, fieldValueType :: TypeReference srcAnnot
, fieldName :: Text
, fieldDefaultValue :: Maybe (ConstValue srcAnnot)
, fieldAnnotations :: [TypeAnnotation]
, fieldDocstring :: Docstring
, fieldSrcAnnot :: srcAnnot
}
deriving (Show, Ord, Eq, Data, Typeable, Generic)
L.makeFields ''Field
data Function srcAnnot = Function
{ functionOneWay :: Bool
, functionReturnType :: Maybe (TypeReference srcAnnot)
, functionName :: Text
, functionParameters :: [Field srcAnnot]
, functionExceptions :: Maybe [Field srcAnnot]
, functionAnnotations :: [TypeAnnotation]
, functionDocstring :: Docstring
, functionSrcAnnot :: srcAnnot
}
deriving (Show, Ord, Eq, Data, Typeable, Generic)
L.makeFields ''Function
data Service srcAnnot = Service
{ serviceName :: Text
, serviceExtends :: Maybe Text
, serviceFunctions :: [Function srcAnnot]
, serviceAnnotations :: [TypeAnnotation]
, serviceDocstring :: Docstring
, serviceSrcAnnot :: srcAnnot
}
deriving (Show, Ord, Eq, Data, Typeable, Generic)
L.makeFields ''Service
data Const srcAnnot = Const
{ constValueType :: TypeReference srcAnnot
, constName :: Text
, constValue :: ConstValue srcAnnot
, constDocstring :: Docstring
, constSrcAnnot :: srcAnnot
}
deriving (Show, Ord, Eq, Data, Typeable, Generic)
L.makeFields ''Const
data Typedef srcAnnot = Typedef
{ typedefTargetType :: TypeReference srcAnnot
, typedefName :: Text
, typedefAnnotations :: [TypeAnnotation]
, typedefDocstring :: Docstring
, typedefSrcAnnot :: srcAnnot
}
deriving (Show, Ord, Eq, Data, Typeable, Generic)
L.makeFields ''Typedef
data EnumDef srcAnnot = EnumDef
{ enumDefName :: Text
, enumDefValue :: Maybe Integer
, enumDefAnnotations :: [TypeAnnotation]
, enumDefDocstring :: Docstring
, enumDefSrcAnnot :: srcAnnot
}
deriving (Show, Ord, Eq, Data, Typeable, Generic)
L.makeFields ''EnumDef
data Enum srcAnnot = Enum
{ enumName :: Text
, enumValues :: [EnumDef srcAnnot]
, enumAnnotations :: [TypeAnnotation]
, enumDocstring :: Docstring
, enumSrcAnnot :: srcAnnot
}
deriving (Show, Ord, Eq, Data, Typeable, Generic)
L.makeFields ''Enum
data Struct srcAnnot = Struct
{ structName :: Text
, structFields :: [Field srcAnnot]
, structAnnotations :: [TypeAnnotation]
, structDocstring :: Docstring
, structSrcAnnot :: srcAnnot
}
deriving (Show, Ord, Eq, Data, Typeable, Generic)
L.makeFields ''Struct
data Union srcAnnot = Union
{ unionName :: Text
, unionFields :: [Field srcAnnot]
, unionAnnotations :: [TypeAnnotation]
, unionDocstring :: Docstring
, unionSrcAnnot :: srcAnnot
}
deriving (Show, Ord, Eq, Data, Typeable, Generic)
L.makeFields ''Union
data Exception srcAnnot = Exception
{ exceptionName :: Text
, exceptionFields :: [Field srcAnnot]
, exceptionAnnotations :: [TypeAnnotation]
, exceptionDocstring :: Docstring
, exceptionSrcAnnot :: srcAnnot
}
deriving (Show, Ord, Eq, Data, Typeable, Generic)
L.makeFields ''Exception
data Senum srcAnnot = Senum
{ senumName :: Text
, senumValues :: [Text]
, senumAnnotations :: [TypeAnnotation]
, senumDocstring :: Docstring
, senumSrcAnnot :: srcAnnot
}
deriving (Show, Ord, Eq, Data, Typeable, Generic)
L.makeFields ''Senum
data Type srcAnnot
=
TypedefType (Typedef srcAnnot)
|
EnumType (Enum srcAnnot)
|
StructType (Struct srcAnnot)
|
UnionType (Union srcAnnot)
|
ExceptionType (Exception srcAnnot)
|
SenumType (Senum srcAnnot)
deriving (Show, Ord, Eq, Data, Typeable, Generic)
_Typedef :: L.Prism' (Type ann) (Typedef ann)
_Typedef = L.prism' TypedefType $ \t ->
case t of
TypedefType a -> Just a
_ -> Nothing
_Enum :: L.Prism' (Type ann) (Enum ann)
_Enum = L.prism' EnumType $ \t ->
case t of
EnumType a -> Just a
_ -> Nothing
_Struct :: L.Prism' (Type ann) (Struct ann)
_Struct = L.prism' StructType $ \t ->
case t of
StructType a -> Just a
_ -> Nothing
_Union :: L.Prism' (Type ann) (Union ann)
_Union = L.prism' UnionType $ \t ->
case t of
UnionType a -> Just a
_ -> Nothing
_Exception :: L.Prism' (Type ann) (Exception ann)
_Exception = L.prism' ExceptionType $ \t ->
case t of
ExceptionType a -> Just a
_ -> Nothing
_Senum :: L.Prism' (Type ann) (Senum ann)
_Senum = L.prism' SenumType $ \t ->
case t of
SenumType a -> Just a
_ -> Nothing
data Definition srcAnnot
=
ConstDefinition (Const srcAnnot)
|
TypeDefinition (Type srcAnnot)
|
ServiceDefinition (Service srcAnnot)
deriving (Show, Ord, Eq, Data, Typeable, Generic)
_Const :: L.Prism' (Definition ann) (Const ann)
_Const = L.prism' ConstDefinition $ \def ->
case def of
ConstDefinition c -> Just c
_ -> Nothing
_Type :: L.Prism' (Definition ann) (Type ann)
_Type = L.prism' TypeDefinition $ \def ->
case def of
TypeDefinition c -> Just c
_ -> Nothing
_Service :: L.Prism' (Definition ann) (Service ann)
_Service = L.prism' ServiceDefinition $ \def ->
case def of
ServiceDefinition c -> Just c
_ -> Nothing
data Namespace srcAnnot = Namespace
{ namespaceLanguage :: Text
, namespaceName :: Text
, namespaceSrcAnnot :: srcAnnot
}
deriving (Show, Ord, Eq, Data, Typeable, Generic)
L.makeFields ''Namespace
data Include srcAnnot = Include
{ includePath :: Text
, includeSrcAnnot :: srcAnnot
}
deriving (Show, Ord, Eq, Data, Typeable, Generic)
L.makeFields ''Include
data Header srcAnnot
=
HeaderInclude (Include srcAnnot)
|
HeaderNamespace (Namespace srcAnnot)
deriving (Show, Ord, Eq, Data, Typeable, Generic)
_Include :: L.Prism' (Header ann) (Include ann)
_Include = L.prism' HeaderInclude $ \h ->
case h of
HeaderInclude inc -> Just inc
_ -> Nothing
_Namespace :: L.Prism' (Header ann) (Namespace ann)
_Namespace = L.prism' HeaderNamespace $ \h ->
case h of
HeaderNamespace ns -> Just ns
_ -> Nothing
data Program srcAnnot = Program
{ programHeaders :: [Header srcAnnot]
, programDefinitions :: [Definition srcAnnot]
}
deriving (Show, Ord, Eq, Data, Typeable, Generic)
L.makeFields ''Program