0.0.0 • Published 4 years ago

@byte-ferry/ferry-parser v0.0.0

Weekly downloads
-
License
MIT
Repository
-
Last release
4 years ago

ferry-parser

A parser for IDL extension specifications.

Table of Contents

Introduction

ferry-parser encapsulates IDL parsers and converts IDL extensions described by IDL extension specifications. Ferry-parser supports Thrift IDL and Proto IDL. Parsers for Thrift IDL and Proto IDL are separated to different modules, and The parser module for Thrift IDL is exported by the main index file.

Usage

Install

npm i -P @byte-ferry/ferry-parser

Parse Thrift IDL

import * as t from '@byte-ferry/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 IDL

import * as t from '@byte-ferry/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 IDL. 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 IDL. 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.

License

MIT