| Copyright | (c) Abhinav Gupta 2015 |
|---|---|
| License | BSD3 |
| Maintainer | Abhinav Gupta <mail@abhinavg.net> |
| Stability | experimental |
| Safe Haskell | None |
| Language | Haskell2010 |
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.
- thriftIDL :: (MonadPlus p, TokenParsing p) => p n -> p (Program n)
- program :: (TokenParsing p, MonadPlus p) => ThriftParser p n (Program n)
- header :: (TokenParsing p, MonadPlus p) => ThriftParser p n Header
- definition :: (TokenParsing p, MonadPlus p) => ThriftParser p n (Definition n)
- function :: (TokenParsing p, MonadPlus p) => ThriftParser p n (Function n)
- fieldType :: (TokenParsing p, MonadPlus p) => ThriftParser p n FieldType
- constantValue :: (TokenParsing p, MonadPlus p) => ThriftParser p n ConstValue
- data ThriftParser p n a
- runThriftParser :: (MonadPlus p, TokenParsing p) => p n -> ThriftParser p n a -> p a
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.
Instances
| (Functor p, MonadPlus p) => Alternative (ThriftParser p n) | |
| Monad p => Monad (ThriftParser p n) | |
| Functor p => Functor (ThriftParser p n) | |
| MonadPlus p => MonadPlus (ThriftParser p n) | |
| (Monad p, Functor p) => Applicative (ThriftParser p n) | |
| (TokenParsing p, MonadPlus p) => TokenParsing (ThriftParser p n) | |
| (MonadPlus p, CharParsing p) => CharParsing (ThriftParser p n) | |
| (MonadPlus p, Parsing p) => Parsing (ThriftParser p n) |
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 |
| -> ThriftParser p n a | |
| -> p a |
Get an exeecutable parser from the given ThriftParser.