@freelog/freelog-cg-collection 1.0.16 → 1.0.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CollectionPolicyCustomVisitor.js +18 -2
- package/dist/contract-declaration-executor/DefaultContractDeclarationExecutor.d.ts +4 -0
- package/dist/contract-declaration-executor/DefaultContractDeclarationExecutor.js +10 -0
- package/index.js +2 -0
- package/package.json +1 -1
- package/src/contract-declaration-executor/DefaultContractDeclarationExecutor.ts +7 -0
|
@@ -13,6 +13,7 @@ class CollectionPolicyCustomVisitor extends CollectionPolicyVisitor {
|
|
|
13
13
|
// 签约条件
|
|
14
14
|
this.audienceSection = {conditions: []};
|
|
15
15
|
this.contractDeclarationSection = {contractDeclarations: []};
|
|
16
|
+
this.varContractDeclarationList = [];
|
|
16
17
|
// 全局定义(变量)声明
|
|
17
18
|
this.varDeclarationList = [];
|
|
18
19
|
// 状态机
|
|
@@ -55,6 +56,9 @@ class CollectionPolicyCustomVisitor extends CollectionPolicyVisitor {
|
|
|
55
56
|
if (system_keywords.varList.indexOf(varName) !== -1) {
|
|
56
57
|
throw new Error(`不能和系统关键字同名 --- ${varName}`);
|
|
57
58
|
}
|
|
59
|
+
if (this.varContractDeclarationList.find(cd => cd["varValueObj"]["varName"] === varName) != null) {
|
|
60
|
+
throw new Error(`已存在合约声明的变量 --- ${varName}`);
|
|
61
|
+
}
|
|
58
62
|
if (this.varDeclarationList.find(vd => vd["varName"] === varName) != null) {
|
|
59
63
|
throw new Error(`不能重复定义同名的全局变量 --- ${varName}`);
|
|
60
64
|
}
|
|
@@ -69,6 +73,13 @@ class CollectionPolicyCustomVisitor extends CollectionPolicyVisitor {
|
|
|
69
73
|
variables.push({name: c, scope: "context"});
|
|
70
74
|
}
|
|
71
75
|
if (this.parseState.inFsmState === 1 || this.parseState.inFsmEvent === 1) {
|
|
76
|
+
for (let v of this.varContractDeclarationList) {
|
|
77
|
+
variables.push({
|
|
78
|
+
name: v["varValueObj"]["varName"],
|
|
79
|
+
type: v["varValueObj"]["varValueType"],
|
|
80
|
+
scope: "global"
|
|
81
|
+
});
|
|
82
|
+
}
|
|
72
83
|
for (let v of this.varDeclarationList) {
|
|
73
84
|
variables.push({name: v["varName"], type: v["varValueType"], scope: "global"});
|
|
74
85
|
}
|
|
@@ -138,13 +149,14 @@ class CollectionPolicyCustomVisitor extends CollectionPolicyVisitor {
|
|
|
138
149
|
}
|
|
139
150
|
|
|
140
151
|
visitContract_declaration(ctx) {
|
|
152
|
+
let keyword = ctx.contract_declaration_expression().contractDeclarationKeyword.text;
|
|
141
153
|
let result = {
|
|
142
154
|
type: "contractDeclaration",
|
|
143
155
|
content: ctx.getText(),
|
|
144
|
-
keywords: [
|
|
156
|
+
keywords: [keyword],
|
|
145
157
|
varValueObj: {
|
|
146
158
|
expType: "varContractDeclaration",
|
|
147
|
-
keyword:
|
|
159
|
+
keyword: keyword,
|
|
148
160
|
type: ctx.contract_declaration_expression().contract_declaration_type().getText(),
|
|
149
161
|
conditions: this.visitExpression_param_list(ctx.contract_declaration_expression().expression_param_list()),
|
|
150
162
|
varName: ctx.contract_declaration_variable().getText(),
|
|
@@ -154,6 +166,10 @@ class CollectionPolicyCustomVisitor extends CollectionPolicyVisitor {
|
|
|
154
166
|
};
|
|
155
167
|
this.contractDeclarationSection.contractDeclarations.push(result);
|
|
156
168
|
|
|
169
|
+
if (result["type"] === "contractDeclaration" && result["varValueObj"] != null && result["varValueObj"]["expType"] === "varContractDeclaration") {
|
|
170
|
+
this.varContractDeclarationList.push(result);
|
|
171
|
+
}
|
|
172
|
+
|
|
157
173
|
return super.visitContract_declaration(ctx);
|
|
158
174
|
}
|
|
159
175
|
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DefaultContractDeclarationExecutor = void 0;
|
|
4
|
+
class DefaultContractDeclarationExecutor {
|
|
5
|
+
execute(keyword, dataObj) {
|
|
6
|
+
throw new Error("这是个空实现,不能被调用!");
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
exports.DefaultContractDeclarationExecutor = DefaultContractDeclarationExecutor;
|
|
10
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiRGVmYXVsdENvbnRyYWN0RGVjbGFyYXRpb25FeGVjdXRvci5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9jb250cmFjdC1kZWNsYXJhdGlvbi1leGVjdXRvci9EZWZhdWx0Q29udHJhY3REZWNsYXJhdGlvbkV4ZWN1dG9yLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7OztBQUVBLE1BQXNCLGtDQUFrQztJQUNwRCxPQUFPLENBQUMsT0FBZSxFQUFFLE9BQVk7UUFDakMsTUFBTSxJQUFJLEtBQUssQ0FBQyxlQUFlLENBQUMsQ0FBQztJQUNyQyxDQUFDO0NBQ0o7QUFKRCxnRkFJQyJ9
|
package/index.js
CHANGED
|
@@ -12,6 +12,7 @@ const {FunctionInvoke} = require("./dist/interface/FunctionInvoke");
|
|
|
12
12
|
const {VarContextCapable} = require("./dist/interface/VarContextCapable");
|
|
13
13
|
const {FunctionHelper} = require("./dist/helper/FunctionHelper");
|
|
14
14
|
const {ExpHelper} = require("./dist/helper/ExpHelper");
|
|
15
|
+
const {DefaultContractDeclarationExecutor} = require("./dist/contract-declaration-executor/DefaultContractDeclarationExecutor");
|
|
15
16
|
const {DefaultFunctionExecutor} = require("./dist/function-executor/DefaultFunctionExecutor");
|
|
16
17
|
|
|
17
18
|
exports.PolicyHelper = PolicyHelper;
|
|
@@ -20,6 +21,7 @@ exports.ExpHelper = ExpHelper;
|
|
|
20
21
|
exports.FunctionInvoke = FunctionInvoke;
|
|
21
22
|
exports.VarContextCapable = VarContextCapable;
|
|
22
23
|
|
|
24
|
+
exports.DefaultContractDeclarationExecutor = DefaultContractDeclarationExecutor;
|
|
23
25
|
exports.DefaultFunctionExecutor = DefaultFunctionExecutor;
|
|
24
26
|
|
|
25
27
|
exports.compile = async function (serviceName, policyText) {
|
package/package.json
CHANGED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import {ContractDeclarationExecute} from "../interface/ContractDeclarationExecute";
|
|
2
|
+
|
|
3
|
+
export abstract class DefaultContractDeclarationExecutor implements ContractDeclarationExecute{
|
|
4
|
+
execute(keyword: string, dataObj: any): any {
|
|
5
|
+
throw new Error("这是个空实现,不能被调用!");
|
|
6
|
+
}
|
|
7
|
+
}
|