0.4.2 • Published 9 years ago

thrift-parser v0.4.2

Weekly downloads
34
License
MIT
Repository
-
Last release
9 years ago

thrift-parser

To parse thrift file to a AST.

Demo

let thriftParser = require('thrift-parser');

let ast = thriftParser(`

struct MyStruct {
    1: required int id,
    2: required bool field1,
    # 3: required string field,
    4: required i16 field,
}
exception Exception1 {
    1: required i32 error_code,
    2: required string error_name,
    3: optional string message,
}
exception Exception2 {
    1: required i32 error_code,
    2: required string error_name,
    3: optional string message,
}
service Service1 {
    bool ping() throws (1: Exception1 user_exception, 2: Exception2 system_exception)
    list<MyStruct> test(1: MyStruct ms)
        throws (1: Exception1 user_exception, 2: Exception2 system_exception)
}

`);

Results

{
  "struct": {
    "MyStruct": [
      {
        "id": 1,
        "option": "required",
        "type": "int",
        "name": "id"
      },
      {
        "id": 2,
        "option": "required",
        "type": "bool",
        "name": "field1"
      },
      {
        "id": 4,
        "option": "required",
        "type": "i16",
        "name": "field"
      }
    ]
  },
  "exception": {
    "Exception1": [
      {
        "id": 1,
        "option": "required",
        "type": "i32",
        "name": "error_code"
      },
      {
        "id": 2,
        "option": "required",
        "type": "string",
        "name": "error_name"
      },
      {
        "id": 3,
        "option": "optional",
        "type": "string",
        "name": "message"
      }
    ],
    "Exception2": [
      {
        "id": 1,
        "option": "required",
        "type": "i32",
        "name": "error_code"
      },
      {
        "id": 2,
        "option": "required",
        "type": "string",
        "name": "error_name"
      },
      {
        "id": 3,
        "option": "optional",
        "type": "string",
        "name": "message"
      }
    ]
  },
  "service": {
    "Service1": {
      "functions": {
        "ping": {
          "type": "bool",
          "name": "ping",
          "args": [],
          "throws": [
            {
              "id": 1,
              "type": "Exception1",
              "name": "user_exception"
            },
            {
              "id": 2,
              "type": "Exception2",
              "name": "system_exception"
            }
          ],
          "oneway": false
        },
        "test": {
          "type": {
            "name": "list",
            "valueType": "MyStruct"
          },
          "name": "test",
          "args": [
            {
              "id": 1,
              "type": "MyStruct",
              "name": "ms"
            }
          ],
          "throws": [
            {
              "id": 1,
              "type": "Exception1",
              "name": "user_exception"
            },
            {
              "id": 2,
              "type": "Exception2",
              "name": "system_exception"
            }
          ],
          "oneway": false
        }
      }
    }
  }
}
0.4.2

9 years ago

0.4.1

9 years ago

0.4.0

9 years ago

0.3.3

9 years ago

0.3.2

9 years ago

0.3.1

9 years ago

0.3.0

9 years ago

0.2.9

9 years ago

0.2.8

9 years ago

0.2.7

9 years ago

0.2.6

10 years ago

0.2.5

10 years ago

0.2.4

10 years ago

0.2.3

10 years ago

0.2.2

10 years ago

0.2.1

10 years ago

0.2.0

10 years ago

0.1.0

10 years ago