Package Exports
- @creditkarma/thrift-parser
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@creditkarma/thrift-parser) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
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
import { parse, ThriftDocument } from '@creditkarma/thrift-parser'
const rawThrift: string =`
struct MyStruct {
1: required i32 id
}
`;
const thriftAST: ThriftDocument = parse(rawThrift);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.thriftIn 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 buildTest
$ npm testViewing 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
$ git submodule update --init
$ cd website/In another terminal window, (until we publish this parser) you'll need to npm link to get things to work.
From the root directory of this parser, where the package.json is...
$ npm linkThen back in your terminal for ASTExplorer (from astexplorer/website)...
$ npm link @creditkarma/thrift-parserCool, 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/thriftYou'll now need to build ASTExplorer and start the server
$ npm run build
$ npm startBy default this will start ASTExplorer on localhost:8080
There is a dropdown to select the language you want to use, choose 'Thrift IDL'
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