https://github.com/leaves4j/node-thrift-parser
Parse thrift IDL to an AST
https://github.com/leaves4j/node-thrift-parser
javascript parser thrift
Last synced: 4 months ago
JSON representation
Parse thrift IDL to an AST
- Host: GitHub
- URL: https://github.com/leaves4j/node-thrift-parser
- Owner: leaves4j
- Created: 2017-10-29T05:43:46.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2017-11-22T08:50:01.000Z (almost 8 years ago)
- Last Synced: 2025-05-15T20:14:47.340Z (5 months ago)
- Topics: javascript, parser, thrift
- Language: Thrift
- Homepage:
- Size: 160 KB
- Stars: 7
- Watchers: 1
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
Awesome Lists containing this project
README
node-thrift-parser
---
Parse thrift IDL to an AST## Installation
```bash
npm install node-thrift-parser -S
```## Example
```js
const parser = require('node-thrift-parser');
const ast = parser(`
/**
* test
*/include 'test.thrift'
namespace * thrift.testenum Numberz {
ONE = 1,
TWO
}typedef i64 UserId;
struct Bonk {
1: string message,
2: i32 type
}exception Xception {
1: i32 errorCode,
2: string message
}service ThriftTest {
void testVoid(),
string testString(1: string thing) throws (1: Xception e),
}
`);```
result```json
{
"headers": [
{
"type": "include",
"path": "'test.thrift'"
},
{
"type": "namespace",
"namespaceScope": "*",
"identifier": "thrift.test"
}
],
"definitions": [
{
"type": "enum",
"identifier": "Numberz",
"enumFields": [
{
"type": "enumField",
"identifier": "ONE",
"value": "1"
},
{
"type": "enumField",
"identifier": "TWO",
"value": null
}
]
},
{
"type": "typedef",
"definitionType": "i64",
"identifier": "UserId"
},
{
"type": "struct",
"identifier": "Bonk",
"fields": [
{
"id": "1",
"option": null,
"fieldType": "string",
"identifier": "message",
"defaultValue": null
},
{
"id": "2",
"option": null,
"fieldType": "i32",
"identifier": "type",
"defaultValue": null
}
]
},
{
"type": "exception",
"identifier": "Xception",
"fields": [
{
"id": "1",
"option": null,
"fieldType": "i32",
"identifier": "errorCode",
"defaultValue": null
},
{
"id": "2",
"option": null,
"fieldType": "string",
"identifier": "message",
"defaultValue": null
}
]
},
{
"type": "service",
"identifier": "ThriftTest",
"extendIdentifier": null,
"functions": [
{
"type": "function",
"functionType": "void",
"identifier": "testVoid",
"oneway": null,
"args": [],
"throws": null
},
{
"type": "function",
"functionType": "string",
"identifier": "testString",
"oneway": null,
"args": [
{
"id": "1",
"option": null,
"fieldType": "string",
"identifier": "thing",
"defaultValue": null
}
],
"throws": [
{
"id": "1",
"option": null,
"fieldType": "Xception",
"identifier": "e",
"defaultValue": null
}
]
}
]
}
]
}```
## ChangeLog[ChangeLog](./CHANGELOG.md)
## License
MIT