language-thrift-0.4.0.0: Parser and pretty printer for the Thrift IDL format.

Copyright(c) Abhinav Gupta 2015
LicenseBSD3
MaintainerAbhinav Gupta <mail@abhinavg.net>
Stabilityexperimental
Safe HaskellSafe-Inferred
LanguageHaskell2010

Language.Thrift.Types

Description

This module defines types that compose a Thrift IDL file.

Synopsis

Documentation

data Program srcAnnot Source

A program represents a single Thrift document.

Constructors

Program 

Fields

programHeaders :: [Header]

Headers in a document define includes and namespaces.

programDefinitions :: [Definition srcAnnot]

Types and services defined in the document.

Instances

Eq srcAnnot => Eq (Program srcAnnot) 
Data srcAnnot => Data (Program srcAnnot) 
Ord srcAnnot => Ord (Program srcAnnot) 
Show srcAnnot => Show (Program srcAnnot) 
Generic (Program srcAnnot) 
Typeable (* -> *) Program 
type Rep (Program srcAnnot) 

data Header Source

Headers for a program.

Constructors

Include

The IDL includes another Thrift file.

include "common.thrift"

typedef common.Foo Bar

Fields

includePath :: Text

Path to the included file.

Namespace

Namespace directives allows control of the namespace or package name used by the generated code for certain languages.

namespace py my_service.generated

Fields

namespaceLanguage :: Text

The language for which the namespace is being specified. This may be * to refer to all languages.

namespaceName :: Text

Namespace or package path to use in the generated code for that language.

data Definition srcAnnot Source

A definition either consists of new constants, new types, or new services.

Constructors

ConstDefinition

A declared constant.

const i32 code = 1;

Fields

constType :: FieldType

Type of the constant.

constName :: Text

Name of the constant.

constValue :: ConstValue

Value of the constant.

constDocstring :: Docstring

Documentation.

constSrcAnnot :: srcAnnot
 
TypeDefinition

A declared type.

Fields

typeDefinition :: Type srcAnnot

Details of the type definition.

typeAnnotations :: [TypeAnnotation]

Annotations added to the type.

ServiceDefinition

A service definition.

service MyService {
    // ...
}

Fields

serviceName :: Text

Name of the service.

serviceExtends :: Maybe Text

Name of the service this service extends.

serviceFunctions :: [Function srcAnnot]

All the functions defined for the service.

serviceAnnotations :: [TypeAnnotation]

Annotations added to the service.

serviceDocstring :: Docstring

Documentation.

serviceSrcAnnot :: srcAnnot
 

Instances

Eq srcAnnot => Eq (Definition srcAnnot) 
Data srcAnnot => Data (Definition srcAnnot) 
Ord srcAnnot => Ord (Definition srcAnnot) 
Show srcAnnot => Show (Definition srcAnnot) 
Generic (Definition srcAnnot) 
Typeable (* -> *) Definition 
type Rep (Definition srcAnnot) 

data Type srcAnnot Source

Defines the various types that can be declared in Thrift.

Constructors

Typedef

A typedef is just an alias for another type.

typedef common.Foo Bar

Fields

typedefType :: FieldType

The aliased type.

typedefName :: Text

Name of the new type.

typedefDocstring :: Docstring

Documentation.

typedefSrcAnnot :: srcAnnot
 
Enum

Enums are sets of named integer values.

enum Role {
    User = 1, Admin = 2
}

Fields

enumName :: Text

Name of the enum type.

enumValues :: [EnumDef srcAnnot]

Values defined in the enum.

enumDocstring :: Docstring

Documentation.

enumSrcAnnot :: srcAnnot
 
Struct

A struct definition

struct User {
    1: Role role = Role.User;
}

Fields

structName :: Text

Name of the struct.

structFields :: [Field srcAnnot]

Fields defined in the struct.

structDocstring :: Docstring

Documentation.

structSrcAnnot :: srcAnnot
 
Union

A union of other types.

union Value {
    1: string stringValue;
    2: i32 intValue;
}

Fields

unionName :: Text

Name of the union.

unionFields :: [Field srcAnnot]

Fields defined in the union.

unionDocstring :: Docstring

Documentation.

unionSrcAnnot :: srcAnnot
 
Exception

Exception types.

exception UserDoesNotExist {
    1: optional string message
    2: required string username
}
Senum

An string-only enum. These are a deprecated feature of Thrift and shouldn't be used.

Fields

senumName :: Text
 
senumValues :: [Text]
 
senumDocstring :: Docstring

Documentation.

senumSrcAnnot :: srcAnnot
 

Instances

Eq srcAnnot => Eq (Type srcAnnot) 
Data srcAnnot => Data (Type srcAnnot) 
Ord srcAnnot => Ord (Type srcAnnot) 
Show srcAnnot => Show (Type srcAnnot) 
Generic (Type srcAnnot) 
Typeable (* -> *) Type 
type Rep (Type srcAnnot) 

data FieldRequiredness Source

Whether a field is required or optional.

Constructors

Required

The field is required.

Optional

The field is optional.

data Field srcAnnot Source

A field inside a struct, exception, or function parameters list.

Constructors

Field 

Fields

fieldIdentifier :: Maybe Integer

Position of the field.

While this is optional, it is recommended that Thrift files always contain specific field IDs.

fieldRequiredness :: Maybe FieldRequiredness

Whether this field is required or not.

Behavior may differ between languages if requiredness is not specified. Therefore it's recommended that requiredness for a field is always specified.

fieldType :: FieldType

Type of value the field holds.

fieldName :: Text

Name of the field.

fieldDefault :: Maybe ConstValue

Default value of the field, if any.

fieldAnnotations :: [TypeAnnotation]

Field annotations.

fieldDocstring :: Docstring

Documentation.

fieldSrcAnnot :: srcAnnot
 

Instances

Eq srcAnnot => Eq (Field srcAnnot) 
Data srcAnnot => Data (Field srcAnnot) 
Ord srcAnnot => Ord (Field srcAnnot) 
Show srcAnnot => Show (Field srcAnnot) 
Generic (Field srcAnnot) 
Typeable (* -> *) Field 
type Rep (Field srcAnnot) 

data EnumDef srcAnnot Source

A named value inside an enum.

Constructors

EnumDef 

Fields

enumDefName :: Text

Name of the value.

enumDefValue :: Maybe Integer

Value attached to the enum for that name.

enumDefAnnotations :: [TypeAnnotation]

Annotations added to this enum field.

enumDefDocstring :: Docstring

Documentation

enumDefSrcAnnot :: srcAnnot
 

Instances

Eq srcAnnot => Eq (EnumDef srcAnnot) 
Data srcAnnot => Data (EnumDef srcAnnot) 
Ord srcAnnot => Ord (EnumDef srcAnnot) 
Show srcAnnot => Show (EnumDef srcAnnot) 
Generic (EnumDef srcAnnot) 
Typeable (* -> *) EnumDef 
type Rep (EnumDef srcAnnot) 

data ConstValue Source

A constant literal value in the IDL. Only a few basic types, lists, and maps can be presented in Thrift files as literals.

Constants are used for IDL-level constants and default values for fields.

Constructors

ConstInt Integer

An integer. 42

ConstFloat Double

A float. 4.2

ConstLiteral Text

A literal string. "hello"

ConstIdentifier Text

A literal identifier. hello

ConstList [ConstValue]

A literal list containing other constant values. [42]

ConstMap [(ConstValue, ConstValue)]

A literal list containing other constant values. {"hellO": 1, "world": 2}

data FieldType Source

A reference to a type.

Constructors

DefinedType Text

A custom defined type referred to by name.

StringType [TypeAnnotation]

string and annotations.

BinaryType [TypeAnnotation]

binary and annotations.

SListType [TypeAnnotation]

slist and annotations.

BoolType [TypeAnnotation]

bool and annotations.

ByteType [TypeAnnotation]

byte and annotations.

I16Type [TypeAnnotation]

i16 and annotations.

I32Type [TypeAnnotation]

i32 and annotations.

I64Type [TypeAnnotation]

i64 and annotations.

DoubleType [TypeAnnotation]

double and annotations.

MapType FieldType FieldType [TypeAnnotation]

map<foo, bar> and annotations.

SetType FieldType [TypeAnnotation]

set<baz> and annotations.

ListType FieldType [TypeAnnotation]

list<qux> and annotations.

data Function srcAnnot Source

A function defined inside a service.

Constructors

Function 

Fields

functionOneWay :: Bool

Whether the function is oneway. If it's one way, it cannot receive repsonses.

functionReturnType :: Maybe FieldType

Return type of the function, or Nothing if it's void or oneway.

functionName :: Text

Name of the function.

functionParameters :: [Field srcAnnot]

Parameters accepted by the function.

functionExceptions :: Maybe [Field srcAnnot]

Exceptions raised by the function, if any.

functionAnnotations :: [TypeAnnotation]

Annotations added to the function.

functionDocstring :: Docstring

Documentation.

functionSrcAnnot :: srcAnnot
 

Instances

Eq srcAnnot => Eq (Function srcAnnot) 
Data srcAnnot => Data (Function srcAnnot) 
Ord srcAnnot => Ord (Function srcAnnot) 
Show srcAnnot => Show (Function srcAnnot) 
Generic (Function srcAnnot) 
Typeable (* -> *) Function 
type Rep (Function srcAnnot) 

data TypeAnnotation Source

Type annoations may be added in various places in the form,

(foo = "bar", baz = "qux")

These do not usually affect code generation but allow for custom logic if writing your own code generator.

Constructors

TypeAnnotation 

Fields

typeAnnotationName :: Text

Name of the annotation.

typeAnnotationValue :: Text

Value for the annotation.

type Docstring = Maybe Text Source

Docstrings are Javadoc-style comments attached various defined objects.

/**
 * Fetches an item.
 */
Item getItem()