@rsconcept/domain 1.0.0 → 1.2.0
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/README.md +3 -3
- package/dist/analyzer-DlSq3Y3r.d.ts +39 -0
- package/dist/arguments-extractor-1acwjQNc.d.ts +38 -0
- package/dist/ast-C8sIpKdL.d.ts +51 -0
- package/dist/ast-annotations-BiMjkKvz.d.ts +16 -0
- package/dist/branded-ZlzIcxzu.d.ts +9 -0
- package/dist/calculator-C9W2jkSx.d.ts +39 -0
- package/dist/cctext/index.d.ts +2 -1
- package/dist/cctext/index.js +2 -42
- package/dist/cctext/language-api.d.ts +10 -12
- package/dist/cctext/language-api.js +157 -227
- package/dist/cctext/language-api.js.map +1 -1
- package/dist/cctext/language.d.ts +24 -22
- package/dist/cctext/language.js +43 -39
- package/dist/cctext/language.js.map +1 -1
- package/dist/error-E1LVq_3w.d.ts +87 -0
- package/dist/graph/graph.d.ts +2 -62
- package/dist/graph/graph.js +339 -382
- package/dist/graph/graph.js.map +1 -1
- package/dist/graph/index.d.ts +2 -1
- package/dist/graph/index.js +2 -384
- package/dist/graph-DR8rL2o3.d.ts +64 -0
- package/dist/hash-Y8I4c6Al.d.ts +8 -0
- package/dist/index-BKZ67WMa.d.ts +1 -0
- package/dist/index-BVVgDSdq.d.ts +1 -0
- package/dist/index-DmtQKWjk.d.ts +1 -0
- package/dist/index-_6s0AX1B.d.ts +1 -0
- package/dist/index.d.ts +27 -28
- package/dist/index.js +23 -5851
- package/dist/lezer-tree-iS7LpLBJ.d.ts +14 -0
- package/dist/library/folder-tree.d.ts +22 -20
- package/dist/library/folder-tree.js +108 -130
- package/dist/library/folder-tree.js.map +1 -1
- package/dist/library/index.d.ts +8 -17
- package/dist/library/index.js +7 -2800
- package/dist/library/library-api.d.ts +3 -1
- package/dist/library/library-api.js +9 -8
- package/dist/library/library-api.js.map +1 -1
- package/dist/library/library.d.ts +2 -56
- package/dist/library/library.js +23 -19
- package/dist/library/library.js.map +1 -1
- package/dist/library/oss-api.d.ts +26 -37
- package/dist/library/oss-api.js +258 -1096
- package/dist/library/oss-api.js.map +1 -1
- package/dist/library/oss-layout-api.d.ts +28 -28
- package/dist/library/oss-layout-api.js +239 -316
- package/dist/library/oss-layout-api.js.map +1 -1
- package/dist/library/oss-layout.d.ts +2 -25
- package/dist/library/oss-layout.js +1 -1
- package/dist/library/oss.d.ts +87 -89
- package/dist/library/oss.js +27 -26
- package/dist/library/oss.js.map +1 -1
- package/dist/library/rsengine.d.ts +100 -106
- package/dist/library/rsengine.js +439 -2599
- package/dist/library/rsengine.js.map +1 -1
- package/dist/library/rsform-api.d.ts +11 -16
- package/dist/library/rsform-api.js +313 -825
- package/dist/library/rsform-api.js.map +1 -1
- package/dist/library/rsform.d.ts +159 -167
- package/dist/library/rsform.js +29 -28
- package/dist/library/rsform.js.map +1 -1
- package/dist/library/rsmodel-api.d.ts +8 -15
- package/dist/library/rsmodel-api.js +172 -813
- package/dist/library/rsmodel-api.js.map +1 -1
- package/dist/library/rsmodel.d.ts +27 -33
- package/dist/library/rsmodel.js +16 -23
- package/dist/library/rsmodel.js.map +1 -1
- package/dist/library/structure-planner.d.ts +20 -26
- package/dist/library/structure-planner.js +106 -474
- package/dist/library/structure-planner.js.map +1 -1
- package/dist/library-CYun28Xz.d.ts +58 -0
- package/dist/oss-layout-3glgAqfn.d.ts +27 -0
- package/dist/parser-Bwd8LxJ1.d.ts +7 -0
- package/dist/parsing/ast.d.ts +2 -49
- package/dist/parsing/ast.js +68 -76
- package/dist/parsing/ast.js.map +1 -1
- package/dist/parsing/index.d.ts +3 -3
- package/dist/parsing/index.js +3 -141
- package/dist/parsing/lezer-tree.d.ts +2 -13
- package/dist/parsing/lezer-tree.js +50 -43
- package/dist/parsing/lezer-tree.js.map +1 -1
- package/dist/rslang/api.d.ts +9 -14
- package/dist/rslang/api.js +114 -827
- package/dist/rslang/api.js.map +1 -1
- package/dist/rslang/ast-annotations.d.ts +2 -18
- package/dist/rslang/ast-annotations.js +34 -45
- package/dist/rslang/ast-annotations.js.map +1 -1
- package/dist/rslang/error.d.ts +2 -85
- package/dist/rslang/error.js +88 -150
- package/dist/rslang/error.js.map +1 -1
- package/dist/rslang/eval/calculator.d.ts +2 -43
- package/dist/rslang/eval/calculator.js +81 -1636
- package/dist/rslang/eval/calculator.js.map +1 -1
- package/dist/rslang/eval/evaluation-cache.d.ts +22 -26
- package/dist/rslang/eval/evaluation-cache.js +168 -287
- package/dist/rslang/eval/evaluation-cache.js.map +1 -1
- package/dist/rslang/eval/evaluator.d.ts +59 -63
- package/dist/rslang/eval/evaluator.js +602 -1509
- package/dist/rslang/eval/evaluator.js.map +1 -1
- package/dist/rslang/eval/value-api.d.ts +2 -48
- package/dist/rslang/eval/value-api.js +2 -490
- package/dist/rslang/eval/value.d.ts +2 -36
- package/dist/rslang/eval/value.js +2 -118
- package/dist/rslang/index.d.ts +14 -17
- package/dist/rslang/index.js +12 -4314
- package/dist/rslang/labels.d.ts +6 -6
- package/dist/rslang/labels.js +139 -305
- package/dist/rslang/labels.js.map +1 -1
- package/dist/rslang/parser/expression-generator.d.ts +5 -5
- package/dist/rslang/parser/expression-generator.js +248 -446
- package/dist/rslang/parser/expression-generator.js.map +1 -1
- package/dist/rslang/parser/normalize.d.ts +4 -8
- package/dist/rslang/parser/normalize.js +286 -481
- package/dist/rslang/parser/normalize.js.map +1 -1
- package/dist/rslang/parser/parser.d.ts +2 -5
- package/dist/rslang/parser/parser.js +30 -21
- package/dist/rslang/parser/parser.js.map +1 -1
- package/dist/rslang/parser/parser.terms.d.ts +43 -41
- package/dist/rslang/parser/parser.terms.js +44 -83
- package/dist/rslang/parser/parser.terms.js.map +1 -1
- package/dist/rslang/parser/syntax-errors.d.ts +5 -8
- package/dist/rslang/parser/syntax-errors.js +113 -382
- package/dist/rslang/parser/syntax-errors.js.map +1 -1
- package/dist/rslang/parser/token.d.ts +2 -79
- package/dist/rslang/parser/token.js +81 -93
- package/dist/rslang/parser/token.js.map +1 -1
- package/dist/rslang/semantic/analyzer.d.ts +2 -39
- package/dist/rslang/semantic/analyzer.js +186 -2600
- package/dist/rslang/semantic/analyzer.js.map +1 -1
- package/dist/rslang/semantic/arguments-extractor.d.ts +2 -42
- package/dist/rslang/semantic/arguments-extractor.js +202 -361
- package/dist/rslang/semantic/arguments-extractor.js.map +1 -1
- package/dist/rslang/semantic/type-auditor.d.ts +64 -68
- package/dist/rslang/semantic/type-auditor.js +594 -1564
- package/dist/rslang/semantic/type-auditor.js.map +1 -1
- package/dist/rslang/semantic/typification-api.d.ts +4 -7
- package/dist/rslang/semantic/typification-api.js +162 -303
- package/dist/rslang/semantic/typification-api.js.map +1 -1
- package/dist/rslang/semantic/typification-parser.d.ts +2 -12
- package/dist/rslang/semantic/typification-parser.js +165 -219
- package/dist/rslang/semantic/typification-parser.js.map +1 -1
- package/dist/rslang/semantic/typification.d.ts +2 -119
- package/dist/rslang/semantic/typification.js +66 -52
- package/dist/rslang/semantic/typification.js.map +1 -1
- package/dist/rslang/semantic/value-auditor.d.ts +32 -38
- package/dist/rslang/semantic/value-auditor.js +206 -518
- package/dist/rslang/semantic/value-auditor.js.map +1 -1
- package/dist/rslang/semantic/value-class.d.ts +2 -10
- package/dist/rslang/semantic/value-class.js +8 -7
- package/dist/rslang/semantic/value-class.js.map +1 -1
- package/dist/rslang/typification-graph.d.ts +2 -33
- package/dist/rslang/typification-graph.js +94 -306
- package/dist/rslang/typification-graph.js.map +1 -1
- package/dist/shared/branded.d.ts +2 -7
- package/dist/shared/branded.js +1 -1
- package/dist/shared/hash.d.ts +2 -6
- package/dist/shared/hash.js +13 -13
- package/dist/shared/hash.js.map +1 -1
- package/dist/shared/index.d.ts +3 -2
- package/dist/shared/index.js +2 -18
- package/dist/token-DeXAmzwr.d.ts +81 -0
- package/dist/typification-Dk-fisgO.d.ts +120 -0
- package/dist/typification-graph-6HcZ-rKH.d.ts +30 -0
- package/dist/typification-parser-BBVx1RxP.d.ts +13 -0
- package/dist/value-B8UtCqaK.js +366 -0
- package/dist/value-B8UtCqaK.js.map +1 -0
- package/dist/value-CTjX6825.d.ts +33 -0
- package/dist/value-api-Bw-SgaYY.d.ts +49 -0
- package/dist/value-class-CNI-lqXJ.d.ts +12 -0
- package/package.json +8 -8
- package/src/library/oss-api.test.ts +76 -0
- package/src/library/oss-api.ts +4 -1
- package/src/library/rsform-api.test.ts +24 -0
- package/src/library/rsform-api.ts +12 -4
- package/dist/cctext/index.js.map +0 -1
- package/dist/graph/index.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/library/index.js.map +0 -1
- package/dist/library/oss-layout.js.map +0 -1
- package/dist/parsing/index.js.map +0 -1
- package/dist/rslang/eval/value-api.js.map +0 -1
- package/dist/rslang/eval/value.js.map +0 -1
- package/dist/rslang/index.js.map +0 -1
- package/dist/shared/branded.js.map +0 -1
- package/dist/shared/index.js.map +0 -1
package/dist/library/oss-api.js
CHANGED
|
@@ -1,1105 +1,267 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
}
|
|
14
|
-
clone() {
|
|
15
|
-
const result = new _GraphNode(this.id);
|
|
16
|
-
result.outputs = [...this.outputs];
|
|
17
|
-
result.inputs = [...this.inputs];
|
|
18
|
-
return result;
|
|
19
|
-
}
|
|
20
|
-
addOutput(node) {
|
|
21
|
-
this.outputs.push(node);
|
|
22
|
-
}
|
|
23
|
-
addInput(node) {
|
|
24
|
-
this.inputs.push(node);
|
|
25
|
-
}
|
|
26
|
-
removeInput(target) {
|
|
27
|
-
const index = this.inputs.findIndex((node) => node === target);
|
|
28
|
-
return index > -1 ? this.inputs.splice(index, 1)[0] : null;
|
|
29
|
-
}
|
|
30
|
-
removeOutput(target) {
|
|
31
|
-
const index = this.outputs.findIndex((node) => node === target);
|
|
32
|
-
return index > -1 ? this.outputs.splice(index, 1)[0] : null;
|
|
33
|
-
}
|
|
34
|
-
};
|
|
35
|
-
var Graph = class _Graph {
|
|
36
|
-
/** Map of nodes. */
|
|
37
|
-
nodes = /* @__PURE__ */ new Map();
|
|
38
|
-
constructor(arr) {
|
|
39
|
-
if (!arr) {
|
|
40
|
-
return;
|
|
41
|
-
}
|
|
42
|
-
arr.forEach((edge) => {
|
|
43
|
-
if (edge.length === 1) {
|
|
44
|
-
this.addNode(edge[0]);
|
|
45
|
-
} else {
|
|
46
|
-
this.addEdge(edge[0], edge[1]);
|
|
47
|
-
}
|
|
48
|
-
});
|
|
49
|
-
}
|
|
50
|
-
clone() {
|
|
51
|
-
const result = new _Graph();
|
|
52
|
-
this.nodes.forEach((node) => result.nodes.set(node.id, node.clone()));
|
|
53
|
-
return result;
|
|
54
|
-
}
|
|
55
|
-
at(target) {
|
|
56
|
-
return this.nodes.get(target);
|
|
57
|
-
}
|
|
58
|
-
addNode(target) {
|
|
59
|
-
let node = this.nodes.get(target);
|
|
60
|
-
if (!node) {
|
|
61
|
-
node = new GraphNode(target);
|
|
62
|
-
this.nodes.set(target, node);
|
|
63
|
-
}
|
|
64
|
-
return node;
|
|
65
|
-
}
|
|
66
|
-
hasNode(target) {
|
|
67
|
-
return !!this.nodes.get(target);
|
|
68
|
-
}
|
|
69
|
-
removeNode(target) {
|
|
70
|
-
this.nodes.forEach((node) => {
|
|
71
|
-
node.removeInput(target);
|
|
72
|
-
node.removeOutput(target);
|
|
73
|
-
});
|
|
74
|
-
this.nodes.delete(target);
|
|
75
|
-
}
|
|
76
|
-
foldNode(target) {
|
|
77
|
-
const nodeToRemove = this.nodes.get(target);
|
|
78
|
-
if (!nodeToRemove) {
|
|
79
|
-
return;
|
|
80
|
-
}
|
|
81
|
-
nodeToRemove.inputs.forEach((input) => {
|
|
82
|
-
nodeToRemove.outputs.forEach((output) => {
|
|
83
|
-
this.addEdge(input, output);
|
|
84
|
-
});
|
|
85
|
-
});
|
|
86
|
-
this.removeNode(target);
|
|
87
|
-
}
|
|
88
|
-
removeIsolated() {
|
|
89
|
-
const result = [];
|
|
90
|
-
this.nodes.forEach((node) => {
|
|
91
|
-
if (node.outputs.length === 0 && node.inputs.length === 0) {
|
|
92
|
-
result.push(node);
|
|
93
|
-
this.nodes.delete(node.id);
|
|
94
|
-
}
|
|
95
|
-
});
|
|
96
|
-
return result;
|
|
97
|
-
}
|
|
98
|
-
addEdge(source, destination) {
|
|
99
|
-
if (this.hasEdge(source, destination)) {
|
|
100
|
-
return;
|
|
101
|
-
}
|
|
102
|
-
const sourceNode = this.addNode(source);
|
|
103
|
-
const destinationNode = this.addNode(destination);
|
|
104
|
-
sourceNode.addOutput(destinationNode.id);
|
|
105
|
-
destinationNode.addInput(sourceNode.id);
|
|
106
|
-
}
|
|
107
|
-
removeEdge(source, destination) {
|
|
108
|
-
const sourceNode = this.nodes.get(source);
|
|
109
|
-
const destinationNode = this.nodes.get(destination);
|
|
110
|
-
if (sourceNode && destinationNode) {
|
|
111
|
-
sourceNode.removeOutput(destination);
|
|
112
|
-
destinationNode.removeInput(source);
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
hasEdge(source, destination) {
|
|
116
|
-
const sourceNode = this.nodes.get(source);
|
|
117
|
-
if (!sourceNode) {
|
|
118
|
-
return false;
|
|
119
|
-
}
|
|
120
|
-
return !!sourceNode.outputs.find((id) => id === destination);
|
|
121
|
-
}
|
|
122
|
-
isReachable(source, destination) {
|
|
123
|
-
return this.expandAllOutputs([source]).includes(destination);
|
|
124
|
-
}
|
|
125
|
-
rootNodes() {
|
|
126
|
-
return [...this.nodes.keys()].filter((id) => !this.nodes.get(id)?.inputs.length);
|
|
127
|
-
}
|
|
128
|
-
expandOutputs(origin) {
|
|
129
|
-
const result = [];
|
|
130
|
-
origin.forEach((id) => {
|
|
131
|
-
const node = this.nodes.get(id);
|
|
132
|
-
if (node) {
|
|
133
|
-
node.outputs.forEach((child) => {
|
|
134
|
-
if (!origin.includes(child) && !result.includes(child)) {
|
|
135
|
-
result.push(child);
|
|
136
|
-
}
|
|
137
|
-
});
|
|
138
|
-
}
|
|
139
|
-
});
|
|
140
|
-
return result;
|
|
141
|
-
}
|
|
142
|
-
expandInputs(origin) {
|
|
143
|
-
const result = [];
|
|
144
|
-
origin.forEach((id) => {
|
|
145
|
-
const node = this.nodes.get(id);
|
|
146
|
-
if (node) {
|
|
147
|
-
node.inputs.forEach((child) => {
|
|
148
|
-
if (!origin.includes(child) && !result.includes(child)) {
|
|
149
|
-
result.push(child);
|
|
150
|
-
}
|
|
151
|
-
});
|
|
152
|
-
}
|
|
153
|
-
});
|
|
154
|
-
return result;
|
|
155
|
-
}
|
|
156
|
-
expandAllOutputs(origin) {
|
|
157
|
-
const result = this.expandOutputs(origin);
|
|
158
|
-
if (result.length === 0) {
|
|
159
|
-
return [];
|
|
160
|
-
}
|
|
161
|
-
const marked = /* @__PURE__ */ new Map();
|
|
162
|
-
origin.forEach((id) => marked.set(id, true));
|
|
163
|
-
let position = 0;
|
|
164
|
-
while (position < result.length) {
|
|
165
|
-
const node = this.nodes.get(result[position]);
|
|
166
|
-
if (node && !marked.get(node.id)) {
|
|
167
|
-
marked.set(node.id, true);
|
|
168
|
-
node.outputs.forEach((child) => {
|
|
169
|
-
if (!marked.get(child) && !result.find((id) => id === child)) {
|
|
170
|
-
result.push(child);
|
|
171
|
-
}
|
|
172
|
-
});
|
|
173
|
-
}
|
|
174
|
-
position += 1;
|
|
175
|
-
}
|
|
176
|
-
return result;
|
|
177
|
-
}
|
|
178
|
-
expandAllInputs(origin) {
|
|
179
|
-
const result = this.expandInputs(origin);
|
|
180
|
-
if (result.length === 0) {
|
|
181
|
-
return [];
|
|
182
|
-
}
|
|
183
|
-
const marked = /* @__PURE__ */ new Map();
|
|
184
|
-
origin.forEach((id) => marked.set(id, true));
|
|
185
|
-
let position = 0;
|
|
186
|
-
while (position < result.length) {
|
|
187
|
-
const node = this.nodes.get(result[position]);
|
|
188
|
-
if (node && !marked.get(node.id)) {
|
|
189
|
-
marked.set(node.id, true);
|
|
190
|
-
node.inputs.forEach((child) => {
|
|
191
|
-
if (!marked.get(child) && !result.find((id) => id === child)) {
|
|
192
|
-
result.push(child);
|
|
193
|
-
}
|
|
194
|
-
});
|
|
195
|
-
}
|
|
196
|
-
position += 1;
|
|
197
|
-
}
|
|
198
|
-
return result;
|
|
199
|
-
}
|
|
200
|
-
maximizePart(origin) {
|
|
201
|
-
const outputs = this.expandAllOutputs(origin);
|
|
202
|
-
const result = [...origin];
|
|
203
|
-
this.topologicalOrder().filter((id) => outputs.includes(id)).forEach((id) => {
|
|
204
|
-
const node = this.nodes.get(id);
|
|
205
|
-
if (node?.inputs.every((parent) => result.includes(parent))) {
|
|
206
|
-
result.push(id);
|
|
207
|
-
}
|
|
208
|
-
});
|
|
209
|
-
return result;
|
|
210
|
-
}
|
|
211
|
-
topologicalOrder() {
|
|
212
|
-
const result = [];
|
|
213
|
-
const marked = /* @__PURE__ */ new Set();
|
|
214
|
-
const nodeStack = [];
|
|
215
|
-
this.nodes.forEach((node) => {
|
|
216
|
-
if (marked.has(node.id)) {
|
|
217
|
-
return;
|
|
218
|
-
}
|
|
219
|
-
nodeStack.push(node.id);
|
|
220
|
-
while (nodeStack.length > 0) {
|
|
221
|
-
const item = nodeStack[nodeStack.length - 1];
|
|
222
|
-
if (marked.has(item)) {
|
|
223
|
-
if (!result.find((id) => id === item)) {
|
|
224
|
-
result.push(item);
|
|
225
|
-
}
|
|
226
|
-
nodeStack.pop();
|
|
227
|
-
} else {
|
|
228
|
-
marked.add(item);
|
|
229
|
-
const itemNode = this.nodes.get(item);
|
|
230
|
-
if (itemNode && itemNode.outputs.length > 0) {
|
|
231
|
-
itemNode.outputs.forEach((child) => {
|
|
232
|
-
if (!marked.has(child)) {
|
|
233
|
-
nodeStack.push(child);
|
|
234
|
-
}
|
|
235
|
-
});
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
});
|
|
240
|
-
return result.reverse();
|
|
241
|
-
}
|
|
242
|
-
/**
|
|
243
|
-
* Stably reorders the given node ids so that, for this DAG, no node appears before a transitive
|
|
244
|
-
* successor (edges: source → dependent; {@link GraphNode.outputs} lists dependents).
|
|
245
|
-
*/
|
|
246
|
-
sortStable(target) {
|
|
247
|
-
if (target.length <= 1) {
|
|
248
|
-
return [...target];
|
|
249
|
-
}
|
|
250
|
-
const reachable = this.buildTransitiveClosureForSort();
|
|
251
|
-
const testSet = /* @__PURE__ */ new Set();
|
|
252
|
-
const result = [];
|
|
253
|
-
for (const nodeId of [...target].reverse()) {
|
|
254
|
-
const nodeReachable = reachable.get(nodeId) ?? /* @__PURE__ */ new Set();
|
|
255
|
-
const needMove = testSet.has(nodeId);
|
|
256
|
-
for (const childId of nodeReachable) {
|
|
257
|
-
testSet.add(childId);
|
|
258
|
-
}
|
|
259
|
-
if (!needMove) {
|
|
260
|
-
result.push(nodeId);
|
|
261
|
-
continue;
|
|
262
|
-
}
|
|
263
|
-
let inserted = false;
|
|
264
|
-
for (let index = 0; index < result.length; index++) {
|
|
265
|
-
const parent = result[index];
|
|
266
|
-
const parentReachable = reachable.get(parent) ?? /* @__PURE__ */ new Set();
|
|
267
|
-
if (nodeReachable.has(parent)) {
|
|
268
|
-
if (parentReachable.has(nodeId)) {
|
|
269
|
-
result.push(nodeId);
|
|
270
|
-
} else {
|
|
271
|
-
result.splice(index, 0, nodeId);
|
|
272
|
-
}
|
|
273
|
-
inserted = true;
|
|
274
|
-
break;
|
|
275
|
-
}
|
|
276
|
-
}
|
|
277
|
-
if (!inserted) {
|
|
278
|
-
result.push(nodeId);
|
|
279
|
-
}
|
|
280
|
-
}
|
|
281
|
-
result.reverse();
|
|
282
|
-
return result;
|
|
283
|
-
}
|
|
284
|
-
buildTransitiveClosureForSort() {
|
|
285
|
-
const closure = /* @__PURE__ */ new Map();
|
|
286
|
-
for (const node of this.nodes.values()) {
|
|
287
|
-
closure.set(node.id, new Set(node.outputs));
|
|
288
|
-
}
|
|
289
|
-
const order = this.topologicalOrder();
|
|
290
|
-
for (const nodeId of [...order].reverse()) {
|
|
291
|
-
const node = this.at(nodeId);
|
|
292
|
-
if (!node) {
|
|
293
|
-
continue;
|
|
294
|
-
}
|
|
295
|
-
const nodeClosure = closure.get(nodeId) ?? /* @__PURE__ */ new Set();
|
|
296
|
-
for (const parentId of node.inputs) {
|
|
297
|
-
const parentClosure = closure.get(parentId) ?? /* @__PURE__ */ new Set();
|
|
298
|
-
for (const childId of nodeClosure) {
|
|
299
|
-
parentClosure.add(childId);
|
|
300
|
-
}
|
|
301
|
-
closure.set(parentId, parentClosure);
|
|
302
|
-
}
|
|
303
|
-
}
|
|
304
|
-
return closure;
|
|
305
|
-
}
|
|
306
|
-
transitiveReduction() {
|
|
307
|
-
const order = this.topologicalOrder();
|
|
308
|
-
const marked = /* @__PURE__ */ new Map();
|
|
309
|
-
order.forEach((nodeID) => {
|
|
310
|
-
if (marked.get(nodeID)) {
|
|
311
|
-
return;
|
|
312
|
-
}
|
|
313
|
-
const stack = [];
|
|
314
|
-
stack.push({ id: nodeID, parents: [] });
|
|
315
|
-
while (stack.length > 0) {
|
|
316
|
-
const item = stack.splice(0, 1)[0];
|
|
317
|
-
const node = this.nodes.get(item.id);
|
|
318
|
-
if (node) {
|
|
319
|
-
node.outputs.forEach((child) => {
|
|
320
|
-
item.parents.forEach((parent) => this.removeEdge(parent, child));
|
|
321
|
-
stack.push({ id: child, parents: [item.id, ...item.parents] });
|
|
322
|
-
});
|
|
323
|
-
}
|
|
324
|
-
marked.set(item.id, true);
|
|
325
|
-
}
|
|
326
|
-
});
|
|
327
|
-
}
|
|
328
|
-
/**
|
|
329
|
-
* Finds a cycle in the graph.
|
|
330
|
-
*
|
|
331
|
-
* @returns {NodeID[] | null} The cycle if found, otherwise `null`.
|
|
332
|
-
* Uses non-recursive DFS.
|
|
333
|
-
*/
|
|
334
|
-
findCycle() {
|
|
335
|
-
const visited = /* @__PURE__ */ new Set();
|
|
336
|
-
const nodeStack = /* @__PURE__ */ new Set();
|
|
337
|
-
const parents = /* @__PURE__ */ new Map();
|
|
338
|
-
for (const nodeId of this.nodes.keys()) {
|
|
339
|
-
if (visited.has(nodeId)) {
|
|
340
|
-
continue;
|
|
341
|
-
}
|
|
342
|
-
const callStack = [];
|
|
343
|
-
callStack.push({ nodeId, parentId: null });
|
|
344
|
-
while (callStack.length > 0) {
|
|
345
|
-
const { nodeId: nodeId2, parentId } = callStack[callStack.length - 1];
|
|
346
|
-
if (visited.has(nodeId2)) {
|
|
347
|
-
nodeStack.delete(nodeId2);
|
|
348
|
-
callStack.pop();
|
|
349
|
-
continue;
|
|
350
|
-
}
|
|
351
|
-
visited.add(nodeId2);
|
|
352
|
-
nodeStack.add(nodeId2);
|
|
353
|
-
if (parentId !== null) {
|
|
354
|
-
parents.set(nodeId2, parentId);
|
|
355
|
-
}
|
|
356
|
-
const currentNode = this.nodes.get(nodeId2);
|
|
357
|
-
for (const child of currentNode.outputs) {
|
|
358
|
-
if (!visited.has(child)) {
|
|
359
|
-
callStack.push({ nodeId: child, parentId: nodeId2 });
|
|
360
|
-
continue;
|
|
361
|
-
}
|
|
362
|
-
if (!nodeStack.has(child)) {
|
|
363
|
-
continue;
|
|
364
|
-
}
|
|
365
|
-
const cycle = [];
|
|
366
|
-
let current = nodeId2;
|
|
367
|
-
cycle.push(child);
|
|
368
|
-
while (current !== child) {
|
|
369
|
-
cycle.push(current);
|
|
370
|
-
current = parents.get(current);
|
|
371
|
-
}
|
|
372
|
-
cycle.push(child);
|
|
373
|
-
cycle.reverse();
|
|
374
|
-
return cycle;
|
|
375
|
-
}
|
|
376
|
-
}
|
|
377
|
-
}
|
|
378
|
-
return null;
|
|
379
|
-
}
|
|
380
|
-
};
|
|
381
|
-
|
|
382
|
-
// src/parsing/ast.ts
|
|
383
|
-
var TOKEN_ERROR = 0;
|
|
384
|
-
|
|
385
|
-
// src/rslang/parser/token.ts
|
|
386
|
-
var TokenID = {
|
|
387
|
-
// Global, local IDs and literals
|
|
388
|
-
ERROR: TOKEN_ERROR,
|
|
389
|
-
ID_LOCAL: 258,
|
|
390
|
-
ID_GLOBAL: 259,
|
|
391
|
-
ID_FUNCTION: 260,
|
|
392
|
-
ID_PREDICATE: 261,
|
|
393
|
-
ID_RADICAL: 262,
|
|
394
|
-
LIT_INTEGER: 263,
|
|
395
|
-
LIT_WHOLE_NUMBERS: 264,
|
|
396
|
-
LIT_EMPTYSET: 265,
|
|
397
|
-
// Arithmetic
|
|
398
|
-
PLUS: 266,
|
|
399
|
-
MINUS: 267,
|
|
400
|
-
MULTIPLY: 268,
|
|
401
|
-
// Integer predicate symbols
|
|
402
|
-
GREATER: 269,
|
|
403
|
-
LESSER: 270,
|
|
404
|
-
GREATER_OR_EQ: 271,
|
|
405
|
-
LESSER_OR_EQ: 272,
|
|
406
|
-
// Equality comparison
|
|
407
|
-
EQUAL: 273,
|
|
408
|
-
NOTEQUAL: 274,
|
|
409
|
-
// Logic predicate symbols
|
|
410
|
-
QUANTOR_UNIVERSAL: 275,
|
|
411
|
-
QUANTOR_EXISTS: 276,
|
|
412
|
-
LOGIC_NOT: 277,
|
|
413
|
-
LOGIC_EQUIVALENT: 278,
|
|
414
|
-
LOGIC_IMPLICATION: 279,
|
|
415
|
-
LOGIC_OR: 280,
|
|
416
|
-
LOGIC_AND: 281,
|
|
417
|
-
// Set theory predicate symbols
|
|
418
|
-
SET_IN: 282,
|
|
419
|
-
SET_NOT_IN: 283,
|
|
420
|
-
SUBSET: 284,
|
|
421
|
-
SUBSET_OR_EQ: 285,
|
|
422
|
-
NOT_SUBSET: 286,
|
|
423
|
-
// Set theory operators
|
|
424
|
-
DECART: 287,
|
|
425
|
-
SET_UNION: 288,
|
|
426
|
-
SET_INTERSECTION: 289,
|
|
427
|
-
SET_MINUS: 290,
|
|
428
|
-
SET_SYMMETRIC_MINUS: 291,
|
|
429
|
-
BOOLEAN: 292,
|
|
430
|
-
// Structure operations
|
|
431
|
-
BIGPR: 293,
|
|
432
|
-
SMALLPR: 294,
|
|
433
|
-
FILTER: 295,
|
|
434
|
-
CARD: 296,
|
|
435
|
-
BOOL: 297,
|
|
436
|
-
DEBOOL: 298,
|
|
437
|
-
REDUCE: 299,
|
|
438
|
-
// Term constructions prefixes
|
|
439
|
-
DECLARATIVE: 300,
|
|
440
|
-
RECURSIVE: 301,
|
|
441
|
-
IMPERATIVE: 302,
|
|
442
|
-
ITERATE: 303,
|
|
443
|
-
ASSIGN: 304,
|
|
444
|
-
// Punctuation
|
|
445
|
-
PUNCTUATION_DEFINE: 305,
|
|
446
|
-
PUNCTUATION_STRUCT: 306,
|
|
447
|
-
PUNCTUATION_PL: 307,
|
|
448
|
-
PUNCTUATION_PR: 308,
|
|
449
|
-
PUNCTUATION_CL: 309,
|
|
450
|
-
PUNCTUATION_CR: 310,
|
|
451
|
-
PUNCTUATION_SL: 311,
|
|
452
|
-
PUNCTUATION_SR: 312,
|
|
453
|
-
PUNCTUATION_BAR: 313,
|
|
454
|
-
PUNCTUATION_COMMA: 314,
|
|
455
|
-
PUNCTUATION_SEMICOLON: 315,
|
|
456
|
-
// ======= Non-terminal tokens =========
|
|
457
|
-
NT_ENUM_DECL: 316,
|
|
458
|
-
NT_TUPLE: 317,
|
|
459
|
-
NT_ENUMERATION: 318,
|
|
460
|
-
NT_TUPLE_DECL: 319,
|
|
461
|
-
NT_ARG_DECL: 320,
|
|
462
|
-
NT_FUNC_DEFINITION: 321,
|
|
463
|
-
NT_ARGUMENTS: 322,
|
|
464
|
-
NT_FUNC_CALL: 323,
|
|
465
|
-
NT_DECLARATIVE_EXPR: 324,
|
|
466
|
-
NT_IMPERATIVE_EXPR: 325,
|
|
467
|
-
NT_RECURSIVE_FULL: 326,
|
|
468
|
-
NT_RECURSIVE_SHORT: 327,
|
|
469
|
-
// ======= Helper tokens ========
|
|
470
|
-
INTERRUPT: 328,
|
|
471
|
-
END: 329
|
|
472
|
-
};
|
|
473
|
-
|
|
474
|
-
// src/rslang/api.ts
|
|
475
|
-
var GLOBALS_REGEXP = /[XCSADFPTN]\d+/g;
|
|
476
|
-
var TYPIFICATION_SET = /^ℬ+\([ℬ\(((X|C)\d+|Z)\)×]*\)$/g;
|
|
477
|
-
function isSetTypification(text) {
|
|
478
|
-
return !!text.match(TYPIFICATION_SET);
|
|
479
|
-
}
|
|
480
|
-
function applyAliasMapping(target, mapping) {
|
|
481
|
-
return applyPattern(target, mapping, GLOBALS_REGEXP);
|
|
482
|
-
}
|
|
483
|
-
function applyTypificationMapping(target, mapping) {
|
|
484
|
-
const modified = applyAliasMapping(target, mapping);
|
|
485
|
-
if (modified === target) {
|
|
486
|
-
return target;
|
|
487
|
-
}
|
|
488
|
-
const deleteBrackets = [];
|
|
489
|
-
const positions = [];
|
|
490
|
-
const booleans = [];
|
|
491
|
-
let boolCount = 0;
|
|
492
|
-
let stackSize = 0;
|
|
493
|
-
for (let i = 0; i < modified.length; i++) {
|
|
494
|
-
const char = modified[i];
|
|
495
|
-
if (char === "\u212C") {
|
|
496
|
-
boolCount++;
|
|
497
|
-
continue;
|
|
498
|
-
}
|
|
499
|
-
if (char === "(") {
|
|
500
|
-
stackSize++;
|
|
501
|
-
positions.push(i);
|
|
502
|
-
booleans.push(boolCount);
|
|
503
|
-
}
|
|
504
|
-
boolCount = 0;
|
|
505
|
-
if (char === ")") {
|
|
506
|
-
if (i < modified.length - 1 && modified[i + 1] === ")" && stackSize > 1 && positions[stackSize - 2] + booleans[stackSize - 1] + 1 === positions[stackSize - 1]) {
|
|
507
|
-
deleteBrackets.push(i);
|
|
508
|
-
deleteBrackets.push(positions[stackSize - 2]);
|
|
509
|
-
}
|
|
510
|
-
if (i === modified.length - 1 && stackSize === 1 && positions[0] === 0) {
|
|
511
|
-
deleteBrackets.push(i);
|
|
512
|
-
deleteBrackets.push(positions[0]);
|
|
513
|
-
}
|
|
514
|
-
stackSize--;
|
|
515
|
-
positions.pop();
|
|
516
|
-
booleans.pop();
|
|
517
|
-
}
|
|
518
|
-
}
|
|
519
|
-
let result = "";
|
|
520
|
-
for (let i = 0; i < modified.length; i++) {
|
|
521
|
-
if (!deleteBrackets.includes(i)) {
|
|
522
|
-
result += modified[i];
|
|
523
|
-
}
|
|
524
|
-
}
|
|
525
|
-
return result;
|
|
526
|
-
}
|
|
527
|
-
function applyPattern(text, mapping, pattern) {
|
|
528
|
-
if (text === "" || pattern === null) {
|
|
529
|
-
return text;
|
|
530
|
-
}
|
|
531
|
-
let posInput = 0;
|
|
532
|
-
let output = "";
|
|
533
|
-
const patternMatches = text.matchAll(pattern);
|
|
534
|
-
for (const segment of patternMatches) {
|
|
535
|
-
const entity = segment[0];
|
|
536
|
-
const start = segment.index ?? 0;
|
|
537
|
-
if (entity in mapping) {
|
|
538
|
-
output += text.substring(posInput, start);
|
|
539
|
-
output += mapping[entity];
|
|
540
|
-
posInput = start + segment[0].length;
|
|
541
|
-
}
|
|
542
|
-
}
|
|
543
|
-
output += text.substring(posInput);
|
|
544
|
-
return output;
|
|
545
|
-
}
|
|
546
|
-
|
|
547
|
-
// src/rslang/semantic/typification.ts
|
|
548
|
-
var TypeID = {
|
|
549
|
-
anyTypification: 1,
|
|
550
|
-
integer: 2,
|
|
551
|
-
basic: 3,
|
|
552
|
-
tuple: 4,
|
|
553
|
-
collection: 5,
|
|
554
|
-
logic: 6,
|
|
555
|
-
function: 7,
|
|
556
|
-
predicate: 8
|
|
557
|
-
};
|
|
558
|
-
var TypeClass = {
|
|
559
|
-
logic: 1,
|
|
560
|
-
typification: 2,
|
|
561
|
-
function: 3,
|
|
562
|
-
predicate: 4
|
|
563
|
-
};
|
|
564
|
-
var LogicT = { typeID: TypeID.logic };
|
|
565
|
-
var IntegerT = {
|
|
566
|
-
typeID: TypeID.integer,
|
|
567
|
-
isOrdered: true,
|
|
568
|
-
isArithmetic: true,
|
|
569
|
-
isIntegerCompatible: true
|
|
570
|
-
};
|
|
571
|
-
var AnyTypificationT = { typeID: TypeID.anyTypification };
|
|
572
|
-
var EmptySetT = bool(AnyTypificationT);
|
|
573
|
-
function bool(base) {
|
|
574
|
-
return { typeID: TypeID.collection, base };
|
|
575
|
-
}
|
|
576
|
-
|
|
577
|
-
// src/rslang/labels.ts
|
|
578
|
-
var INTEGER_TYPE_NAME = "Z";
|
|
579
|
-
var ANY_TYPE_NAME = "R0";
|
|
580
|
-
var LOGIC_TYPE_NAME = "Logic";
|
|
581
|
-
var labelTokenRecord = {
|
|
582
|
-
[TokenID.DECART]: "\xD7",
|
|
583
|
-
[TokenID.PUNCTUATION_PL]: "( )",
|
|
584
|
-
[TokenID.PUNCTUATION_SL]: "[ ]",
|
|
585
|
-
[TokenID.QUANTOR_UNIVERSAL]: "\u2200",
|
|
586
|
-
[TokenID.QUANTOR_EXISTS]: "\u2203",
|
|
587
|
-
[TokenID.LOGIC_NOT]: "\xAC",
|
|
588
|
-
[TokenID.LOGIC_AND]: "&",
|
|
589
|
-
[TokenID.LOGIC_OR]: "\u2228",
|
|
590
|
-
[TokenID.LOGIC_IMPLICATION]: "\u21D2",
|
|
591
|
-
[TokenID.LOGIC_EQUIVALENT]: "\u21D4",
|
|
592
|
-
[TokenID.LIT_EMPTYSET]: "\u2205",
|
|
593
|
-
[TokenID.LIT_WHOLE_NUMBERS]: "Z",
|
|
594
|
-
[TokenID.MULTIPLY]: "*",
|
|
595
|
-
[TokenID.EQUAL]: "=",
|
|
596
|
-
[TokenID.NOTEQUAL]: "\u2260",
|
|
597
|
-
[TokenID.GREATER_OR_EQ]: "\u2265",
|
|
598
|
-
[TokenID.LESSER_OR_EQ]: "\u2264",
|
|
599
|
-
[TokenID.SET_IN]: "\u2208",
|
|
600
|
-
[TokenID.SET_NOT_IN]: "\u2209",
|
|
601
|
-
[TokenID.SUBSET_OR_EQ]: "\u2286",
|
|
602
|
-
[TokenID.SUBSET]: "\u2282",
|
|
603
|
-
[TokenID.NOT_SUBSET]: "\u2284",
|
|
604
|
-
[TokenID.SET_INTERSECTION]: "\u2229",
|
|
605
|
-
[TokenID.SET_UNION]: "\u222A",
|
|
606
|
-
[TokenID.SET_MINUS]: "\\",
|
|
607
|
-
[TokenID.SET_SYMMETRIC_MINUS]: "\u2206",
|
|
608
|
-
[TokenID.BOOLEAN]: "\u212C()",
|
|
609
|
-
[TokenID.NT_DECLARATIVE_EXPR]: "D{}",
|
|
610
|
-
[TokenID.NT_IMPERATIVE_EXPR]: "I{}",
|
|
611
|
-
[TokenID.NT_RECURSIVE_FULL]: "R{}",
|
|
612
|
-
[TokenID.BIGPR]: "Pr1()",
|
|
613
|
-
[TokenID.SMALLPR]: "pr1()",
|
|
614
|
-
[TokenID.FILTER]: "Fi1[]()",
|
|
615
|
-
[TokenID.REDUCE]: "red()",
|
|
616
|
-
[TokenID.CARD]: "card()",
|
|
617
|
-
[TokenID.BOOL]: "bool()",
|
|
618
|
-
[TokenID.DEBOOL]: "debool()",
|
|
619
|
-
[TokenID.ASSIGN]: ":=",
|
|
620
|
-
[TokenID.ITERATE]: ":\u2208"
|
|
621
|
-
};
|
|
622
|
-
function labelType(type) {
|
|
623
|
-
if (!type) {
|
|
624
|
-
return "N/A";
|
|
625
|
-
}
|
|
626
|
-
switch (type.typeID) {
|
|
627
|
-
case TypeID.anyTypification:
|
|
628
|
-
return ANY_TYPE_NAME;
|
|
629
|
-
case TypeID.integer:
|
|
630
|
-
return INTEGER_TYPE_NAME;
|
|
631
|
-
case TypeID.basic:
|
|
632
|
-
return type.baseID;
|
|
633
|
-
case TypeID.tuple:
|
|
634
|
-
return type.factors.map((factor) => factor.typeID === TypeID.tuple ? `(${labelType(factor)})` : labelType(factor)).join("\xD7");
|
|
635
|
-
case TypeID.collection:
|
|
636
|
-
return type.base.typeID === TypeID.collection ? `\u212C${labelType(type.base)}` : `\u212C(${labelType(type.base)})`;
|
|
637
|
-
case TypeID.logic:
|
|
638
|
-
return LOGIC_TYPE_NAME;
|
|
639
|
-
case TypeID.predicate:
|
|
640
|
-
case TypeID.function:
|
|
641
|
-
const argsText = type.args.map((arg) => labelType(arg.type)).join(", ");
|
|
642
|
-
return `[${argsText}] \u2192 ${labelType(type.result)}`;
|
|
643
|
-
}
|
|
644
|
-
}
|
|
645
|
-
|
|
646
|
-
// src/rslang/semantic/typification-api.ts
|
|
647
|
-
var TypeIDToClass = {
|
|
648
|
-
[TypeID.anyTypification]: TypeClass.typification,
|
|
649
|
-
[TypeID.integer]: TypeClass.typification,
|
|
650
|
-
[TypeID.basic]: TypeClass.typification,
|
|
651
|
-
[TypeID.tuple]: TypeClass.typification,
|
|
652
|
-
[TypeID.collection]: TypeClass.typification,
|
|
653
|
-
[TypeID.logic]: TypeClass.logic,
|
|
654
|
-
[TypeID.function]: TypeClass.function,
|
|
655
|
-
[TypeID.predicate]: TypeClass.predicate
|
|
656
|
-
};
|
|
657
|
-
function extractBases(target) {
|
|
658
|
-
return new Set(extractBasesImpl(target));
|
|
659
|
-
}
|
|
660
|
-
function extractBasesImpl(target) {
|
|
661
|
-
switch (target.typeID) {
|
|
662
|
-
case TypeID.basic:
|
|
663
|
-
return [target.baseID];
|
|
664
|
-
case TypeID.collection:
|
|
665
|
-
return extractBasesImpl(target.base);
|
|
666
|
-
case TypeID.tuple:
|
|
667
|
-
return target.factors.reduce((result2, factor) => result2.concat(extractBasesImpl(factor)), []);
|
|
668
|
-
case TypeID.function:
|
|
669
|
-
const result = extractBasesImpl(target.result);
|
|
670
|
-
return target.args.reduce((result2, arg) => result2.concat(extractBasesImpl(arg.type)), result);
|
|
671
|
-
case TypeID.predicate:
|
|
672
|
-
return target.args.reduce((result2, arg) => result2.concat(extractBasesImpl(arg.type)), []);
|
|
673
|
-
default:
|
|
674
|
-
return [];
|
|
675
|
-
}
|
|
676
|
-
}
|
|
677
|
-
|
|
678
|
-
// src/library/oss.ts
|
|
679
|
-
var NodeType = {
|
|
680
|
-
OPERATION: 1,
|
|
681
|
-
BLOCK: 2
|
|
682
|
-
};
|
|
683
|
-
var SubstitutionErrorType = {
|
|
684
|
-
invalidIDs: 0,
|
|
685
|
-
incorrectCst: 1,
|
|
686
|
-
invalidClasses: 2,
|
|
687
|
-
invalidBasic: 3,
|
|
688
|
-
invalidConstant: 4,
|
|
689
|
-
typificationCycle: 5,
|
|
690
|
-
baseSubstitutionNotSet: 6,
|
|
691
|
-
unequalTypification: 7,
|
|
692
|
-
unequalExpressions: 8,
|
|
693
|
-
unequalArgsCount: 9,
|
|
694
|
-
unequalArgs: 10,
|
|
695
|
-
invalidNominal: 11
|
|
696
|
-
};
|
|
697
|
-
|
|
698
|
-
// src/library/rsform.ts
|
|
699
|
-
var CstType = {
|
|
700
|
-
NOMINAL: "nominal",
|
|
701
|
-
BASE: "basic",
|
|
702
|
-
STRUCTURED: "structure",
|
|
703
|
-
TERM: "term",
|
|
704
|
-
AXIOM: "axiom",
|
|
705
|
-
FUNCTION: "function",
|
|
706
|
-
PREDICATE: "predicate",
|
|
707
|
-
CONSTANT: "constant",
|
|
708
|
-
STATEMENT: "statement"
|
|
709
|
-
};
|
|
710
|
-
var CstClass = {
|
|
711
|
-
NOMINAL: "nominal",
|
|
712
|
-
BASIC: "basic",
|
|
713
|
-
DERIVED: "derived",
|
|
714
|
-
STATEMENT: "statement",
|
|
715
|
-
TEMPLATE: "template"
|
|
716
|
-
};
|
|
717
|
-
|
|
718
|
-
// src/library/oss-api.ts
|
|
719
|
-
var STARTING_SUB_INDEX = 900;
|
|
1
|
+
import { Graph } from "../graph/graph.js";
|
|
2
|
+
import { NodeType, SubstitutionErrorType } from "./oss.js";
|
|
3
|
+
import { labelType } from "../rslang/labels.js";
|
|
4
|
+
import { extractBases } from "../rslang/semantic/typification-api.js";
|
|
5
|
+
import { CstClass, CstType } from "./rsform.js";
|
|
6
|
+
import { applyAliasMapping, applyTypificationMapping, isSetTypification } from "../rslang/api.js";
|
|
7
|
+
import "../graph/index.js";
|
|
8
|
+
//#region src/library/oss-api.ts
|
|
9
|
+
/**
|
|
10
|
+
* Module: API for OperationSystem.
|
|
11
|
+
*/
|
|
12
|
+
const STARTING_SUB_INDEX = 900;
|
|
720
13
|
function constructNodeID(type, itemID) {
|
|
721
|
-
|
|
14
|
+
return type === NodeType.OPERATION ? "o" + String(itemID) : "b" + String(itemID);
|
|
722
15
|
}
|
|
16
|
+
/** Sorts library items relevant for the specified {@link OperationSchema}. */
|
|
723
17
|
function sortItemsForOSS(oss, items) {
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
}
|
|
730
|
-
for (const item of items) {
|
|
731
|
-
if (item.visible && !result.includes(item)) {
|
|
732
|
-
result.push(item);
|
|
733
|
-
}
|
|
734
|
-
}
|
|
735
|
-
for (const item of items) {
|
|
736
|
-
if (!result.includes(item)) {
|
|
737
|
-
result.push(item);
|
|
738
|
-
}
|
|
739
|
-
}
|
|
740
|
-
return result;
|
|
18
|
+
const result = items.filter((item) => item.location === oss.location);
|
|
19
|
+
for (const item of items) if (item.visible && item.owner === oss.owner && !result.includes(item)) result.push(item);
|
|
20
|
+
for (const item of items) if (item.visible && !result.includes(item)) result.push(item);
|
|
21
|
+
for (const item of items) if (!result.includes(item)) result.push(item);
|
|
22
|
+
return result;
|
|
741
23
|
}
|
|
24
|
+
/** Validator for Substitution table. */
|
|
742
25
|
var SubstitutionValidator = class {
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
const original = this.cstByID.get(item.original);
|
|
961
|
-
if (original.cst_type === CstType.BASE || original.cst_type === CstType.CONSTANT || original.cst_type === CstType.NOMINAL) {
|
|
962
|
-
continue;
|
|
963
|
-
}
|
|
964
|
-
const substitution = this.cstByID.get(item.substitution);
|
|
965
|
-
if (original.cst_type === substitution.cst_type && original.cst_class !== CstClass.BASIC) {
|
|
966
|
-
if (!this.checkEqual(original, substitution)) {
|
|
967
|
-
this.reportError(SubstitutionErrorType.unequalExpressions, [substitution.alias, original.alias]);
|
|
968
|
-
}
|
|
969
|
-
}
|
|
970
|
-
if (original.analysis.success !== substitution.analysis.success) {
|
|
971
|
-
return this.reportError(SubstitutionErrorType.unequalTypification, [substitution.alias, original.alias]);
|
|
972
|
-
}
|
|
973
|
-
if (!original.analysis.success || !substitution.analysis.success) {
|
|
974
|
-
continue;
|
|
975
|
-
}
|
|
976
|
-
const originalType = applyTypificationMapping(
|
|
977
|
-
applyAliasMapping(labelType(original.effectiveType), baseMappings.get(original.schema)),
|
|
978
|
-
typeMappings
|
|
979
|
-
);
|
|
980
|
-
const substitutionType = applyTypificationMapping(
|
|
981
|
-
applyAliasMapping(labelType(substitution.effectiveType), baseMappings.get(substitution.schema)),
|
|
982
|
-
typeMappings
|
|
983
|
-
);
|
|
984
|
-
if (originalType !== substitutionType) {
|
|
985
|
-
return this.reportError(SubstitutionErrorType.unequalTypification, [substitution.alias, original.alias]);
|
|
986
|
-
}
|
|
987
|
-
}
|
|
988
|
-
return true;
|
|
989
|
-
}
|
|
990
|
-
prepareBaseMappings() {
|
|
991
|
-
const result = /* @__PURE__ */ new Map();
|
|
992
|
-
let baseCount = 0;
|
|
993
|
-
let constCount = 0;
|
|
994
|
-
for (const schema of this.schemas) {
|
|
995
|
-
const mapping = {};
|
|
996
|
-
for (const cst of schema.items) {
|
|
997
|
-
if (cst.cst_type === CstType.BASE) {
|
|
998
|
-
baseCount++;
|
|
999
|
-
mapping[cst.alias] = `X${baseCount}`;
|
|
1000
|
-
} else if (cst.cst_type === CstType.CONSTANT) {
|
|
1001
|
-
constCount++;
|
|
1002
|
-
mapping[cst.alias] = `C${constCount}`;
|
|
1003
|
-
}
|
|
1004
|
-
result.set(schema.id, mapping);
|
|
1005
|
-
}
|
|
1006
|
-
}
|
|
1007
|
-
return result;
|
|
1008
|
-
}
|
|
1009
|
-
calculateSubstituteMappings(baseMappings) {
|
|
1010
|
-
const result = {};
|
|
1011
|
-
const processed = /* @__PURE__ */ new Set();
|
|
1012
|
-
for (const item of this.substitutions) {
|
|
1013
|
-
const original = this.cstByID.get(item.original);
|
|
1014
|
-
if (original.cst_type !== CstType.BASE && original.cst_type !== CstType.CONSTANT) {
|
|
1015
|
-
continue;
|
|
1016
|
-
}
|
|
1017
|
-
const originalAlias = baseMappings.get(original.schema)[original.alias];
|
|
1018
|
-
const substitution = this.cstByID.get(item.substitution);
|
|
1019
|
-
let substitutionText = "";
|
|
1020
|
-
if (substitution.cst_type === original.cst_type || !substitution.effectiveType) {
|
|
1021
|
-
substitutionText = baseMappings.get(substitution.schema)[substitution.alias];
|
|
1022
|
-
} else {
|
|
1023
|
-
const typeText = labelType(substitution.effectiveType);
|
|
1024
|
-
substitutionText = applyAliasMapping(typeText, baseMappings.get(substitution.schema));
|
|
1025
|
-
substitutionText = applyTypificationMapping(substitutionText, result);
|
|
1026
|
-
if (!isSetTypification(substitutionText)) {
|
|
1027
|
-
this.reportError(SubstitutionErrorType.baseSubstitutionNotSet, [substitution.alias, typeText]);
|
|
1028
|
-
return null;
|
|
1029
|
-
}
|
|
1030
|
-
if (substitutionText.includes("\xD7") || substitutionText.startsWith("\u212C\u212C")) {
|
|
1031
|
-
substitutionText = substitutionText.slice(1);
|
|
1032
|
-
} else {
|
|
1033
|
-
substitutionText = substitutionText.slice(2, -1);
|
|
1034
|
-
}
|
|
1035
|
-
}
|
|
1036
|
-
for (const prevAlias of processed) {
|
|
1037
|
-
result[prevAlias] = applyTypificationMapping(result[prevAlias], { [originalAlias]: substitutionText });
|
|
1038
|
-
}
|
|
1039
|
-
result[originalAlias] = substitutionText;
|
|
1040
|
-
processed.add(originalAlias);
|
|
1041
|
-
}
|
|
1042
|
-
return result;
|
|
1043
|
-
}
|
|
1044
|
-
checkEqual(left, right) {
|
|
1045
|
-
const schema1 = this.schemaByID.get(left.schema);
|
|
1046
|
-
const inputs1 = schema1.graph.at(left.id).inputs;
|
|
1047
|
-
if (inputs1.some((id) => !this.constituents.has(id))) {
|
|
1048
|
-
return false;
|
|
1049
|
-
}
|
|
1050
|
-
const schema2 = this.schemaByID.get(right.schema);
|
|
1051
|
-
const inputs2 = schema2.graph.at(right.id).inputs;
|
|
1052
|
-
if (inputs2.some((id) => !this.constituents.has(id))) {
|
|
1053
|
-
return false;
|
|
1054
|
-
}
|
|
1055
|
-
const expression1 = applyAliasMapping(left.definition_formal, this.mapping.get(schema1.id));
|
|
1056
|
-
const expression2 = applyAliasMapping(right.definition_formal, this.mapping.get(schema2.id));
|
|
1057
|
-
return expression1.replace(" ", "") === expression2.replace(" ", "");
|
|
1058
|
-
}
|
|
1059
|
-
reportError(errorType, params) {
|
|
1060
|
-
this.errors.push({
|
|
1061
|
-
errorType,
|
|
1062
|
-
params
|
|
1063
|
-
});
|
|
1064
|
-
return false;
|
|
1065
|
-
}
|
|
26
|
+
errors = [];
|
|
27
|
+
suggestions = [];
|
|
28
|
+
schemas;
|
|
29
|
+
substitutions;
|
|
30
|
+
constituents = /* @__PURE__ */ new Set();
|
|
31
|
+
originals = /* @__PURE__ */ new Set();
|
|
32
|
+
mapping = /* @__PURE__ */ new Map();
|
|
33
|
+
cstByID = /* @__PURE__ */ new Map();
|
|
34
|
+
schemaByID = /* @__PURE__ */ new Map();
|
|
35
|
+
schemaByCst = /* @__PURE__ */ new Map();
|
|
36
|
+
constructor(schemas, substitutions) {
|
|
37
|
+
this.schemas = schemas;
|
|
38
|
+
this.substitutions = substitutions;
|
|
39
|
+
if (schemas.length === 0) return;
|
|
40
|
+
for (const schema of schemas) {
|
|
41
|
+
this.schemaByID.set(schema.id, schema);
|
|
42
|
+
this.mapping.set(schema.id, {});
|
|
43
|
+
for (const item of schema.items) {
|
|
44
|
+
this.cstByID.set(item.id, item);
|
|
45
|
+
this.schemaByCst.set(item.id, schema);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
if (substitutions.length === 0) return;
|
|
49
|
+
let index = STARTING_SUB_INDEX;
|
|
50
|
+
for (const item of substitutions) {
|
|
51
|
+
this.constituents.add(item.original);
|
|
52
|
+
this.constituents.add(item.substitution);
|
|
53
|
+
this.originals.add(item.original);
|
|
54
|
+
const original = this.cstByID.get(item.original);
|
|
55
|
+
const substitution = this.cstByID.get(item.substitution);
|
|
56
|
+
if (!original || !substitution) return;
|
|
57
|
+
index++;
|
|
58
|
+
const newAlias = `${substitution.alias[0]}${index}`;
|
|
59
|
+
this.mapping.get(original.schema)[original.alias] = newAlias;
|
|
60
|
+
this.mapping.get(substitution.schema)[substitution.alias] = newAlias;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
validate() {
|
|
64
|
+
this.errors = [];
|
|
65
|
+
this.suggestions = [];
|
|
66
|
+
this.calculateSuggestions();
|
|
67
|
+
if (this.substitutions.length === 0) return true;
|
|
68
|
+
if (!this.checkTypes()) return false;
|
|
69
|
+
if (!this.checkCycles()) return false;
|
|
70
|
+
if (!this.checkSubstitutions()) return false;
|
|
71
|
+
return true;
|
|
72
|
+
}
|
|
73
|
+
calculateSuggestions() {
|
|
74
|
+
const candidates = /* @__PURE__ */ new Map();
|
|
75
|
+
const minors = /* @__PURE__ */ new Set();
|
|
76
|
+
const schemaByCst = /* @__PURE__ */ new Map();
|
|
77
|
+
for (const schema of this.schemas) for (const cst of schema.items) {
|
|
78
|
+
if (this.originals.has(cst.id)) continue;
|
|
79
|
+
if (cst.cst_class === CstClass.BASIC || cst.definition_formal.length === 0) continue;
|
|
80
|
+
const inputs = schema.graph.at(cst.id).inputs;
|
|
81
|
+
if (inputs.some((id) => !this.constituents.has(id))) continue;
|
|
82
|
+
if (inputs.some((id) => this.originals.has(id))) minors.add(cst.id);
|
|
83
|
+
candidates.set(cst.id, applyAliasMapping(cst.definition_formal, this.mapping.get(schema.id)).replace(" ", ""));
|
|
84
|
+
schemaByCst.set(cst.id, schema);
|
|
85
|
+
}
|
|
86
|
+
for (const [key1, value1] of candidates) for (const [key2, value2] of candidates) {
|
|
87
|
+
if (key1 >= key2) continue;
|
|
88
|
+
if (schemaByCst.get(key1) === schemaByCst.get(key2)) continue;
|
|
89
|
+
if (value1 != value2) continue;
|
|
90
|
+
if (minors.has(key2)) this.suggestions.push({
|
|
91
|
+
original: key2,
|
|
92
|
+
substitution: key1
|
|
93
|
+
});
|
|
94
|
+
else this.suggestions.push({
|
|
95
|
+
original: key1,
|
|
96
|
+
substitution: key2
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
checkTypes() {
|
|
101
|
+
for (const item of this.substitutions) {
|
|
102
|
+
const original = this.cstByID.get(item.original);
|
|
103
|
+
const substitution = this.cstByID.get(item.substitution);
|
|
104
|
+
if (!original || !substitution) return this.reportError(SubstitutionErrorType.invalidIDs, []);
|
|
105
|
+
if (substitution.analysis && original.analysis && (!original.analysis.success || !substitution.analysis.success)) return this.reportError(SubstitutionErrorType.incorrectCst, [substitution.alias, original.alias]);
|
|
106
|
+
switch (substitution.cst_type) {
|
|
107
|
+
case CstType.NOMINAL:
|
|
108
|
+
if (original.cst_type !== CstType.NOMINAL) return this.reportError(SubstitutionErrorType.invalidNominal, [substitution.alias, original.alias]);
|
|
109
|
+
break;
|
|
110
|
+
case CstType.BASE:
|
|
111
|
+
if (original.cst_type !== CstType.BASE && original.cst_type !== CstType.CONSTANT && original.cst_type !== CstType.NOMINAL) return this.reportError(SubstitutionErrorType.invalidBasic, [substitution.alias, original.alias]);
|
|
112
|
+
break;
|
|
113
|
+
case CstType.CONSTANT:
|
|
114
|
+
if (original.cst_type !== CstType.CONSTANT) return this.reportError(SubstitutionErrorType.invalidConstant, [substitution.alias, original.alias]);
|
|
115
|
+
break;
|
|
116
|
+
case CstType.AXIOM:
|
|
117
|
+
case CstType.STATEMENT:
|
|
118
|
+
if (original.cst_type !== CstType.AXIOM && original.cst_type !== CstType.STATEMENT) return this.reportError(SubstitutionErrorType.invalidClasses, [substitution.alias, original.alias]);
|
|
119
|
+
break;
|
|
120
|
+
case CstType.FUNCTION:
|
|
121
|
+
if (original.cst_type !== CstType.FUNCTION) return this.reportError(SubstitutionErrorType.invalidClasses, [substitution.alias, original.alias]);
|
|
122
|
+
break;
|
|
123
|
+
case CstType.PREDICATE:
|
|
124
|
+
if (original.cst_type !== CstType.PREDICATE) return this.reportError(SubstitutionErrorType.invalidClasses, [substitution.alias, original.alias]);
|
|
125
|
+
break;
|
|
126
|
+
case CstType.TERM:
|
|
127
|
+
case CstType.STRUCTURED:
|
|
128
|
+
if (original.cst_type !== CstType.TERM && original.cst_type !== CstType.STRUCTURED && original.cst_type !== CstType.BASE) return this.reportError(SubstitutionErrorType.invalidClasses, [substitution.alias, original.alias]);
|
|
129
|
+
break;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
return true;
|
|
133
|
+
}
|
|
134
|
+
checkCycles() {
|
|
135
|
+
const graph = new Graph();
|
|
136
|
+
for (const schema of this.schemas) for (const cst of schema.items) if (cst.cst_type === CstType.BASE || cst.cst_type === CstType.CONSTANT) graph.addNode(cst.id);
|
|
137
|
+
for (const item of this.substitutions) {
|
|
138
|
+
const original = this.cstByID.get(item.original);
|
|
139
|
+
const substitution = this.cstByID.get(item.substitution);
|
|
140
|
+
for (const cst of [original, substitution]) {
|
|
141
|
+
if (cst.cst_type === CstType.BASE || cst.cst_type === CstType.CONSTANT) continue;
|
|
142
|
+
graph.addNode(cst.id);
|
|
143
|
+
if (cst.effectiveType === null) continue;
|
|
144
|
+
const parents = extractBases(cst.effectiveType);
|
|
145
|
+
if (parents.size === 0) continue;
|
|
146
|
+
const schema = this.schemaByID.get(cst.schema);
|
|
147
|
+
for (const alias of parents) {
|
|
148
|
+
const parent = schema.cstByAlias.get(alias);
|
|
149
|
+
if (parent) graph.addEdge(parent.id, cst.id);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
graph.addEdge(substitution.id, original.id);
|
|
153
|
+
}
|
|
154
|
+
const cycle = graph.findCycle();
|
|
155
|
+
if (cycle !== null) {
|
|
156
|
+
const cycleMsg = cycle.map((id) => {
|
|
157
|
+
const cst = this.cstByID.get(id);
|
|
158
|
+
return `[${this.schemaByID.get(cst.schema).alias}]-${cst.alias}`;
|
|
159
|
+
}).join(", ");
|
|
160
|
+
return this.reportError(SubstitutionErrorType.typificationCycle, [cycleMsg]);
|
|
161
|
+
}
|
|
162
|
+
return true;
|
|
163
|
+
}
|
|
164
|
+
checkSubstitutions() {
|
|
165
|
+
const baseMappings = this.prepareBaseMappings();
|
|
166
|
+
const typeMappings = this.calculateSubstituteMappings(baseMappings);
|
|
167
|
+
if (typeMappings === null) return false;
|
|
168
|
+
for (const item of this.substitutions) {
|
|
169
|
+
const original = this.cstByID.get(item.original);
|
|
170
|
+
if (original.cst_type === CstType.BASE || original.cst_type === CstType.CONSTANT || original.cst_type === CstType.NOMINAL) continue;
|
|
171
|
+
const substitution = this.cstByID.get(item.substitution);
|
|
172
|
+
if (original.cst_type === substitution.cst_type && original.cst_class !== CstClass.BASIC) {
|
|
173
|
+
if (!this.checkEqual(original, substitution)) this.reportError(SubstitutionErrorType.unequalExpressions, [substitution.alias, original.alias]);
|
|
174
|
+
}
|
|
175
|
+
if (original.analysis.success !== substitution.analysis.success) return this.reportError(SubstitutionErrorType.unequalTypification, [substitution.alias, original.alias]);
|
|
176
|
+
if (!original.analysis.success || !substitution.analysis.success) continue;
|
|
177
|
+
if (applyTypificationMapping(applyAliasMapping(labelType(original.effectiveType), baseMappings.get(original.schema)), typeMappings) !== applyTypificationMapping(applyAliasMapping(labelType(substitution.effectiveType), baseMappings.get(substitution.schema)), typeMappings)) return this.reportError(SubstitutionErrorType.unequalTypification, [substitution.alias, original.alias]);
|
|
178
|
+
}
|
|
179
|
+
return true;
|
|
180
|
+
}
|
|
181
|
+
prepareBaseMappings() {
|
|
182
|
+
const result = /* @__PURE__ */ new Map();
|
|
183
|
+
let baseCount = 0;
|
|
184
|
+
let constCount = 0;
|
|
185
|
+
for (const schema of this.schemas) {
|
|
186
|
+
const mapping = {};
|
|
187
|
+
for (const cst of schema.items) {
|
|
188
|
+
if (cst.cst_type === CstType.BASE) {
|
|
189
|
+
baseCount++;
|
|
190
|
+
mapping[cst.alias] = `X${baseCount}`;
|
|
191
|
+
} else if (cst.cst_type === CstType.CONSTANT) {
|
|
192
|
+
constCount++;
|
|
193
|
+
mapping[cst.alias] = `C${constCount}`;
|
|
194
|
+
}
|
|
195
|
+
result.set(schema.id, mapping);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
return result;
|
|
199
|
+
}
|
|
200
|
+
calculateSubstituteMappings(baseMappings) {
|
|
201
|
+
const result = {};
|
|
202
|
+
const processed = /* @__PURE__ */ new Set();
|
|
203
|
+
for (const item of this.substitutions) {
|
|
204
|
+
const original = this.cstByID.get(item.original);
|
|
205
|
+
if (original.cst_type !== CstType.BASE && original.cst_type !== CstType.CONSTANT) continue;
|
|
206
|
+
const originalAlias = baseMappings.get(original.schema)[original.alias];
|
|
207
|
+
const substitution = this.cstByID.get(item.substitution);
|
|
208
|
+
let substitutionText = "";
|
|
209
|
+
if (substitution.cst_type === original.cst_type || !substitution.effectiveType) substitutionText = baseMappings.get(substitution.schema)[substitution.alias];
|
|
210
|
+
else {
|
|
211
|
+
const typeText = labelType(substitution.effectiveType);
|
|
212
|
+
substitutionText = applyAliasMapping(typeText, baseMappings.get(substitution.schema));
|
|
213
|
+
substitutionText = applyTypificationMapping(substitutionText, result);
|
|
214
|
+
if (!isSetTypification(substitutionText)) {
|
|
215
|
+
this.reportError(SubstitutionErrorType.baseSubstitutionNotSet, [substitution.alias, typeText]);
|
|
216
|
+
return null;
|
|
217
|
+
}
|
|
218
|
+
if (substitutionText.includes("×") || substitutionText.startsWith("ℬℬ")) substitutionText = substitutionText.slice(1);
|
|
219
|
+
else substitutionText = substitutionText.slice(2, -1);
|
|
220
|
+
}
|
|
221
|
+
for (const prevAlias of processed) result[prevAlias] = applyTypificationMapping(result[prevAlias], { [originalAlias]: substitutionText });
|
|
222
|
+
result[originalAlias] = substitutionText;
|
|
223
|
+
processed.add(originalAlias);
|
|
224
|
+
}
|
|
225
|
+
return result;
|
|
226
|
+
}
|
|
227
|
+
checkEqual(left, right) {
|
|
228
|
+
const schema1 = this.schemaByID.get(left.schema);
|
|
229
|
+
if (schema1.graph.at(left.id).inputs.some((id) => !this.constituents.has(id))) return false;
|
|
230
|
+
const schema2 = this.schemaByID.get(right.schema);
|
|
231
|
+
if (schema2.graph.at(right.id).inputs.some((id) => !this.constituents.has(id))) return false;
|
|
232
|
+
const expression1 = applyAliasMapping(left.definition_formal, this.mapping.get(schema1.id));
|
|
233
|
+
const expression2 = applyAliasMapping(right.definition_formal, this.mapping.get(schema2.id));
|
|
234
|
+
return expression1.replace(" ", "") === expression2.replace(" ", "");
|
|
235
|
+
}
|
|
236
|
+
reportError(errorType, params) {
|
|
237
|
+
this.errors.push({
|
|
238
|
+
errorType,
|
|
239
|
+
params
|
|
240
|
+
});
|
|
241
|
+
return false;
|
|
242
|
+
}
|
|
1066
243
|
};
|
|
244
|
+
/** Filter relocate candidates from gives schema. */
|
|
1067
245
|
function getRelocateCandidates(source, destination, schema, oss) {
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
const parent = schema.inheritance.find((item) => item.child === cst.id && item.child_source === cst.schema)?.parent;
|
|
1086
|
-
if (parent) {
|
|
1087
|
-
const original = oss.substitutions.find((sub) => sub.substitution === parent)?.original;
|
|
1088
|
-
if (original) {
|
|
1089
|
-
continue;
|
|
1090
|
-
}
|
|
1091
|
-
}
|
|
1092
|
-
unreachableBases.push(cst.id);
|
|
1093
|
-
}
|
|
1094
|
-
const unreachable = schema.graph.expandAllOutputs(unreachableBases);
|
|
1095
|
-
return schema.items.filter(
|
|
1096
|
-
(cst) => cst.parent_schema === destinationSchema || addedCst.includes(cst.id) && !unreachable.includes(cst.id)
|
|
1097
|
-
);
|
|
246
|
+
const destinationSchema = oss.operationByID.get(destination)?.result;
|
|
247
|
+
if (!destinationSchema) return [];
|
|
248
|
+
const node = oss.graph.at(source);
|
|
249
|
+
if (!node) return [];
|
|
250
|
+
if (node.outputs.includes(destination)) return schema.items;
|
|
251
|
+
const addedCst = schema.items.filter((item) => !item.is_inherited).map((cst) => cst.id);
|
|
252
|
+
const unreachableBases = [];
|
|
253
|
+
for (const cst of schema.items.filter((item) => item.is_inherited)) {
|
|
254
|
+
if (cst.parent_schema == destinationSchema) continue;
|
|
255
|
+
const parent = schema.inheritance.find((item) => item.child === cst.id && item.child_source === cst.schema)?.parent;
|
|
256
|
+
if (parent) {
|
|
257
|
+
if (oss.substitutions.find((sub) => sub.substitution === parent)?.original) continue;
|
|
258
|
+
}
|
|
259
|
+
unreachableBases.push(cst.id);
|
|
260
|
+
}
|
|
261
|
+
const unreachable = schema.graph.expandAllOutputs(unreachableBases);
|
|
262
|
+
return schema.items.filter((cst) => cst.parent_schema === destinationSchema || addedCst.includes(cst.id) && !unreachable.includes(cst.id));
|
|
1098
263
|
}
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
getRelocateCandidates,
|
|
1103
|
-
sortItemsForOSS
|
|
1104
|
-
};
|
|
264
|
+
//#endregion
|
|
265
|
+
export { SubstitutionValidator, constructNodeID, getRelocateCandidates, sortItemsForOSS };
|
|
266
|
+
|
|
1105
267
|
//# sourceMappingURL=oss-api.js.map
|