Copyright | (c) Abhinav Gupta 2016 |
---|---|
License | BSD3 |
Maintainer | Abhinav Gupta <mail@abhinavg.net> |
Stability | experimental |
Safe Haskell | None |
Language | Haskell2010 |
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.
- parseFromFile :: FilePath -> IO (Either (ParseError Char Dec) (Program SourcePos))
- parse :: (Stream s, Token s ~ Char) => FilePath -> s -> Either (ParseError Char Dec) (Program SourcePos)
- thriftIDL :: (Stream s, Token s ~ Char) => Parsec Dec s (Program SourcePos)
- program :: (Stream s, Token s ~ Char) => Parser s (Program SourcePos)
- header :: (Stream s, Token s ~ Char) => Parser s (Header SourcePos)
- include :: (Stream s, Token s ~ Char) => Parser s (Include SourcePos)
- namespace :: (Stream s, Token s ~ Char) => Parser s (Namespace SourcePos)
- definition :: (Stream s, Token s ~ Char) => Parser s (Definition SourcePos)
- constant :: (Stream s, Token s ~ Char) => Parser s (Const SourcePos)
- typeDefinition :: (Stream s, Token s ~ Char) => Parser s (Type SourcePos)
- service :: (Stream s, Token s ~ Char) => Parser s (Service SourcePos)
- typedef :: (Stream s, Token s ~ Char) => Parser s (Typedef SourcePos)
- enum :: (Stream s, Token s ~ Char) => Parser s (Enum SourcePos)
- struct :: (Stream s, Token s ~ Char) => Parser s (Struct SourcePos)
- union :: (Stream s, Token s ~ Char) => Parser s (Union SourcePos)
- exception :: (Stream s, Token s ~ Char) => Parser s (Exception SourcePos)
- senum :: (Stream s, Token s ~ Char) => Parser s (Senum SourcePos)
- typeReference :: (Stream s, Token s ~ Char) => Parser s (TypeReference SourcePos)
- constantValue :: (Stream s, Token s ~ Char) => Parser s (ConstValue SourcePos)
- docstring :: (Stream s, Token s ~ Char) => Parser s Text
- type Parser s = StateT State (Parsec Dec s)
- runParser :: (Stream s, Token s ~ Char) => Parser s a -> Parsec Dec s a
- whiteSpace :: (Stream s, Token s ~ Char) => Parser s ()
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.