language-thrift-0.8.0.1: 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 (Program SourcePos)) Source #

Parses the Thrift file at the given path.

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

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

thriftIDL :: Stream s Char => Parsec s (Program SourcePos) Source #

Megaparsec parser that is able to parse full Thrift documents.

Components

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

Top-level parser to parse complete Thrift documents.

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

Headers defined for the IDL.

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

The IDL includes another Thrift file.

include "common.thrift"

typedef common.Foo Bar

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

A constant, type, or service definition.

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

A const definition.

const i32 code = 1;

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

A type definition.

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

A service.

service MyService {
    // ...
}

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

A typedef is just an alias for another type.

typedef common.Foo Bar

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

Enums are sets of named integer values.

enum Role {
    User = 1, Admin
}

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

A struct.

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

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

A union of types.

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

exception :: Stream 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 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 Char => Parser s (TypeReference SourcePos) Source #

A reference to a built-in or defined field.

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

A constant value literal.

docstring :: Stream 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 s) Source #

Underlying Parser type.

runParser :: Parser s a -> Parsec s a Source #

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

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

Optional whitespace.