Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/rickyes/kiritobuf
Interface description language | Kirito ⚔
https://github.com/rickyes/kiritobuf
ast compiler idl kirito nodejs parser tokenizer
Last synced: 24 days ago
JSON representation
Interface description language | Kirito ⚔
- Host: GitHub
- URL: https://github.com/rickyes/kiritobuf
- Owner: rickyes
- License: mit
- Created: 2018-07-31T11:45:22.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2022-02-11T13:55:18.000Z (over 2 years ago)
- Last Synced: 2024-10-10T23:01:59.687Z (27 days ago)
- Topics: ast, compiler, idl, kirito, nodejs, parser, tokenizer
- Language: JavaScript
- Homepage:
- Size: 7.81 KB
- Stars: 11
- Watchers: 1
- Forks: 6
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# kiritobuf
Interface Description Language | Kirito
[![Travis](https://img.shields.io/travis/rickyes/kiritobuf.svg?style=for-the-badge)](https://travis-ci.org/rickyes/kiritobuf)
[![Node Version](https://img.shields.io/badge/node-%3E=9.0.0-brightgreen.svg?longCache=true&style=for-the-badge)](https://www.npmjs.com/package/kiritobuf)
[![npm](https://img.shields.io/npm/v/kiritobuf.svg?style=for-the-badge)](https://www.npmjs.com/package/kiritobuf)## Install
``` shell
$ npm i kiritobuf --save
```## Get Started
1. Define the `kirito` suffix file
```shell
# testservice testService {
method ping (reqMsg, resMsg)
}struct reqMsg {
@1 age = Int16;
@2 name = Text;
}struct resMsg {
@1 age = Int16;
@2 name = Text;
}
```
2. Generate `AST`
``` js
'use strict';const path = require('path');
const kirito = require('kiritobuf');
const kiritoProto = './test.kirito';const k = new kirito();
const AST = k.parse(path.join(__dirname, kiritoProto));
console.log(JSON.stringify(AST, null, 2));
```
3. AST struct
``` json
{
"type": "Program",
"body": [
{
"type": "StructDeclaration",
"name": "service",
"value": "testService",
"params": [
{
"type": "StructDeclaration",
"name": "method",
"value": "ping",
"params": [
{
"type": "Identifier",
"value": "reqMsg"
},
{
"type": "Identifier",
"value": "resMsg"
}
]
}
]
},
{
"type": "StructDeclaration",
"name": "struct",
"value": "reqMsg",
"params": [
{
"type": "VariableDeclaration",
"name": "@",
"value": "1",
"params": [
{
"type": "Identifier",
"value": "age"
},
{
"type": "DataType",
"value": "Int16"
}
]
},
{
"type": "VariableDeclaration",
"name": "@",
"value": "2",
"params": [
{
"type": "Identifier",
"value": "name"
},
{
"type": "DataType",
"value": "Text"
}
]
}
]
},
{
"type": "StructDeclaration",
"name": "struct",
"value": "resMsg",
"params": [
{
"type": "VariableDeclaration",
"name": "@",
"value": "1",
"params": [
{
"type": "Identifier",
"value": "age"
},
{
"type": "DataType",
"value": "Int16"
}
]
},
{
"type": "VariableDeclaration",
"name": "@",
"value": "2",
"params": [
{
"type": "Identifier",
"value": "name"
},
{
"type": "DataType",
"value": "Text"
}
]
}
]
}
]
}
```## Author
Kiritobuf © [Ricky 泽阳](https://github.com/rickyes), Released under the MIT License.