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 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 Source

Headers defined for the IDL.

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

A constant, type, or service definition.

function :: (TokenParsing p, MonadPlus p) => ThriftParser p n (Function n) Source

A function defined inside a service.

Foo getFoo() throws (1: FooDoesNotExist doesNotExist);
oneway void putBar(1: Bar bar);

fieldType :: (TokenParsing p, MonadPlus p) => ThriftParser p n FieldType Source

A reference to a built-in or defined field.

constantValue :: (TokenParsing p, MonadPlus p) => ThriftParser p n ConstValue 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.