All Projects → creditkarma → thrift-parser

creditkarma / thrift-parser

Licence: Apache-2.0 license
A Thrift Parser built in TypeScript that generates a TypeScript AST that retains the Thrift grammar

Programming Languages

typescript
32286 projects
Thrift
134 projects
javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to thrift-parser

Springboot Thrift Etcd Ribbon
基于springboot的thrift的rpc, 服务发现基于etcd,路由基于ribbon
Stars: ✭ 75 (-10.71%)
Mutual labels:  thrift
Thrift Missing Guide
Thrift: The Missing Guide
Stars: ✭ 148 (+76.19%)
Mutual labels:  thrift
Go
decode/encode thrift message without IDL
Stars: ✭ 219 (+160.71%)
Mutual labels:  thrift
Line Instant Messenger Protocol
It is work of Matti Virkkunen, link to http://altrepo.eu/git/line-protocol.git for latest update.
Stars: ✭ 96 (+14.29%)
Mutual labels:  thrift
Aeraki
Manage any layer 7 traffic in Istio Service Mesh.
Stars: ✭ 119 (+41.67%)
Mutual labels:  thrift
Finatra
Fast, testable, Scala services built on TwitterServer and Finagle
Stars: ✭ 2,126 (+2430.95%)
Mutual labels:  thrift
Sails
Create a Thrift Server use like Rails
Stars: ✭ 72 (-14.29%)
Mutual labels:  thrift
Hibari
Hibari is a production-ready, distributed, ordered key-value, big data store. Hibari uses chain replication for strong consistency, high-availability, and durability. Hibari has excellent performance especially for read and large value operations.
Stars: ✭ 253 (+201.19%)
Mutual labels:  thrift
Herringbone
Tools for working with parquet, impala, and hive
Stars: ✭ 134 (+59.52%)
Mutual labels:  thrift
Gunicorn thrift
Thrift app and worker for gunicorn!
Stars: ✭ 193 (+129.76%)
Mutual labels:  thrift
Dapeng Soa
A lightweight, high performance micro-service framework
Stars: ✭ 101 (+20.24%)
Mutual labels:  thrift
Frugal
Thrift improved
Stars: ✭ 113 (+34.52%)
Mutual labels:  thrift
Elixir Thrift
A Pure Elixir Thrift Implementation
Stars: ✭ 182 (+116.67%)
Mutual labels:  thrift
Evernote Thrift
Thrift IDL files for the Evernote Cloud API
Stars: ✭ 94 (+11.9%)
Mutual labels:  thrift
Harpc
基于Thrift的跨语言、高可用、高性能、轻量级的RPC框架。
Stars: ✭ 229 (+172.62%)
Mutual labels:  thrift
Thrift connector
Clients of thrift, utilizing connection pools
Stars: ✭ 74 (-11.9%)
Mutual labels:  thrift
Spring Thrift Starter
Set of cool annotations that helps you building Thrift applications with Spring Boot
Stars: ✭ 151 (+79.76%)
Mutual labels:  thrift
raster
A micro server framework, support coroutine, and parallel-computing, used for building flatbuffers/thrift/protobuf/http protocol service.
Stars: ✭ 19 (-77.38%)
Mutual labels:  thrift
Osquery Go
Go bindings for osquery
Stars: ✭ 249 (+196.43%)
Mutual labels:  thrift
Thrift Tools
thrift-tools is a library and a set of tools to introspect Apache Thrift traffic.
Stars: ✭ 189 (+125%)
Mutual labels:  thrift

TypeScript Thrift Parser

A parser for Thrift written in TypeScript. The resulting AST can be used to codegen JavaScript from a Thrift file, or just to inspect the Thrift structure.

Usage

A successful parse returns a ThriftDocument object. An unsuccessful parse returns a ThriftErrors object.

import { parse, ThriftDocument } from '@creditkarma/thrift-parser'


const rawThrift: string =`
  struct MyStruct {
    1: required i32 id
  }
`;

const thriftAST: ThriftDocument | ThriftErrors = parse(rawThrift);

switch(thriftAST.type) {
  case 'ThriftDocument':
    // Do something with valid AST
  case 'ThriftErrors':
    // Report or recover from errors
}

You can also use Thrift Parser from the command line or npm scripts. When using from the command line the generated AST is saved to file as JSON.

$ thrift-parser --rootDir thrift --outDir thrift-json --fastFail false some_file.thrift

In this usage there are three options:

  • --rootDir: where to initiate file search and save
  • --outDir: relative to rootDir where to save output files
  • --fastFail: If true fail on first error encountered

Build

$ npm install
$ npm run build

Test

$ npm test

AST Structure

The root of the returned AST is either a ThriftDocument (successful parse) or a ThriftErrors (unsuccessful parse).

ThriftDocument

{
  type: "ThriftDocument",
  body: Array<ThriftStatement>
}

ThriftErrors

{
  type: "ThriftErrors",
  errors: Array<ThriftError>
}

ThriftError

A descriptor of what went wrong while parsing the specified Thrift source.

{
  type: "ParseError" | "ScanError",
  message: string,
  loc: TextLocation
}

Thrift Statements

Thrift Statements represent each of the main constructs that can be defined in Thrift source.

NamespaceDefinition

namespace <identifier> <identifier>
{
  type: "NamespaceDefinition",
  scope: Identifier,
  name: Identifier
}

IncludeDefinition

include '<path>'"
{
  type: "IncludeDefinition",
  path: StringLiteral
}

TypedefDefinition

typedef <field-type> <identifier>
{
  type: "TypedefDefinition",
  name: Identifier,
  definitionType: FieldType
}

ConstDefinition

const <field-type> <identifier> = <initializer>
{
  type: "ConstDefinition",
  name: Identifier,
  fieldType: FieldType,
  initializer: ConstValue,
}

EnumDefinition

enum <identifier> { <members> }
{
  type: "EnumDefinition",
  name: Identifier,
  members: Array<EnumMember>
}

StructDefinition

struct <identifier> { <fields> }
{
  type: "StructDefinition",
  name: Identifier,
  fields: Array<FieldDefinition>
}

UnionDefinition

union <identifier> { <fields> }
{
  type: "UnionDefinition",
  name: Identifier,
  fields: Array<FieldDefinition>
}

ExceptionDefinition

exception <identifier> { <fields> }
{
  type: "ExceptionDefinition",
  name: Identifier,
  fields: Array<FieldDefinition>
}

ServiceDefinition

service <identifier> (extends <identifier>)? { <functions> }
{
  type: "ServiceDefinition",
  name: Identifier,
  extends: Identifier | null,
  functions: Array<FunctionDefinition>
}

Viewing with ASTExplorer

ASTExplorer is a web app for visualizing ASTs. You type source. It shows you the resulting syntax tree based on the parser you've selected. I've included the integrations for this parser. To get that up and running you'll need to clone ASTExplorer.

$ git clone https://github.com/fkling/astexplorer.git
$ cd astexplorer/website
$ npm install

You will now need to install thrift-parser for ASTExplorer

$ npm install @creditkarma/thrift-parser

Cool, now we need to copy some stuff into the ASTExplorer project.

If the ASTExplorer project and the @creditkarma/thrift-parser project are siblings you can type this into the temrinal (from astexplorer/website)...

$ cp -r ../../thrift-parser/astexplorer/thrift ./src/parsers/thrift

You'll now need to build ASTExplorer and start the server

$ npm run build
$ npm start

By default this will start ASTExplorer on localhost:8080

There is a dropdown to select the language you want to use, choose 'Thrift IDL'

Note: I have had some trouble getting npm run build to work. However, the watch build is much more reliable.

$ npm run watch

Then in another terminal window run start.

$ npm start

Contributing

For more information about contributing new features and bug fixes, see our Contribution Guidelines. External contributors must sign Contributor License Agreement (CLA)

License

This project is licensed under Apache License Version 2.0

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].