README
English | 简体中文
ferry-parser
a Ferry parser written in JavaScript. It parses Thrift IDL and Proto IDL files to ASTs, and parses the extended informations to certain fields according to the Ferry extension specification.
Install
$ npm i @byte-ferry/parser
Usage
parse thrift files
import * as t from '@byte-ferry/parser';
// alternatively, const idl = `<thrift-file-path>/example.thrift`
const idl = `
struct Foo {
1: i32 code (api.position = 'query')
2: string content
}
`;
const document = t.parse(idl);
console.log(JSON.stringify(document, null, 2));
parse proto files
import * as t from '@byte-ferry/parser/dist/proto';
// alternatively, const idl = `<proto-file-path>/example.proto`
const idl = `
syntax = 'proto3';
message Foo {
int32 code = 1 [(api.position) = 'query'];
string content = 2;
}
`;
const document = t.parse(idl);
console.log(JSON.stringify(document, null, 2));
API
parse(source: string, option?: ParseOption): ThriftDocument
parse thrift files. source
should be assigned with the path or content of a thrift file. ParseOption
is defined below:
interface ParseOption {
// set whether to revise the positions of tail comments. the default value is true.
reviseTailComment?: boolean
}
parse(source: string): ProtoDocument
parse proto files. source
should be assigned with the path or content of a proto file. A revision for the positions of tail comments in proto files is not supported now.