language-thrift-0.3.0.0: Parser for the Thrift IDL format.

Copyright(c) Abhinav Gupta 2015
LicenseBSD3
MaintainerAbhinav Gupta <mail@abhinavg.net>
Stabilityexperimental
Safe HaskellSafe
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) Source 
Data srcAnnot => Data (Program srcAnnot) Source 
Ord srcAnnot => Ord (Program srcAnnot) Source 
Show srcAnnot => Show (Program srcAnnot) Source 
Generic (Program srcAnnot) Source 
type Rep (Program srcAnnot) Source 

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) Source 
Data srcAnnot => Data (Definition srcAnnot) Source 
Ord srcAnnot => Ord (Definition srcAnnot) Source 
Show srcAnnot => Show (Definition srcAnnot) Source 
Generic (Definition srcAnnot) Source 
type Rep (Definition srcAnnot) Source 

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) Source 
Data srcAnnot => Data (Type srcAnnot) Source 
Ord srcAnnot => Ord (Type srcAnnot) Source 
Show srcAnnot => Show (Type srcAnnot) Source 
Generic (Type srcAnnot) Source 
type Rep (Type srcAnnot) Source 

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) Source 
Data srcAnnot => Data (Field srcAnnot) Source 
Ord srcAnnot => Ord (Field srcAnnot) Source 
Show srcAnnot => Show (Field srcAnnot) Source 
Generic (Field srcAnnot) Source 
type Rep (Field srcAnnot) Source 

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) Source 
Data srcAnnot => Data (EnumDef srcAnnot) Source 
Ord srcAnnot => Ord (EnumDef srcAnnot) Source 
Show srcAnnot => Show (EnumDef srcAnnot) Source 
Generic (EnumDef srcAnnot) Source 
type Rep (EnumDef srcAnnot) Source 

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) Source 
Data srcAnnot => Data (Function srcAnnot) Source 
Ord srcAnnot => Ord (Function srcAnnot) Source 
Show srcAnnot => Show (Function srcAnnot) Source 
Generic (Function srcAnnot) Source 
type Rep (Function srcAnnot) Source 

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()