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

Copyright(c) Abhinav Gupta 2016
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

parseFromFile :: FilePath -> IO (Either (ParseError Char Dec) (Program SourcePos)) Source #

Parses the Thrift file at the given path.

parse :: (Stream s, Token s ~ Char) => FilePath -> s -> Either (ParseError Char Dec) (Program SourcePos) Source #

parse name contents parses the contents of a Thrift document with name name held in contents.

thriftIDL :: (Stream s, Token s ~ Char) => Parsec Dec s (Program SourcePos) Source #

Megaparsec parser that is able to parse full Thrift documents.

Components

program :: (Stream s, Token s ~ Char) => Parser s (Program SourcePos) Source #

Top-level parser to parse complete Thrift documents.

header :: (Stream s, Token s ~ Char) => Parser s (Header SourcePos) Source #

Headers defined for the IDL.

include :: (Stream s, Token s ~ Char) => Parser s (Include SourcePos) Source #

The IDL includes another Thrift file.

include "common.thrift"

typedef common.Foo Bar

namespace :: (Stream s, Token s ~ Char) => Parser s (Namespace SourcePos) 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 :: (Stream s, Token s ~ Char) => Parser s (Definition SourcePos) Source #

A constant, type, or service definition.

constant :: (Stream s, Token s ~ Char) => Parser s (Const SourcePos) Source #

A const definition.

const i32 code = 1;

typeDefinition :: (Stream s, Token s ~ Char) => Parser s (Type SourcePos) Source #

A type definition.

service :: (Stream s, Token s ~ Char) => Parser s (Service SourcePos) Source #

A service.

service MyService {
    // ...
}

typedef :: (Stream s, Token s ~ Char) => Parser s (Typedef SourcePos) Source #

A typedef is just an alias for another type.

typedef common.Foo Bar

enum :: (Stream s, Token s ~ Char) => Parser s (Enum SourcePos) Source #

Enums are sets of named integer values.

enum Role {
    User = 1, Admin

struct :: (Stream s, Token s ~ Char) => Parser s (Struct SourcePos) Source #

A struct.

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

union :: (Stream s, Token s ~ Char) => Parser s (Union SourcePos) Source #

A union of types.

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

exception :: (Stream s, Token s ~ Char) => Parser s (Exception SourcePos) Source #

An exception that can be raised by service methods.

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

senum :: (Stream s, Token s ~ Char) => Parser s (Senum SourcePos) Source #

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

typeReference :: (Stream s, Token s ~ Char) => Parser s (TypeReference SourcePos) Source #

A reference to a built-in or defined field.

constantValue :: (Stream s, Token s ~ Char) => Parser s (ConstValue SourcePos) Source #

A constant value literal.

docstring :: (Stream s, Token s ~ Char) => Parser s Text Source #

A javadoc-style docstring.

/**
 * foo
 */

This parses attempts to preserve indentation inside the docstring while getting rid of the aligned *s (if any) and any other preceding space.

Parser

type Parser s = StateT State (Parsec Dec s) Source #

Underlying Parser type.

runParser :: (Stream s, Token s ~ Char) => Parser s a -> Parsec Dec s a Source #

Evaluates the underlying parser with a default state and get the Megaparsec parser.

whiteSpace :: (Stream s, Token s ~ Char) => Parser s () Source #

Optional whitespace.