@rsconcept/domain 1.0.0 → 1.1.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 +257 -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/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
|
@@ -0,0 +1,366 @@
|
|
|
1
|
+
import { generateStub } from "./shared/hash.js";
|
|
2
|
+
import "./shared/index.js";
|
|
3
|
+
import { TypeID } from "./rslang/semantic/typification.js";
|
|
4
|
+
//#region src/rslang/eval/value-api.ts
|
|
5
|
+
/** Cartesian product of factor sets. */
|
|
6
|
+
function cartesianProduct(factors) {
|
|
7
|
+
const cardinality = factors.reduce((acc, f) => acc * f.length, 1);
|
|
8
|
+
if (cardinality > 1e7) return null;
|
|
9
|
+
if (cardinality === 0 || factors.length === 0) return EmptySetV;
|
|
10
|
+
let accumulator = [[]];
|
|
11
|
+
for (const factor of factors) {
|
|
12
|
+
const next = [];
|
|
13
|
+
for (const prefix of accumulator) for (const value of factor) next.push([...prefix, value]);
|
|
14
|
+
accumulator = next;
|
|
15
|
+
}
|
|
16
|
+
return accumulator.map(tuple);
|
|
17
|
+
}
|
|
18
|
+
/** Boolean power set ℬ(X). No cache - materialized. */
|
|
19
|
+
function boolean(base) {
|
|
20
|
+
if (base.length > 18) return null;
|
|
21
|
+
return powerset(base);
|
|
22
|
+
}
|
|
23
|
+
/** Powerset of array. */
|
|
24
|
+
function powerset(arr) {
|
|
25
|
+
const result = [[]];
|
|
26
|
+
if (arr.length === 0) return result;
|
|
27
|
+
let current = [[]];
|
|
28
|
+
let maxIndex = [-1];
|
|
29
|
+
while (current.length > 0) {
|
|
30
|
+
const next = [];
|
|
31
|
+
const nextMaxIndex = [];
|
|
32
|
+
for (let i = 0; i < current.length; i++) for (let j = maxIndex[i] + 1; j < arr.length; j++) {
|
|
33
|
+
const subset = [...current[i], arr[j]];
|
|
34
|
+
result.push(subset);
|
|
35
|
+
if (j < arr.length - 1) {
|
|
36
|
+
next.push(subset);
|
|
37
|
+
nextMaxIndex.push(j);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
current = next;
|
|
41
|
+
maxIndex = nextMaxIndex;
|
|
42
|
+
}
|
|
43
|
+
return result;
|
|
44
|
+
}
|
|
45
|
+
/** Check if set contains element. */
|
|
46
|
+
function contains(setData, element) {
|
|
47
|
+
let left = 0;
|
|
48
|
+
let right = setData.length - 1;
|
|
49
|
+
while (left <= right) {
|
|
50
|
+
const mid = Math.floor((left + right) / 2);
|
|
51
|
+
const cmp = compare(setData[mid], element);
|
|
52
|
+
if (cmp === 0) return true;
|
|
53
|
+
else if (cmp < 0) left = mid + 1;
|
|
54
|
+
else right = mid - 1;
|
|
55
|
+
}
|
|
56
|
+
return false;
|
|
57
|
+
}
|
|
58
|
+
/** Is A ⊆ B. */
|
|
59
|
+
function isSubsetOrEq(a, b) {
|
|
60
|
+
let i = 0, j = 0;
|
|
61
|
+
while (i < a.length && j < b.length) {
|
|
62
|
+
const cmp = compare(a[i], b[j]);
|
|
63
|
+
if (cmp === 0) {
|
|
64
|
+
i++;
|
|
65
|
+
j++;
|
|
66
|
+
} else if (cmp > 0) j++;
|
|
67
|
+
else return false;
|
|
68
|
+
}
|
|
69
|
+
return i === a.length;
|
|
70
|
+
}
|
|
71
|
+
/** Reduce: flatten double boolean to single boolean. */
|
|
72
|
+
function reduce(target) {
|
|
73
|
+
const result = [];
|
|
74
|
+
for (const element of target) result.push(...element);
|
|
75
|
+
return set(result);
|
|
76
|
+
}
|
|
77
|
+
/** Union A ∪ B. */
|
|
78
|
+
function setUnion(set1, set2) {
|
|
79
|
+
const result = [];
|
|
80
|
+
let i = 0, j = 0;
|
|
81
|
+
while (i < set1.length && j < set2.length) {
|
|
82
|
+
const cmp = compare(set1[i], set2[j]);
|
|
83
|
+
if (cmp < 0) {
|
|
84
|
+
result.push(set1[i]);
|
|
85
|
+
i++;
|
|
86
|
+
} else if (cmp > 0) {
|
|
87
|
+
result.push(set2[j]);
|
|
88
|
+
j++;
|
|
89
|
+
} else {
|
|
90
|
+
result.push(set1[i]);
|
|
91
|
+
i++;
|
|
92
|
+
j++;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
while (i < set1.length) {
|
|
96
|
+
result.push(set1[i]);
|
|
97
|
+
i++;
|
|
98
|
+
}
|
|
99
|
+
while (j < set2.length) {
|
|
100
|
+
result.push(set2[j]);
|
|
101
|
+
j++;
|
|
102
|
+
}
|
|
103
|
+
return result;
|
|
104
|
+
}
|
|
105
|
+
/** Intersection A ∩ B. */
|
|
106
|
+
function setIntersection(set1, set2) {
|
|
107
|
+
const result = [];
|
|
108
|
+
for (let i = 0, j = 0; i < set1.length && j < set2.length;) {
|
|
109
|
+
const cmp = compare(set1[i], set2[j]);
|
|
110
|
+
if (cmp < 0) i++;
|
|
111
|
+
else if (cmp > 0) j++;
|
|
112
|
+
else {
|
|
113
|
+
result.push(set1[i]);
|
|
114
|
+
i++;
|
|
115
|
+
j++;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
return result;
|
|
119
|
+
}
|
|
120
|
+
/** Difference A \ B. */
|
|
121
|
+
function setDiff(set1, set2) {
|
|
122
|
+
const result = [];
|
|
123
|
+
let i = 0, j = 0;
|
|
124
|
+
while (i < set1.length && j < set2.length) {
|
|
125
|
+
const cmp = compare(set1[i], set2[j]);
|
|
126
|
+
if (cmp < 0) {
|
|
127
|
+
result.push(set1[i]);
|
|
128
|
+
i++;
|
|
129
|
+
} else if (cmp > 0) j++;
|
|
130
|
+
else {
|
|
131
|
+
i++;
|
|
132
|
+
j++;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
while (i < set1.length) {
|
|
136
|
+
result.push(set1[i]);
|
|
137
|
+
i++;
|
|
138
|
+
}
|
|
139
|
+
return result;
|
|
140
|
+
}
|
|
141
|
+
/** Symmetric difference A ∆ B. */
|
|
142
|
+
function setSymDiff(set1, set2) {
|
|
143
|
+
const result = [];
|
|
144
|
+
let i = 0, j = 0;
|
|
145
|
+
while (i < set1.length && j < set2.length) {
|
|
146
|
+
const cmp = compare(set1[i], set2[j]);
|
|
147
|
+
if (cmp < 0) {
|
|
148
|
+
result.push(set1[i]);
|
|
149
|
+
i++;
|
|
150
|
+
} else if (cmp > 0) {
|
|
151
|
+
result.push(set2[j]);
|
|
152
|
+
j++;
|
|
153
|
+
} else {
|
|
154
|
+
i++;
|
|
155
|
+
j++;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
while (i < set1.length) {
|
|
159
|
+
result.push(set1[i]);
|
|
160
|
+
i++;
|
|
161
|
+
}
|
|
162
|
+
while (j < set2.length) {
|
|
163
|
+
result.push(set2[j]);
|
|
164
|
+
j++;
|
|
165
|
+
}
|
|
166
|
+
return result;
|
|
167
|
+
}
|
|
168
|
+
/** Projection of set by indices (BigPr). */
|
|
169
|
+
function projection(target, indices) {
|
|
170
|
+
return set(target.map((element) => {
|
|
171
|
+
const newComponents = indices.map((idx) => element[idx]);
|
|
172
|
+
return indices.length === 1 ? newComponents[0] : tuple(newComponents);
|
|
173
|
+
}));
|
|
174
|
+
}
|
|
175
|
+
/** Condensed string representation. */
|
|
176
|
+
function printValue(data) {
|
|
177
|
+
if (!Array.isArray(data)) return String(data);
|
|
178
|
+
const len = data.length;
|
|
179
|
+
if (data.length === 0) return "{}";
|
|
180
|
+
const isTuple = data[0] === TUPLE_ID;
|
|
181
|
+
const start = isTuple ? 1 : 0;
|
|
182
|
+
let result = isTuple ? "(" : "{";
|
|
183
|
+
for (let i = start; i < len; i++) {
|
|
184
|
+
if (i > start) result += ", ";
|
|
185
|
+
result += printValue(data[i]);
|
|
186
|
+
}
|
|
187
|
+
result += isTuple ? ")" : "}";
|
|
188
|
+
return result;
|
|
189
|
+
}
|
|
190
|
+
/** Generates stub ID for value. */
|
|
191
|
+
function valueStub(value) {
|
|
192
|
+
if (value == null) return "";
|
|
193
|
+
return generateStub(printValue(value));
|
|
194
|
+
}
|
|
195
|
+
/** Checks if value is a set representation, not a tuple representation. */
|
|
196
|
+
function isSetValue(data) {
|
|
197
|
+
return Array.isArray(data) && (data.length === 0 || data[0] !== -111);
|
|
198
|
+
}
|
|
199
|
+
/** Checks if value is a tuple representation. */
|
|
200
|
+
function isTupleValue(data) {
|
|
201
|
+
return Array.isArray(data) && data.length > 1 && data[0] === -111;
|
|
202
|
+
}
|
|
203
|
+
/** Normalize unsorted array of values. */
|
|
204
|
+
function normalizeValue(data) {
|
|
205
|
+
if (!Array.isArray(data) || data.length === 0) return;
|
|
206
|
+
if (data[0] === -111) {
|
|
207
|
+
for (let i = 1; i < data.length; i++) normalizeValue(data[i]);
|
|
208
|
+
return;
|
|
209
|
+
}
|
|
210
|
+
for (const item of data) normalizeValue(item);
|
|
211
|
+
data.sort((a, b) => compare(a, b));
|
|
212
|
+
let i = 1;
|
|
213
|
+
while (i < data.length) if (compare(data[i - 1], data[i]) === 0) data.splice(i, 1);
|
|
214
|
+
else i++;
|
|
215
|
+
}
|
|
216
|
+
/** Validates value for {@link ExpressionType} and value of basic sets. */
|
|
217
|
+
function validateValue(value, type, basics) {
|
|
218
|
+
switch (type.typeID) {
|
|
219
|
+
case TypeID.integer: return typeof value === "number";
|
|
220
|
+
case TypeID.logic:
|
|
221
|
+
if (typeof value !== "number") return false;
|
|
222
|
+
return value === 1 || value === 0;
|
|
223
|
+
case TypeID.basic: {
|
|
224
|
+
if (typeof value !== "number") return false;
|
|
225
|
+
const domain = basics.get(type.baseID);
|
|
226
|
+
return !!domain && Array.isArray(domain) && domain.includes(value);
|
|
227
|
+
}
|
|
228
|
+
case TypeID.tuple:
|
|
229
|
+
if (!Array.isArray(value) || value.length !== type.factors.length + 1 || value[0] !== -111) return false;
|
|
230
|
+
for (let i = 0; i < type.factors.length; i++) if (!validateValue(value[i + 1], type.factors[i], basics)) return false;
|
|
231
|
+
return true;
|
|
232
|
+
case TypeID.collection:
|
|
233
|
+
if (!isSetValue(value)) return false;
|
|
234
|
+
for (const item of value) if (!validateValue(item, type.base, basics)) return false;
|
|
235
|
+
return true;
|
|
236
|
+
case TypeID.anyTypification:
|
|
237
|
+
case TypeID.predicate:
|
|
238
|
+
case TypeID.function: return false;
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
/** Converts value path to type path. */
|
|
242
|
+
function convertPathToType(path, type) {
|
|
243
|
+
const result = [];
|
|
244
|
+
if (path.length === 0) return result;
|
|
245
|
+
let curType = type;
|
|
246
|
+
let index = 0;
|
|
247
|
+
while (index < path.length) switch (curType.typeID) {
|
|
248
|
+
case TypeID.collection:
|
|
249
|
+
result.push(0);
|
|
250
|
+
curType = curType.base;
|
|
251
|
+
index++;
|
|
252
|
+
break;
|
|
253
|
+
case TypeID.tuple: {
|
|
254
|
+
const tupleIdx = path[index];
|
|
255
|
+
if (typeof tupleIdx !== "number" || tupleIdx < 1 || tupleIdx > curType.factors.length) return null;
|
|
256
|
+
result.push(tupleIdx);
|
|
257
|
+
curType = curType.factors[tupleIdx - 1];
|
|
258
|
+
index++;
|
|
259
|
+
break;
|
|
260
|
+
}
|
|
261
|
+
case TypeID.basic:
|
|
262
|
+
case TypeID.integer:
|
|
263
|
+
case TypeID.anyTypification: return null;
|
|
264
|
+
}
|
|
265
|
+
return result;
|
|
266
|
+
}
|
|
267
|
+
/** Extracts value from a target by path. */
|
|
268
|
+
function extractValue(target, path) {
|
|
269
|
+
let current = target;
|
|
270
|
+
let i = 0;
|
|
271
|
+
while (i < path.length) {
|
|
272
|
+
if (!Array.isArray(current) || current.length <= path[i]) return null;
|
|
273
|
+
current = current[path[i]];
|
|
274
|
+
i++;
|
|
275
|
+
}
|
|
276
|
+
return current;
|
|
277
|
+
}
|
|
278
|
+
/** Makes default value for a type. */
|
|
279
|
+
function makeDefaultValue(type) {
|
|
280
|
+
switch (type.typeID) {
|
|
281
|
+
case TypeID.anyTypification:
|
|
282
|
+
case TypeID.integer:
|
|
283
|
+
case TypeID.basic: return -1;
|
|
284
|
+
case TypeID.collection: return [];
|
|
285
|
+
case TypeID.tuple: return tuple(type.factors.map((item) => makeDefaultValue(item)));
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
/** Perform immutable deep copy update. */
|
|
289
|
+
function setNestedValue(target, path, newVal) {
|
|
290
|
+
if (path.length === 0) return newVal;
|
|
291
|
+
const [head, ...rest] = path;
|
|
292
|
+
const arr = Array.isArray(target) ? [...target] : [];
|
|
293
|
+
arr[head] = setNestedValue(arr[head], makeValuePath(rest), newVal);
|
|
294
|
+
return arr;
|
|
295
|
+
}
|
|
296
|
+
/** Test if value contains invalid elements. */
|
|
297
|
+
function testInvalid(value) {
|
|
298
|
+
const stack = [value];
|
|
299
|
+
while (stack.length > 0) {
|
|
300
|
+
const current = stack.pop();
|
|
301
|
+
if (current === -1) return true;
|
|
302
|
+
if (Array.isArray(current)) for (const element of current) stack.push(element);
|
|
303
|
+
}
|
|
304
|
+
return false;
|
|
305
|
+
}
|
|
306
|
+
//#endregion
|
|
307
|
+
//#region src/rslang/eval/value.ts
|
|
308
|
+
/** Tuple ID for array distinction. */
|
|
309
|
+
const TUPLE_ID = -111;
|
|
310
|
+
/** Invalid value for structured data. */
|
|
311
|
+
const INVALID_ELEMENT = -1;
|
|
312
|
+
/** Boolean values: true. */
|
|
313
|
+
const VALUE_TRUE = 1;
|
|
314
|
+
/** Boolean values: false. */
|
|
315
|
+
const VALUE_FALSE = 0;
|
|
316
|
+
/** Cardinality threshold for "infinite" sets (e.g. Z). */
|
|
317
|
+
const SET_INFINITY = 1e7;
|
|
318
|
+
/** Cardinality threshold for Boolean power set. */
|
|
319
|
+
const BOOL_INFINITY = 18;
|
|
320
|
+
/** Creates value path. */
|
|
321
|
+
function makeValuePath(path) {
|
|
322
|
+
return path;
|
|
323
|
+
}
|
|
324
|
+
/** Empty set ∅. */
|
|
325
|
+
const EmptySetV = [];
|
|
326
|
+
/** Compare two structured data without recursive calls. */
|
|
327
|
+
function compare(v1, v2) {
|
|
328
|
+
const stack1 = [v1];
|
|
329
|
+
const stack2 = [v2];
|
|
330
|
+
while (stack1.length > 0 && stack2.length > 0) {
|
|
331
|
+
const el1 = stack1.pop();
|
|
332
|
+
const el2 = stack2.pop();
|
|
333
|
+
if (el1 === el2) continue;
|
|
334
|
+
if (typeof el1 === "number" && typeof el2 === "number") {
|
|
335
|
+
const numDiff = el1 - el2;
|
|
336
|
+
if (numDiff !== 0) return numDiff;
|
|
337
|
+
continue;
|
|
338
|
+
}
|
|
339
|
+
if (!Array.isArray(el1) || !Array.isArray(el2)) throw new Error(`Cannot compare different types ${printValue(el1)} and ${printValue(el2)}`);
|
|
340
|
+
const arr1 = el1;
|
|
341
|
+
const arr2 = el2;
|
|
342
|
+
const len1 = arr1.length;
|
|
343
|
+
const len2 = arr2.length;
|
|
344
|
+
if (len1 !== len2) return len1 - len2;
|
|
345
|
+
for (let i = len1 - 1; i >= 0; i--) {
|
|
346
|
+
stack1.push(arr1[i]);
|
|
347
|
+
stack2.push(arr2[i]);
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
return 0;
|
|
351
|
+
}
|
|
352
|
+
/** Tuple from components. */
|
|
353
|
+
function tuple(components) {
|
|
354
|
+
return [TUPLE_ID, ...components];
|
|
355
|
+
}
|
|
356
|
+
/** Set from elements (unique). Value[] - materialized. */
|
|
357
|
+
function set(elements) {
|
|
358
|
+
const sorted = [...elements].sort(compare);
|
|
359
|
+
for (let i = 1; i < sorted.length;) if (compare(sorted[i - 1], sorted[i]) === 0) sorted.splice(i, 1);
|
|
360
|
+
else i++;
|
|
361
|
+
return sorted;
|
|
362
|
+
}
|
|
363
|
+
//#endregion
|
|
364
|
+
export { testInvalid as A, projection as C, setNestedValue as D, setIntersection as E, valueStub as M, setSymDiff as O, printValue as S, setDiff as T, isSetValue as _, TUPLE_ID as a, makeDefaultValue as b, compare as c, tuple as d, boolean as f, extractValue as g, convertPathToType as h, SET_INFINITY as i, validateValue as j, setUnion as k, makeValuePath as l, contains as m, EmptySetV as n, VALUE_FALSE as o, cartesianProduct as p, INVALID_ELEMENT as r, VALUE_TRUE as s, BOOL_INFINITY as t, set as u, isSubsetOrEq as v, reduce as w, normalizeValue as x, isTupleValue as y };
|
|
365
|
+
|
|
366
|
+
//# sourceMappingURL=value-B8UtCqaK.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"value-B8UtCqaK.js","names":[],"sources":["../src/rslang/eval/value-api.ts","../src/rslang/eval/value.ts"],"sourcesContent":["import { generateStub } from '../../shared';\nimport { type ExpressionType, TypeID, type TypePath, type Typification } from '../semantic/typification';\n\nimport {\n BOOL_INFINITY,\n compare,\n EmptySetV,\n INVALID_ELEMENT,\n makeValuePath,\n set,\n SET_INFINITY,\n tuple,\n TUPLE_ID,\n type Value,\n VALUE_FALSE,\n VALUE_TRUE,\n type ValueContext,\n type ValuePath\n} from './value';\n\n/** Cartesian product of factor sets. */\nexport function cartesianProduct(factors: Value[][]): Value[] | null {\n const cardinality = factors.reduce((acc, f) => acc * f.length, 1);\n if (cardinality > SET_INFINITY) {\n return null;\n }\n if (cardinality === 0 || factors.length === 0) {\n return EmptySetV;\n }\n\n let accumulator: Value[][] = [[]];\n for (const factor of factors) {\n const next: Value[][] = [];\n for (const prefix of accumulator) {\n for (const value of factor) {\n next.push([...prefix, value]);\n }\n }\n accumulator = next;\n }\n return accumulator.map(tuple);\n}\n\n/** Boolean power set ℬ(X). No cache - materialized. */\nexport function boolean(base: Value[]): Value[] | null {\n if (base.length > BOOL_INFINITY) {\n return null;\n }\n return powerset(base);\n}\n\n/** Powerset of array. */\nfunction powerset(arr: readonly Value[]): Value[][] {\n const result: Value[][] = [[]];\n if (arr.length === 0) {\n return result;\n }\n\n let current: Value[][] = [[]];\n let maxIndex: number[] = [-1];\n while (current.length > 0) {\n const next: Value[][] = [];\n const nextMaxIndex: number[] = [];\n for (let i = 0; i < current.length; i++) {\n for (let j = maxIndex[i] + 1; j < arr.length; j++) {\n const subset = [...current[i], arr[j]];\n result.push(subset);\n if (j < arr.length - 1) {\n next.push(subset);\n nextMaxIndex.push(j);\n }\n }\n }\n current = next;\n maxIndex = nextMaxIndex;\n }\n return result;\n}\n\n/** Check if set contains element. */\nexport function contains(setData: Value[], element: Value): boolean {\n let left = 0;\n let right = setData.length - 1;\n while (left <= right) {\n const mid = Math.floor((left + right) / 2);\n const cmp = compare(setData[mid], element);\n if (cmp === 0) {\n return true;\n } else if (cmp < 0) {\n left = mid + 1;\n } else {\n right = mid - 1;\n }\n }\n return false;\n}\n\n/** Is A ⊆ B. */\nexport function isSubsetOrEq(a: Value[], b: Value[]): boolean {\n let i = 0,\n j = 0;\n while (i < a.length && j < b.length) {\n const cmp = compare(a[i], b[j]);\n if (cmp === 0) {\n i++;\n j++;\n } else if (cmp > 0) {\n j++;\n } else {\n return false;\n }\n }\n return i === a.length;\n}\n\n/** Reduce: flatten double boolean to single boolean. */\nexport function reduce(target: Value[][]): Value[] {\n const result: Value[] = [];\n for (const element of target) {\n result.push(...element);\n }\n return set(result);\n}\n\n/** Union A ∪ B. */\nexport function setUnion(set1: Value[], set2: Value[]): Value[] {\n const result: Value[] = [];\n let i = 0,\n j = 0;\n while (i < set1.length && j < set2.length) {\n const cmp = compare(set1[i], set2[j]);\n if (cmp < 0) {\n result.push(set1[i]);\n i++;\n } else if (cmp > 0) {\n result.push(set2[j]);\n j++;\n } else {\n result.push(set1[i]);\n i++;\n j++;\n }\n }\n while (i < set1.length) {\n result.push(set1[i]);\n i++;\n }\n while (j < set2.length) {\n result.push(set2[j]);\n j++;\n }\n return result;\n}\n\n/** Intersection A ∩ B. */\nexport function setIntersection(set1: Value[], set2: Value[]): Value[] {\n const result: Value[] = [];\n for (let i = 0, j = 0; i < set1.length && j < set2.length; ) {\n const cmp = compare(set1[i], set2[j]);\n if (cmp < 0) {\n i++;\n } else if (cmp > 0) {\n j++;\n } else {\n result.push(set1[i]);\n i++;\n j++;\n }\n }\n return result;\n}\n\n/** Difference A \\ B. */\nexport function setDiff(set1: Value[], set2: Value[]): Value[] {\n const result: Value[] = [];\n let i = 0,\n j = 0;\n while (i < set1.length && j < set2.length) {\n const cmp = compare(set1[i], set2[j]);\n if (cmp < 0) {\n result.push(set1[i]);\n i++;\n } else if (cmp > 0) {\n j++;\n } else {\n i++;\n j++;\n }\n }\n while (i < set1.length) {\n result.push(set1[i]);\n i++;\n }\n return result;\n}\n\n/** Symmetric difference A ∆ B. */\nexport function setSymDiff(set1: Value[], set2: Value[]): Value[] {\n const result: Value[] = [];\n let i = 0,\n j = 0;\n while (i < set1.length && j < set2.length) {\n const cmp = compare(set1[i], set2[j]);\n if (cmp < 0) {\n result.push(set1[i]);\n i++;\n } else if (cmp > 0) {\n result.push(set2[j]);\n j++;\n } else {\n i++;\n j++;\n }\n }\n while (i < set1.length) {\n result.push(set1[i]);\n i++;\n }\n while (j < set2.length) {\n result.push(set2[j]);\n j++;\n }\n return result;\n}\n\n/** Projection of set by indices (BigPr). */\nexport function projection(target: Value[][], indices: number[]): Value[] {\n const projectedElements: Value[] = target.map(element => {\n const newComponents = indices.map(idx => element[idx]);\n return indices.length === 1 ? newComponents[0] : tuple(newComponents);\n });\n return set(projectedElements);\n}\n\n/** Condensed string representation. */\nexport function printValue(data: Value | null): string {\n if (!Array.isArray(data)) {\n return String(data);\n }\n const len = data.length;\n if (data.length === 0) {\n return '{}';\n }\n\n const isTuple = data[0] === TUPLE_ID;\n const start = isTuple ? 1 : 0;\n\n let result = isTuple ? '(' : '{';\n for (let i = start; i < len; i++) {\n if (i > start) result += ', ';\n result += printValue(data[i]);\n }\n result += isTuple ? ')' : '}';\n return result;\n}\n\n/** Generates stub ID for value. */\nexport function valueStub(value: Value | null): string {\n if (value == null) {\n return '';\n }\n const str = printValue(value);\n return generateStub(str);\n}\n\n/** Checks if value is a set representation, not a tuple representation. */\nexport function isSetValue(data: Value | null): data is Value[] {\n return Array.isArray(data) && (data.length === 0 || data[0] !== TUPLE_ID);\n}\n\n/** Checks if value is a tuple representation. */\nexport function isTupleValue(data: Value | null): data is Value[] {\n return Array.isArray(data) && data.length > 1 && data[0] === TUPLE_ID;\n}\n\n/** Normalize unsorted array of values. */\nexport function normalizeValue(data: Value): void {\n if (!Array.isArray(data) || data.length === 0) {\n return;\n }\n\n if (data[0] === TUPLE_ID) {\n for (let i = 1; i < data.length; i++) {\n normalizeValue(data[i]);\n }\n return;\n }\n\n for (const item of data) {\n normalizeValue(item);\n }\n\n data.sort((a, b) => compare(a, b));\n let i = 1;\n while (i < data.length) {\n if (compare(data[i - 1], data[i]) === 0) {\n data.splice(i, 1);\n } else {\n i++;\n }\n }\n}\n\n/** Validates value for {@link ExpressionType} and value of basic sets. */\nexport function validateValue(value: Value, type: ExpressionType, basics: ValueContext): boolean {\n switch (type.typeID) {\n case TypeID.integer:\n return typeof value === 'number';\n case TypeID.logic: {\n if (typeof value !== 'number') {\n return false;\n }\n return value === VALUE_TRUE || value === VALUE_FALSE;\n }\n case TypeID.basic: {\n if (typeof value !== 'number') {\n return false;\n }\n const domain = basics.get(type.baseID);\n return !!domain && Array.isArray(domain) && domain.includes(value);\n }\n\n case TypeID.tuple: {\n if (!Array.isArray(value) || value.length !== type.factors.length + 1 || value[0] !== TUPLE_ID) {\n return false;\n }\n for (let i = 0; i < type.factors.length; i++) {\n if (!validateValue(value[i + 1], type.factors[i], basics)) {\n return false;\n }\n }\n return true;\n }\n\n case TypeID.collection: {\n if (!isSetValue(value)) {\n return false;\n }\n for (const item of value) {\n if (!validateValue(item, type.base, basics)) {\n return false;\n }\n }\n return true;\n }\n\n case TypeID.anyTypification:\n case TypeID.predicate:\n case TypeID.function:\n return false;\n }\n}\n\n/** Converts value path to type path. */\nexport function convertPathToType(path: ValuePath, type: Typification): TypePath | null {\n const result: number[] = [];\n if (path.length === 0) {\n return result as TypePath;\n }\n\n let curType = type;\n let index = 0;\n while (index < path.length) {\n switch (curType.typeID) {\n case TypeID.collection: {\n result.push(0);\n curType = curType.base;\n index++;\n break;\n }\n case TypeID.tuple: {\n const tupleIdx = path[index];\n if (typeof tupleIdx !== 'number' || tupleIdx < 1 || tupleIdx > curType.factors.length) {\n return null;\n }\n result.push(tupleIdx);\n curType = curType.factors[tupleIdx - 1];\n index++;\n break;\n }\n case TypeID.basic:\n case TypeID.integer:\n case TypeID.anyTypification:\n return null;\n }\n }\n return result as TypePath;\n}\n\n/** Extracts value from a target by path. */\nexport function extractValue(target: Value, path: ValuePath): Value | null {\n let current: Value = target;\n let i = 0;\n while (i < path.length) {\n if (!Array.isArray(current) || current.length <= path[i]) {\n return null;\n }\n current = current[path[i]];\n i++;\n }\n return current;\n}\n\n/** Makes default value for a type. */\nexport function makeDefaultValue(type: Typification): Value {\n switch (type.typeID) {\n case TypeID.anyTypification:\n case TypeID.integer:\n case TypeID.basic:\n return INVALID_ELEMENT;\n case TypeID.collection:\n return [];\n case TypeID.tuple:\n return tuple(type.factors.map(item => makeDefaultValue(item)));\n }\n}\n\n/** Perform immutable deep copy update. */\nexport function setNestedValue(target: Value | null, path: ValuePath, newVal: Value): Value {\n if (path.length === 0) {\n return newVal;\n }\n const [head, ...rest] = path;\n const arr = Array.isArray(target) ? [...target] : [];\n arr[head] = setNestedValue(arr[head], makeValuePath(rest), newVal);\n return arr;\n}\n\n/** Test if value contains invalid elements. */\nexport function testInvalid(value: Value): boolean {\n const stack = [value];\n while (stack.length > 0) {\n const current = stack.pop();\n if (current === INVALID_ELEMENT) {\n return true;\n }\n if (Array.isArray(current)) {\n for (const element of current) {\n stack.push(element);\n }\n }\n }\n return false;\n}\n","/**\n * Module: Structured data for RSLang expression evaluation.\n */\n\nimport { type Branded } from '../../shared';\n\nimport { printValue } from './value-api';\n\n/** Tuple ID for array distinction. */\nexport const TUPLE_ID = -111;\n\n/** Invalid value for structured data. */\nexport const INVALID_ELEMENT = -1;\n\n/** Boolean values: true. */\nexport const VALUE_TRUE = 1;\n\n/** Boolean values: false. */\nexport const VALUE_FALSE = 0;\n\n/** Cardinality threshold for \"infinite\" sets (e.g. Z). */\nexport const SET_INFINITY = 10_000_000;\n\n/** Cardinality threshold for Boolean power set. */\nexport const BOOL_INFINITY = 18;\n\n/** Expression evaluation result: structured data. */\nexport type Value = number | Value[];\n\n/** Values context. */\nexport type ValueContext = Map<string, Value>;\n\n/** Value extraction path. */\nexport type ValuePath = Branded<number[], 'ValuePath'>;\n\n/** Creates value path. */\nexport function makeValuePath(path: number[]): ValuePath {\n return path as ValuePath;\n}\n\n/** Empty set ∅. */\nexport const EmptySetV = [];\n\n/** Compare two structured data without recursive calls. */\nexport function compare(v1: Value, v2: Value): number {\n const stack1: Value[] = [v1];\n const stack2: Value[] = [v2];\n\n while (stack1.length > 0 && stack2.length > 0) {\n const el1 = stack1.pop();\n const el2 = stack2.pop();\n if (el1 === el2) {\n continue;\n }\n\n const type1 = typeof el1;\n const type2 = typeof el2;\n if (type1 === 'number' && type2 === 'number') {\n const numDiff = (el1 as number) - (el2 as number);\n if (numDiff !== 0) return numDiff;\n continue;\n }\n\n const isArray1 = Array.isArray(el1);\n const isArray2 = Array.isArray(el2);\n if (!isArray1 || !isArray2) {\n throw new Error(`Cannot compare different types ${printValue(el1!)} and ${printValue(el2!)}`);\n }\n\n const arr1 = el1;\n const arr2 = el2;\n const len1 = arr1.length;\n const len2 = arr2.length;\n if (len1 !== len2) {\n return len1 - len2;\n }\n\n for (let i = len1 - 1; i >= 0; i--) {\n stack1.push(arr1[i]);\n stack2.push(arr2[i]);\n }\n }\n return 0;\n}\n\n/** Tuple from components. */\nexport function tuple(components: Value[]): Value {\n return [TUPLE_ID, ...components];\n}\n\n/** Set from elements (unique). Value[] - materialized. */\nexport function set(elements: Value[]): Value[] {\n const sorted = [...elements].sort(compare);\n for (let i = 1; i < sorted.length; ) {\n if (compare(sorted[i - 1], sorted[i]) === 0) {\n sorted.splice(i, 1);\n } else {\n i++;\n }\n }\n return sorted;\n}\n"],"mappings":";;;;;AAqBA,SAAgB,iBAAiB,SAAoC;CACnE,MAAM,cAAc,QAAQ,QAAQ,KAAK,MAAM,MAAM,EAAE,QAAQ,CAAC;CAChE,IAAI,cAAA,KACF,OAAO;CAET,IAAI,gBAAgB,KAAK,QAAQ,WAAW,GAC1C,OAAO;CAGT,IAAI,cAAyB,CAAC,CAAC,CAAC;CAChC,KAAK,MAAM,UAAU,SAAS;EAC5B,MAAM,OAAkB,CAAC;EACzB,KAAK,MAAM,UAAU,aACnB,KAAK,MAAM,SAAS,QAClB,KAAK,KAAK,CAAC,GAAG,QAAQ,KAAK,CAAC;EAGhC,cAAc;CAChB;CACA,OAAO,YAAY,IAAI,KAAK;AAC9B;;AAGA,SAAgB,QAAQ,MAA+B;CACrD,IAAI,KAAK,SAAA,IACP,OAAO;CAET,OAAO,SAAS,IAAI;AACtB;;AAGA,SAAS,SAAS,KAAkC;CAClD,MAAM,SAAoB,CAAC,CAAC,CAAC;CAC7B,IAAI,IAAI,WAAW,GACjB,OAAO;CAGT,IAAI,UAAqB,CAAC,CAAC,CAAC;CAC5B,IAAI,WAAqB,CAAC,EAAE;CAC5B,OAAO,QAAQ,SAAS,GAAG;EACzB,MAAM,OAAkB,CAAC;EACzB,MAAM,eAAyB,CAAC;EAChC,KAAK,IAAI,IAAI,GAAG,IAAI,QAAQ,QAAQ,KAClC,KAAK,IAAI,IAAI,SAAS,KAAK,GAAG,IAAI,IAAI,QAAQ,KAAK;GACjD,MAAM,SAAS,CAAC,GAAG,QAAQ,IAAI,IAAI,EAAE;GACrC,OAAO,KAAK,MAAM;GAClB,IAAI,IAAI,IAAI,SAAS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CAAC,CAAC,KAAK,OAAO;CACzC,KAAK,IAAI,IAAI,GAAG,IAAI,OAAO,SACzB,IAAI,QAAQ,OAAO,IAAI,IAAI,OAAO,EAAE,MAAM,GACxC,OAAO,OAAO,GAAG,CAAC;MAElB;CAGJ,OAAO;AACT"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { t as Branded } from "./branded-ZlzIcxzu.js";
|
|
2
|
+
//#region src/rslang/eval/value.d.ts
|
|
3
|
+
/** Tuple ID for array distinction. */
|
|
4
|
+
declare const TUPLE_ID = -111;
|
|
5
|
+
/** Invalid value for structured data. */
|
|
6
|
+
declare const INVALID_ELEMENT = -1;
|
|
7
|
+
/** Boolean values: true. */
|
|
8
|
+
declare const VALUE_TRUE = 1;
|
|
9
|
+
/** Boolean values: false. */
|
|
10
|
+
declare const VALUE_FALSE = 0;
|
|
11
|
+
/** Cardinality threshold for "infinite" sets (e.g. Z). */
|
|
12
|
+
declare const SET_INFINITY = 10000000;
|
|
13
|
+
/** Cardinality threshold for Boolean power set. */
|
|
14
|
+
declare const BOOL_INFINITY = 18;
|
|
15
|
+
/** Expression evaluation result: structured data. */
|
|
16
|
+
type Value = number | Value[];
|
|
17
|
+
/** Values context. */
|
|
18
|
+
type ValueContext = Map<string, Value>;
|
|
19
|
+
/** Value extraction path. */
|
|
20
|
+
type ValuePath = Branded<number[], 'ValuePath'>;
|
|
21
|
+
/** Creates value path. */
|
|
22
|
+
declare function makeValuePath(path: number[]): ValuePath;
|
|
23
|
+
/** Empty set ∅. */
|
|
24
|
+
declare const EmptySetV: never[];
|
|
25
|
+
/** Compare two structured data without recursive calls. */
|
|
26
|
+
declare function compare(v1: Value, v2: Value): number;
|
|
27
|
+
/** Tuple from components. */
|
|
28
|
+
declare function tuple(components: Value[]): Value;
|
|
29
|
+
/** Set from elements (unique). Value[] - materialized. */
|
|
30
|
+
declare function set(elements: Value[]): Value[];
|
|
31
|
+
//#endregion
|
|
32
|
+
export { TUPLE_ID as a, Value as c, compare as d, makeValuePath as f, SET_INFINITY as i, ValueContext as l, tuple as m, EmptySetV as n, VALUE_FALSE as o, set as p, INVALID_ELEMENT as r, VALUE_TRUE as s, BOOL_INFINITY as t, ValuePath as u };
|
|
33
|
+
//# sourceMappingURL=value-CTjX6825.d.ts.map
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { b as Typification, f as ExpressionType, y as TypePath } from "./typification-Dk-fisgO.js";
|
|
2
|
+
import { c as Value, l as ValueContext, u as ValuePath } from "./value-CTjX6825.js";
|
|
3
|
+
|
|
4
|
+
//#region src/rslang/eval/value-api.d.ts
|
|
5
|
+
/** Cartesian product of factor sets. */
|
|
6
|
+
declare function cartesianProduct(factors: Value[][]): Value[] | null;
|
|
7
|
+
/** Boolean power set ℬ(X). No cache - materialized. */
|
|
8
|
+
declare function boolean(base: Value[]): Value[] | null;
|
|
9
|
+
/** Check if set contains element. */
|
|
10
|
+
declare function contains(setData: Value[], element: Value): boolean;
|
|
11
|
+
/** Is A ⊆ B. */
|
|
12
|
+
declare function isSubsetOrEq(a: Value[], b: Value[]): boolean;
|
|
13
|
+
/** Reduce: flatten double boolean to single boolean. */
|
|
14
|
+
declare function reduce(target: Value[][]): Value[];
|
|
15
|
+
/** Union A ∪ B. */
|
|
16
|
+
declare function setUnion(set1: Value[], set2: Value[]): Value[];
|
|
17
|
+
/** Intersection A ∩ B. */
|
|
18
|
+
declare function setIntersection(set1: Value[], set2: Value[]): Value[];
|
|
19
|
+
/** Difference A \ B. */
|
|
20
|
+
declare function setDiff(set1: Value[], set2: Value[]): Value[];
|
|
21
|
+
/** Symmetric difference A ∆ B. */
|
|
22
|
+
declare function setSymDiff(set1: Value[], set2: Value[]): Value[];
|
|
23
|
+
/** Projection of set by indices (BigPr). */
|
|
24
|
+
declare function projection(target: Value[][], indices: number[]): Value[];
|
|
25
|
+
/** Condensed string representation. */
|
|
26
|
+
declare function printValue(data: Value | null): string;
|
|
27
|
+
/** Generates stub ID for value. */
|
|
28
|
+
declare function valueStub(value: Value | null): string;
|
|
29
|
+
/** Checks if value is a set representation, not a tuple representation. */
|
|
30
|
+
declare function isSetValue(data: Value | null): data is Value[];
|
|
31
|
+
/** Checks if value is a tuple representation. */
|
|
32
|
+
declare function isTupleValue(data: Value | null): data is Value[];
|
|
33
|
+
/** Normalize unsorted array of values. */
|
|
34
|
+
declare function normalizeValue(data: Value): void;
|
|
35
|
+
/** Validates value for {@link ExpressionType} and value of basic sets. */
|
|
36
|
+
declare function validateValue(value: Value, type: ExpressionType, basics: ValueContext): boolean;
|
|
37
|
+
/** Converts value path to type path. */
|
|
38
|
+
declare function convertPathToType(path: ValuePath, type: Typification): TypePath | null;
|
|
39
|
+
/** Extracts value from a target by path. */
|
|
40
|
+
declare function extractValue(target: Value, path: ValuePath): Value | null;
|
|
41
|
+
/** Makes default value for a type. */
|
|
42
|
+
declare function makeDefaultValue(type: Typification): Value;
|
|
43
|
+
/** Perform immutable deep copy update. */
|
|
44
|
+
declare function setNestedValue(target: Value | null, path: ValuePath, newVal: Value): Value;
|
|
45
|
+
/** Test if value contains invalid elements. */
|
|
46
|
+
declare function testInvalid(value: Value): boolean;
|
|
47
|
+
//#endregion
|
|
48
|
+
export { setSymDiff as _, extractValue as a, validateValue as b, isTupleValue as c, printValue as d, projection as f, setNestedValue as g, setIntersection as h, convertPathToType as i, makeDefaultValue as l, setDiff as m, cartesianProduct as n, isSetValue as o, reduce as p, contains as r, isSubsetOrEq as s, boolean as t, normalizeValue as u, setUnion as v, valueStub as x, testInvalid as y };
|
|
49
|
+
//# sourceMappingURL=value-api-Bw-SgaYY.d.ts.map
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
//#region src/rslang/semantic/value-class.d.ts
|
|
2
|
+
/** Represents computability class. */
|
|
3
|
+
declare const ValueClass: {
|
|
4
|
+
readonly VALUE: "value";
|
|
5
|
+
readonly PROPERTY: "property";
|
|
6
|
+
};
|
|
7
|
+
type ValueClass = (typeof ValueClass)[keyof typeof ValueClass];
|
|
8
|
+
/** ValueClass context. */
|
|
9
|
+
type ValueClassContext = Map<string, ValueClass>;
|
|
10
|
+
//#endregion
|
|
11
|
+
export { ValueClassContext as n, ValueClass as t };
|
|
12
|
+
//# sourceMappingURL=value-class-CNI-lqXJ.d.ts.map
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rsconcept/domain",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "Shared TypeScript domain for RS language, RSForm, RSModel, RSEngine, OSS, and concept-text helpers.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "IRBorisov",
|
|
7
7
|
"repository": {
|
|
8
8
|
"type": "git",
|
|
9
|
-
"url": "git+https://github.com/IRBorisov/ConceptPortal
|
|
9
|
+
"url": "git+https://github.com/IRBorisov/ConceptPortal",
|
|
10
10
|
"directory": "rsconcept/domain"
|
|
11
11
|
},
|
|
12
12
|
"homepage": "https://portal.acconcept.ru",
|
|
@@ -152,7 +152,7 @@
|
|
|
152
152
|
],
|
|
153
153
|
"scripts": {
|
|
154
154
|
"generate": "lezer-generator src/rslang/parser/rslang.grammar -o src/rslang/parser/parser.ts",
|
|
155
|
-
"build": "
|
|
155
|
+
"build": "tsdown",
|
|
156
156
|
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
157
157
|
"test": "vitest run",
|
|
158
158
|
"lint": "eslint . --report-unused-disable-directives --max-warnings 0",
|
|
@@ -167,16 +167,16 @@
|
|
|
167
167
|
},
|
|
168
168
|
"devDependencies": {
|
|
169
169
|
"@lezer/generator": "^1.8.0",
|
|
170
|
-
"@types/node": "^25.9.
|
|
170
|
+
"@types/node": "^25.9.3",
|
|
171
171
|
"@typescript-eslint/parser": "^8.0.1",
|
|
172
172
|
"eslint": "^9.39.4",
|
|
173
173
|
"eslint-plugin-simple-import-sort": "^13.0.0",
|
|
174
174
|
"globals": "^17.6.0",
|
|
175
|
-
"prettier": "^3.8.
|
|
176
|
-
"
|
|
175
|
+
"prettier": "^3.8.4",
|
|
176
|
+
"tsdown": "^0.22.2",
|
|
177
177
|
"typescript": "^6.0.3",
|
|
178
|
-
"typescript-eslint": "^8.
|
|
179
|
-
"vitest": "^4.1.
|
|
178
|
+
"typescript-eslint": "^8.61.0",
|
|
179
|
+
"vitest": "^4.1.8"
|
|
180
180
|
},
|
|
181
181
|
"publishConfig": {
|
|
182
182
|
"access": "public"
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
|
|
3
|
+
import { CstType } from './rsform';
|
|
4
|
+
import { validateAliasFormat } from './rsform-api';
|
|
5
|
+
|
|
6
|
+
describe('validateAliasFormat', () => {
|
|
7
|
+
it('accepts alias with type prefix and numeric suffix', () => {
|
|
8
|
+
expect(validateAliasFormat('X1', CstType.BASE)).toBe(true);
|
|
9
|
+
expect(validateAliasFormat('D12', CstType.TERM)).toBe(true);
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
it('rejects alias with wrong prefix for type', () => {
|
|
13
|
+
expect(validateAliasFormat('D1', CstType.BASE)).toBe(false);
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
it('rejects alias without numeric suffix', () => {
|
|
17
|
+
expect(validateAliasFormat('X', CstType.BASE)).toBe(false);
|
|
18
|
+
expect(validateAliasFormat('XA', CstType.BASE)).toBe(false);
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
it('rejects duplicate-looking aliases with non-digit suffix', () => {
|
|
22
|
+
expect(validateAliasFormat('X1a', CstType.BASE)).toBe(false);
|
|
23
|
+
});
|
|
24
|
+
});
|
|
@@ -257,8 +257,8 @@ export function canHaveManualTypification(type: CstType): boolean {
|
|
|
257
257
|
}
|
|
258
258
|
}
|
|
259
259
|
|
|
260
|
-
/** Validate
|
|
261
|
-
export function
|
|
260
|
+
/** Validate alias format for a given {@link CstType} (prefix + digits, min length 2). */
|
|
261
|
+
export function validateAliasFormat(alias: string, type: CstType): boolean {
|
|
262
262
|
if (alias.length < 2) {
|
|
263
263
|
return false;
|
|
264
264
|
}
|
|
@@ -266,10 +266,18 @@ export function validateNewAlias(alias: string, type: CstType, schema: RSForm):
|
|
|
266
266
|
if (!alias.startsWith(prefix)) {
|
|
267
267
|
return false;
|
|
268
268
|
}
|
|
269
|
-
if (
|
|
269
|
+
if (!/^\d+$/.exec(alias.substring(prefix.length))) {
|
|
270
270
|
return false;
|
|
271
271
|
}
|
|
272
|
-
|
|
272
|
+
return true;
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
/** Validate new alias against {@link CstType} and {@link RSForm}. */
|
|
276
|
+
export function validateNewAlias(alias: string, type: CstType, schema: RSForm): boolean {
|
|
277
|
+
if (!validateAliasFormat(alias, type)) {
|
|
278
|
+
return false;
|
|
279
|
+
}
|
|
280
|
+
if (schema.cstByAlias.has(alias)) {
|
|
273
281
|
return false;
|
|
274
282
|
}
|
|
275
283
|
return true;
|
package/dist/cctext/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/cctext/language.ts"],"sourcesContent":["/**\n * Module: Natural language model declarations.\n */\n\n/** Represents single unit of language Morphology. */\n// prettier-ignore\nexport const Grammeme = {\n // Число\n sing: 'sing', plur: 'plur',\n\n // Падеж\n nomn: 'nomn', gent: 'gent', datv: 'datv',\n accs: 'accs', ablt: 'ablt', loct: 'loct',\n} as const;\nexport type Grammeme = (typeof Grammeme)[keyof typeof Grammeme];\n\n/** Represents case language concept. */\nexport const Case: Grammeme[] = [\n Grammeme.nomn,\n Grammeme.gent,\n Grammeme.datv,\n Grammeme.accs,\n Grammeme.ablt,\n Grammeme.loct\n] as const;\n\n/** Represents plurality language concept. */\nexport const Plurality: Grammeme[] = [Grammeme.sing, Grammeme.plur] as const;\n\n/** Represents specific wordform attached to {@link Grammeme}s. */\nexport interface WordForm {\n text: string;\n grams: Grammeme[];\n}\n\n/** Represents a term available for text reference resolution. */\nexport interface TermContextItem {\n nominal: string;\n forms?: WordForm[];\n}\n\n/** Represents term lookup context keyed by entity alias. */\nexport type TermContext = Record<string, TermContextItem>;\n\n/**\n * Represents list of {@link Grammeme}s available in reference construction.\n */\n// prettier-ignore\nexport const supportedGrammemes = [\n Grammeme.sing, Grammeme.plur,\n Grammeme.nomn, Grammeme.gent, Grammeme.datv,\n Grammeme.accs, Grammeme.ablt, Grammeme.loct,\n] as const;\n\n// ====== Reference resolution =====\n\n/** Represents text reference type. */\nexport const ReferenceType = {\n ENTITY: 'entity',\n SYNTACTIC: 'syntax'\n} as const;\nexport type ReferenceType = (typeof ReferenceType)[keyof typeof ReferenceType];\n\n/** Represents entity reference payload. */\nexport interface EntityReference {\n entity: string;\n tags: Grammeme[];\n}\n\n/** Represents syntactic reference payload. */\nexport interface SyntacticReference {\n offset: number;\n nominal: string;\n}\n\n/** Represents abstract reference data. */\nexport interface IReference {\n type: ReferenceType;\n data: EntityReference | SyntacticReference;\n}\n"],"mappings":";AAMO,IAAM,WAAW;AAAA;AAAA,EAEtB,MAAM;AAAA,EAAQ,MAAM;AAAA;AAAA,EAGpB,MAAM;AAAA,EAAQ,MAAM;AAAA,EAAQ,MAAM;AAAA,EAClC,MAAM;AAAA,EAAQ,MAAM;AAAA,EAAQ,MAAM;AACpC;AAIO,IAAM,OAAmB;AAAA,EAC9B,SAAS;AAAA,EACT,SAAS;AAAA,EACT,SAAS;AAAA,EACT,SAAS;AAAA,EACT,SAAS;AAAA,EACT,SAAS;AACX;AAGO,IAAM,YAAwB,CAAC,SAAS,MAAM,SAAS,IAAI;AAqB3D,IAAM,qBAAqB;AAAA,EAChC,SAAS;AAAA,EAAM,SAAS;AAAA,EACxB,SAAS;AAAA,EAAM,SAAS;AAAA,EAAM,SAAS;AAAA,EACvC,SAAS;AAAA,EAAM,SAAS;AAAA,EAAM,SAAS;AACzC;AAKO,IAAM,gBAAgB;AAAA,EAC3B,QAAQ;AAAA,EACR,WAAW;AACb;","names":[]}
|