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 (Program SourcePos))
- parse :: Stream s Char => FilePath -> s -> Either ParseError (Program SourcePos)
- thriftIDL :: Stream s Char => Parsec s (Program SourcePos)
- program :: Stream s Char => Parser s (Program SourcePos)
- header :: Stream s Char => Parser s (Header SourcePos)
- include :: Stream s Char => Parser s (Include SourcePos)
- namespace :: Stream s Char => Parser s (Namespace SourcePos)
- definition :: Stream s Char => Parser s (Definition SourcePos)
- constant :: Stream s Char => Parser s (Const SourcePos)
- typeDefinition :: Stream s Char => Parser s (Type SourcePos)
- service :: Stream s Char => Parser s (Service SourcePos)
- typedef :: Stream s Char => Parser s (Typedef SourcePos)
- enum :: Stream s Char => Parser s (Enum SourcePos)
- struct :: Stream s Char => Parser s (Struct SourcePos)
- union :: Stream s Char => Parser s (Union SourcePos)
- exception :: Stream s Char => Parser s (Exception SourcePos)
- senum :: Stream s Char => Parser s (Senum SourcePos)
- typeReference :: Stream s Char => Parser s (TypeReference SourcePos)
- constantValue :: Stream s Char => Parser s (ConstValue SourcePos)
- docstring :: Stream s Char => Parser s Text
- type Parser s = StateT State (Parsec s)
- runParser :: Parser s a -> Parsec s a
- whiteSpace :: Stream s Char => Parser s ()
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.
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;
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.