A Pure Elixir Thrift Implementation
Go to file
Jon Parise 8c75213a59 Require at least Elixir 1.2 (#11)
With today's release of Elixir 1.3, now is a good time to drop compatibility
with much older releases. This also lets us use some of the nicer language
features introduced in Elixir 1.2, like the multi-alias syntax.
2016-06-21 08:56:00 -07:00
ext Update our Thrift reference to version 0.9.3. 2015-10-16 09:35:34 -07:00
lib Fix unsafe conditional assignments 2016-06-21 07:52:21 -07:00
src An implementation of the Thrift parser 2016-06-14 08:53:54 -07:00
test An implementation of the Thrift parser 2016-06-14 08:53:54 -07:00
.gitignore An implementation of the Thrift parser 2016-06-14 08:53:54 -07:00
.gitmodules Initial revision. 2015-01-06 17:51:59 -08:00
.travis.yml Require at least Elixir 1.2 (#11) 2016-06-21 08:56:00 -07:00
coveralls.json An implementation of the Thrift parser 2016-06-14 08:53:54 -07:00
LICENSE Add a full copy of our Apache license. 2015-12-19 08:49:23 -08:00
Makefile Build Thrift 0.9.3 in the Travis home directory 2016-05-24 08:57:17 -07:00
mix.exs Require at least Elixir 1.2 (#11) 2016-06-21 08:56:00 -07:00
mix.lock Update to Credo 0.4.5 2016-06-20 13:11:16 -07:00
README.md Add a :thrift_executable compile task option 2016-05-27 17:59:15 -07:00

Thrift Utilities for Elixir

Build Status Coverage Status License

This package contains a handful of useful utilities for working with Thrift in Elixir.

In particular, it includes a copy of the Erlang Thrift runtime library.

Setup

Start by adding this package to your project as a dependency:

{:thrift, github: "pinterest/elixir-thrift", submodules: true}

Mix

This package includes a Mix compiler task that can be used to automate Thrift code generation. Start by adding :thrift to your project's :compilers list. For example:

compilers: [:thrift | Mix.compilers]

It's important to add :thrift before the :erlang entry. The Thrift compiler will generate Erlang source files, and we currently rely on this ordering to ensure those generated source files get compiled.

Next, define the list of :thrift_files that should be compiled. In this example, we gather all of the .thrift files under the thrift directory:

thrift_files: Mix.Utils.extract_files(["thrift"], [:thrift])

By default, the generated source files will be written to the src directory, but you can change that using the thrift_output option.

You can also pass additional options to the Thrift compiler by listing them in the thrift_options option:

thrift_options: ~w[-I my/include/dir]

If you require a specific version of the Thrift compiler, you can specify a version requirement using the thrift_version option. Version requirements use the SemVer 2.0 schema. For example:

thrift_version: ">= 0.9.3"  # Erlang maps support

You can also override the name of the Thrift compiler executable itself:

thrift_executable: "thrift-0.9.3"

If you get something like type set() undefined when compiling the generated files you can try:

thrift_options: ~w[--gen erl:maps]

Thrift IDL Parsing

This package also contains experimental support for parsing Thrift IDL files. For the moment, only an Erlang lexer is available, but the goal is to provide more advanced parser support over time.

:thrift_lexer.string('enum Colors { RED, GREEN, BLUE}')
{:ok,
 [{:enum, 1}, {:ident, 1, 'Colors'}, {:symbol, 1, '{'}, {:ident, 1, 'RED'},
  {:symbol, 1, ','}, {:ident, 1, 'GREEN'}, {:symbol, 1, ','},
  {:ident, 1, 'BLUE'}, {:symbol, 1, '}'}], 1}