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

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

Language.Thrift.Parser

Contents

Description

Provides a parser for Thrift IDLs.

In addition to parsing the IDLs, the parser also keeps track of Javadoc-style docstrings on defined items and makes their values available. For example,

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

Note that the parser does not validate the Thrift file for correctness, so, for example, you could define a string value for an int constant.

Synopsis

Documentation

thriftIDL :: (MonadPlus p, TokenParsing p) => p n -> p (Program n) Source

Get a top level parser that is able to parse full Thrift documents.

Entities defined in the IDL are annotated with n values (determined by executing p n before the parser for the entity is executed).

Usage with Trifecta to get entities tagged with location information (see also, thriftIDL):

Trifecta.parseFromFile (thriftIDL Trifecta.position) "service.thrift"

Usage with Attoparsec without any annotations:

Attoparsec.parse (thriftIDL (return ())) document

Components

program :: (TokenParsing p, MonadPlus p) => ThriftParser p n (Program n) Source

Top-level parser to parse complete Thrift documents.

header :: (TokenParsing p, MonadPlus p) => ThriftParser p n (Header n) Source

Headers defined for the IDL.

include :: (TokenParsing p, MonadPlus p) => ThriftParser p n (Include n) Source

The IDL includes another Thrift file.

include "common.thrift"

typedef common.Foo Bar

namespace :: (TokenParsing p, MonadPlus p) => ThriftParser p n (Namespace n) Source

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

namespace py my_service.generated

definition :: (TokenParsing p, MonadPlus p) => ThriftParser p n (Definition n) Source

A constant, type, or service definition.

constant :: (TokenParsing p, MonadPlus p) => ThriftParser p n (Const n) Source

A const definition.

const i32 code = 1;

typeDefinition :: (TokenParsing p, MonadPlus p) => ThriftParser p n (Type n) Source

A type definition.

service :: (TokenParsing p, MonadPlus p) => ThriftParser p n (Service n) Source

A service.

service MyService {
    // ...
}

typedef :: (TokenParsing p, MonadPlus p) => ThriftParser p n (Typedef n) Source

A typedef is just an alias for another type.

typedef common.Foo Bar

enum :: (TokenParsing p, MonadPlus p) => ThriftParser p n (Enum n) Source

Enums are sets of named integer values.

enum Role {
    User = 1, Admin
}

struct :: (TokenParsing p, MonadPlus p) => ThriftParser p n (Struct n) Source

A struct.

struct User {
    1: string name
    2: Role role = Role.User;
}

union :: (TokenParsing p, MonadPlus p) => ThriftParser p n (Union n) Source

A union of types.

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

exception :: (TokenParsing p, MonadPlus p) => ThriftParser p n (Exception n) Source

An exception that can be raised by service methods.

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

senum :: (TokenParsing p, MonadPlus p) => ThriftParser p n (Senum n) Source

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

typeReference :: (TokenParsing p, MonadPlus p) => ThriftParser p n (TypeReference n) Source

A reference to a built-in or defined field.

constantValue :: (TokenParsing p, MonadPlus p) => ThriftParser p n (ConstValue n) Source

A constant value literal.

Parser

data ThriftParser p n a Source

The ThriftParser wraps another parser p with some extra state. It also allows injecting a configurable action (p n) which produces annotations that will be attached to entities in the Thrift file. See thriftIDLParser for an example.

runThriftParser Source

Arguments

:: (MonadPlus p, TokenParsing p) 
=> p n

How to get annotations from the underlying parser. If this is not something you need to use, make it return () and generated types will be annotated with ().

-> ThriftParser p n a 
-> p a 

Get an exeecutable parser from the given ThriftParser.