Interface Description Language | Kirito
$ npm i kiritobuf --save
- Define the
kirito
suffix file
# test
service testService {
method ping (reqMsg, resMsg)
}
struct reqMsg {
@1 age = Int16;
@2 name = Text;
}
struct resMsg {
@1 age = Int16;
@2 name = Text;
}
- Generate
AST
'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));
- AST struct
{
"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"
}
]
}
]
}
]
}
Kiritobuf © Ricky 泽阳, Released under the MIT License.