@rsconcept/domain 1.0.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/LICENSE +21 -0
- package/README.md +55 -0
- package/dist/cctext/index.d.ts +1 -0
- package/dist/cctext/index.js +42 -0
- package/dist/cctext/index.js.map +1 -0
- package/dist/cctext/language-api.d.ts +43 -0
- package/dist/cctext/language-api.js +252 -0
- package/dist/cctext/language-api.js.map +1 -0
- package/dist/cctext/language.d.ts +58 -0
- package/dist/cctext/language.js +44 -0
- package/dist/cctext/language.js.map +1 -0
- package/dist/graph/graph.d.ts +62 -0
- package/dist/graph/graph.js +385 -0
- package/dist/graph/graph.js.map +1 -0
- package/dist/graph/index.d.ts +1 -0
- package/dist/graph/index.js +384 -0
- package/dist/graph/index.js.map +1 -0
- package/dist/index.d.ts +28 -0
- package/dist/index.js +5851 -0
- package/dist/index.js.map +1 -0
- package/dist/library/folder-tree.d.ts +32 -0
- package/dist/library/folder-tree.js +136 -0
- package/dist/library/folder-tree.js.map +1 -0
- package/dist/library/index.d.ts +17 -0
- package/dist/library/index.js +2800 -0
- package/dist/library/index.js.map +1 -0
- package/dist/library/library-api.d.ts +6 -0
- package/dist/library/library-api.js +13 -0
- package/dist/library/library-api.js.map +1 -0
- package/dist/library/library.d.ts +56 -0
- package/dist/library/library.js +23 -0
- package/dist/library/library.js.map +1 -0
- package/dist/library/oss-api.d.ts +47 -0
- package/dist/library/oss-api.js +1105 -0
- package/dist/library/oss-api.js.map +1 -0
- package/dist/library/oss-layout-api.d.ts +36 -0
- package/dist/library/oss-layout-api.js +330 -0
- package/dist/library/oss-layout-api.js.map +1 -0
- package/dist/library/oss-layout.d.ts +25 -0
- package/dist/library/oss-layout.js +1 -0
- package/dist/library/oss-layout.js.map +1 -0
- package/dist/library/oss.d.ts +136 -0
- package/dist/library/oss.js +30 -0
- package/dist/library/oss.js.map +1 -0
- package/dist/library/rsengine.d.ts +116 -0
- package/dist/library/rsengine.js +2604 -0
- package/dist/library/rsengine.js.map +1 -0
- package/dist/library/rsform-api.d.ts +74 -0
- package/dist/library/rsform-api.js +879 -0
- package/dist/library/rsform-api.js.map +1 -0
- package/dist/library/rsform.d.ts +206 -0
- package/dist/library/rsform.js +32 -0
- package/dist/library/rsform.js.map +1 -0
- package/dist/library/rsmodel-api.d.ts +43 -0
- package/dist/library/rsmodel-api.js +836 -0
- package/dist/library/rsmodel-api.js.map +1 -0
- package/dist/library/rsmodel.d.ts +52 -0
- package/dist/library/rsmodel.js +25 -0
- package/dist/library/rsmodel.js.map +1 -0
- package/dist/library/structure-planner.d.ts +33 -0
- package/dist/library/structure-planner.js +481 -0
- package/dist/library/structure-planner.js.map +1 -0
- package/dist/parsing/ast.d.ts +49 -0
- package/dist/parsing/ast.js +93 -0
- package/dist/parsing/ast.js.map +1 -0
- package/dist/parsing/index.d.ts +3 -0
- package/dist/parsing/index.js +141 -0
- package/dist/parsing/index.js.map +1 -0
- package/dist/parsing/lezer-tree.d.ts +13 -0
- package/dist/parsing/lezer-tree.js +50 -0
- package/dist/parsing/lezer-tree.js.map +1 -0
- package/dist/rslang/api.d.ts +53 -0
- package/dist/rslang/api.js +846 -0
- package/dist/rslang/api.js.map +1 -0
- package/dist/rslang/ast-annotations.d.ts +18 -0
- package/dist/rslang/ast-annotations.js +56 -0
- package/dist/rslang/ast-annotations.js.map +1 -0
- package/dist/rslang/error.d.ts +85 -0
- package/dist/rslang/error.js +159 -0
- package/dist/rslang/error.js.map +1 -0
- package/dist/rslang/eval/calculator.d.ts +43 -0
- package/dist/rslang/eval/calculator.js +1639 -0
- package/dist/rslang/eval/calculator.js.map +1 -0
- package/dist/rslang/eval/evaluation-cache.d.ts +36 -0
- package/dist/rslang/eval/evaluation-cache.js +310 -0
- package/dist/rslang/eval/evaluation-cache.js.map +1 -0
- package/dist/rslang/eval/evaluator.d.ts +70 -0
- package/dist/rslang/eval/evaluator.js +1514 -0
- package/dist/rslang/eval/evaluator.js.map +1 -0
- package/dist/rslang/eval/value-api.d.ts +48 -0
- package/dist/rslang/eval/value-api.js +490 -0
- package/dist/rslang/eval/value-api.js.map +1 -0
- package/dist/rslang/eval/value.d.ts +36 -0
- package/dist/rslang/eval/value.js +118 -0
- package/dist/rslang/eval/value.js.map +1 -0
- package/dist/rslang/index.d.ts +17 -0
- package/dist/rslang/index.js +4314 -0
- package/dist/rslang/index.js.map +1 -0
- package/dist/rslang/labels.d.ts +16 -0
- package/dist/rslang/labels.js +315 -0
- package/dist/rslang/labels.js.map +1 -0
- package/dist/rslang/parser/expression-generator.d.ts +10 -0
- package/dist/rslang/parser/expression-generator.js +451 -0
- package/dist/rslang/parser/expression-generator.js.map +1 -0
- package/dist/rslang/parser/normalize.d.ts +11 -0
- package/dist/rslang/parser/normalize.js +507 -0
- package/dist/rslang/parser/normalize.js.map +1 -0
- package/dist/rslang/parser/parser.d.ts +5 -0
- package/dist/rslang/parser/parser.js +24 -0
- package/dist/rslang/parser/parser.js.map +1 -0
- package/dist/rslang/parser/parser.terms.d.ts +42 -0
- package/dist/rslang/parser/parser.terms.js +84 -0
- package/dist/rslang/parser/parser.terms.js.map +1 -0
- package/dist/rslang/parser/syntax-errors.d.ts +11 -0
- package/dist/rslang/parser/syntax-errors.js +403 -0
- package/dist/rslang/parser/syntax-errors.js.map +1 -0
- package/dist/rslang/parser/token.d.ts +79 -0
- package/dist/rslang/parser/token.js +95 -0
- package/dist/rslang/parser/token.js.map +1 -0
- package/dist/rslang/semantic/analyzer.d.ts +39 -0
- package/dist/rslang/semantic/analyzer.js +2604 -0
- package/dist/rslang/semantic/analyzer.js.map +1 -0
- package/dist/rslang/semantic/arguments-extractor.d.ts +42 -0
- package/dist/rslang/semantic/arguments-extractor.js +366 -0
- package/dist/rslang/semantic/arguments-extractor.js.map +1 -0
- package/dist/rslang/semantic/type-auditor.d.ts +73 -0
- package/dist/rslang/semantic/type-auditor.js +1570 -0
- package/dist/rslang/semantic/type-auditor.js.map +1 -0
- package/dist/rslang/semantic/typification-api.d.ts +27 -0
- package/dist/rslang/semantic/typification-api.js +320 -0
- package/dist/rslang/semantic/typification-api.js.map +1 -0
- package/dist/rslang/semantic/typification-parser.d.ts +12 -0
- package/dist/rslang/semantic/typification-parser.js +226 -0
- package/dist/rslang/semantic/typification-parser.js.map +1 -0
- package/dist/rslang/semantic/typification.d.ts +119 -0
- package/dist/rslang/semantic/typification.js +74 -0
- package/dist/rslang/semantic/typification.js.map +1 -0
- package/dist/rslang/semantic/value-auditor.d.ts +43 -0
- package/dist/rslang/semantic/value-auditor.js +523 -0
- package/dist/rslang/semantic/value-auditor.js.map +1 -0
- package/dist/rslang/semantic/value-class.d.ts +10 -0
- package/dist/rslang/semantic/value-class.js +9 -0
- package/dist/rslang/semantic/value-class.js.map +1 -0
- package/dist/rslang/typification-graph.d.ts +33 -0
- package/dist/rslang/typification-graph.js +311 -0
- package/dist/rslang/typification-graph.js.map +1 -0
- package/dist/shared/branded.d.ts +7 -0
- package/dist/shared/branded.js +1 -0
- package/dist/shared/branded.js.map +1 -0
- package/dist/shared/hash.d.ts +6 -0
- package/dist/shared/hash.js +18 -0
- package/dist/shared/hash.js.map +1 -0
- package/dist/shared/index.d.ts +2 -0
- package/dist/shared/index.js +18 -0
- package/dist/shared/index.js.map +1 -0
- package/package.json +184 -0
- package/src/cctext/index.ts +9 -0
- package/src/cctext/language-api.test.ts +149 -0
- package/src/cctext/language-api.ts +285 -0
- package/src/cctext/language.ts +80 -0
- package/src/graph/graph.test.ts +392 -0
- package/src/graph/graph.ts +433 -0
- package/src/graph/index.ts +1 -0
- package/src/index.ts +96 -0
- package/src/library/folder-tree.test.ts +47 -0
- package/src/library/folder-tree.ts +156 -0
- package/src/library/index.ts +46 -0
- package/src/library/library-api.test.ts +32 -0
- package/src/library/library-api.ts +11 -0
- package/src/library/library.ts +61 -0
- package/src/library/oss-api.ts +449 -0
- package/src/library/oss-layout-api.ts +377 -0
- package/src/library/oss-layout.ts +27 -0
- package/src/library/oss.ts +150 -0
- package/src/library/rsengine.ts +593 -0
- package/src/library/rsform-api.ts +533 -0
- package/src/library/rsform.ts +228 -0
- package/src/library/rsmodel-api.ts +340 -0
- package/src/library/rsmodel.ts +50 -0
- package/src/library/structure-planner.ts +143 -0
- package/src/parsing/ast.ts +136 -0
- package/src/parsing/index.ts +15 -0
- package/src/parsing/lezer-tree.ts +69 -0
- package/src/rslang/api.test.ts +116 -0
- package/src/rslang/api.ts +183 -0
- package/src/rslang/ast-annotations.ts +70 -0
- package/src/rslang/error.ts +129 -0
- package/src/rslang/eval/calculator.test.ts +124 -0
- package/src/rslang/eval/calculator.ts +121 -0
- package/src/rslang/eval/evaluation-cache.ts +257 -0
- package/src/rslang/eval/evaluator.test.ts +352 -0
- package/src/rslang/eval/evaluator.ts +935 -0
- package/src/rslang/eval/value-api.test.ts +105 -0
- package/src/rslang/eval/value-api.ts +444 -0
- package/src/rslang/eval/value.ts +102 -0
- package/src/rslang/index.ts +23 -0
- package/src/rslang/labels.ts +191 -0
- package/src/rslang/parser/expression-generator.test.ts +100 -0
- package/src/rslang/parser/expression-generator.ts +466 -0
- package/src/rslang/parser/normalize.test.ts +99 -0
- package/src/rslang/parser/normalize.ts +462 -0
- package/src/rslang/parser/parser.terms.ts +42 -0
- package/src/rslang/parser/parser.test.ts +153 -0
- package/src/rslang/parser/parser.ts +20 -0
- package/src/rslang/parser/rslang.grammar +251 -0
- package/src/rslang/parser/syntax-errors.ts +209 -0
- package/src/rslang/parser/token.ts +106 -0
- package/src/rslang/semantic/analyzer.test.ts +59 -0
- package/src/rslang/semantic/analyzer.ts +179 -0
- package/src/rslang/semantic/arguments-extractor.ts +327 -0
- package/src/rslang/semantic/type-auditor.test.ts +326 -0
- package/src/rslang/semantic/type-auditor.ts +1049 -0
- package/src/rslang/semantic/typification-api.test.ts +46 -0
- package/src/rslang/semantic/typification-api.ts +321 -0
- package/src/rslang/semantic/typification-parser.test.ts +50 -0
- package/src/rslang/semantic/typification-parser.ts +220 -0
- package/src/rslang/semantic/typification.ts +180 -0
- package/src/rslang/semantic/value-auditor.test.ts +206 -0
- package/src/rslang/semantic/value-auditor.ts +332 -0
- package/src/rslang/semantic/value-class.ts +11 -0
- package/src/rslang/typification-graph.ts +155 -0
- package/src/shared/branded.ts +6 -0
- package/src/shared/hash.ts +17 -0
- package/src/shared/index.ts +2 -0
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
// src/rslang/semantic/typification.ts
|
|
2
|
+
var TypeID = {
|
|
3
|
+
anyTypification: 1,
|
|
4
|
+
integer: 2,
|
|
5
|
+
basic: 3,
|
|
6
|
+
tuple: 4,
|
|
7
|
+
collection: 5,
|
|
8
|
+
logic: 6,
|
|
9
|
+
function: 7,
|
|
10
|
+
predicate: 8
|
|
11
|
+
};
|
|
12
|
+
var LogicT = { typeID: TypeID.logic };
|
|
13
|
+
var IntegerT = {
|
|
14
|
+
typeID: TypeID.integer,
|
|
15
|
+
isOrdered: true,
|
|
16
|
+
isArithmetic: true,
|
|
17
|
+
isIntegerCompatible: true
|
|
18
|
+
};
|
|
19
|
+
var AnyTypificationT = { typeID: TypeID.anyTypification };
|
|
20
|
+
var EmptySetT = bool(AnyTypificationT);
|
|
21
|
+
function bool(base) {
|
|
22
|
+
return { typeID: TypeID.collection, base };
|
|
23
|
+
}
|
|
24
|
+
function tuple(factors) {
|
|
25
|
+
if (factors.length < 2) {
|
|
26
|
+
throw new Error("Tuple with less than two factors is not allowed");
|
|
27
|
+
}
|
|
28
|
+
return { typeID: TypeID.tuple, factors };
|
|
29
|
+
}
|
|
30
|
+
function isTypification(type) {
|
|
31
|
+
return type?.typeID === TypeID.basic || type?.typeID === TypeID.anyTypification || type?.typeID === TypeID.integer || type?.typeID === TypeID.collection || type?.typeID === TypeID.tuple;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// src/rslang/semantic/typification-parser.ts
|
|
35
|
+
function parseTypeText(input) {
|
|
36
|
+
const normalized = input.trim().replaceAll("->", "\u2192");
|
|
37
|
+
if (normalized.length === 0) {
|
|
38
|
+
return { type: null, error: null };
|
|
39
|
+
}
|
|
40
|
+
const parser = new TypificationParser(normalized);
|
|
41
|
+
return parser.parse();
|
|
42
|
+
}
|
|
43
|
+
function applyAsciiTypeSubstitutions(raw) {
|
|
44
|
+
return raw.replaceAll("->", "\u2192").replaceAll("*", "\xD7").replaceAll("B", "\u212C");
|
|
45
|
+
}
|
|
46
|
+
var TypificationParser = class {
|
|
47
|
+
index = 0;
|
|
48
|
+
input;
|
|
49
|
+
constructor(input) {
|
|
50
|
+
this.index = 0;
|
|
51
|
+
this.input = input;
|
|
52
|
+
}
|
|
53
|
+
parse() {
|
|
54
|
+
try {
|
|
55
|
+
const result = this.parseExpressionType();
|
|
56
|
+
this.skipSpaces();
|
|
57
|
+
if (!this.eof()) {
|
|
58
|
+
throw new Error("Unexpected trailing symbols");
|
|
59
|
+
}
|
|
60
|
+
return { type: result, error: null };
|
|
61
|
+
} catch (error) {
|
|
62
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
63
|
+
return { type: null, error: message };
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
parseExpressionType() {
|
|
67
|
+
this.skipSpaces();
|
|
68
|
+
if (this.peek() === "[") {
|
|
69
|
+
return this.parseCallableType();
|
|
70
|
+
} else {
|
|
71
|
+
return this.parseTypification();
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
parseCallableType() {
|
|
75
|
+
this.expect("[");
|
|
76
|
+
const args = [];
|
|
77
|
+
this.skipSpaces();
|
|
78
|
+
if (this.peek() !== "]") {
|
|
79
|
+
while (true) {
|
|
80
|
+
args.push(this.parseTypification());
|
|
81
|
+
this.skipSpaces();
|
|
82
|
+
if (this.peek() === ",") {
|
|
83
|
+
this.next();
|
|
84
|
+
this.skipSpaces();
|
|
85
|
+
if (this.peek() === "]") {
|
|
86
|
+
throw new Error("Empty argument in callable typification");
|
|
87
|
+
}
|
|
88
|
+
continue;
|
|
89
|
+
}
|
|
90
|
+
break;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
this.expect("]");
|
|
94
|
+
this.skipSpaces();
|
|
95
|
+
this.expect("\u2192");
|
|
96
|
+
const result = this.parseCallableResult();
|
|
97
|
+
if (result.typeID === TypeID.logic) {
|
|
98
|
+
return {
|
|
99
|
+
typeID: TypeID.predicate,
|
|
100
|
+
result: LogicT,
|
|
101
|
+
args: args.map((arg, index) => ({ alias: `a${index + 1}`, type: arg }))
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
if (!isTypification(result)) {
|
|
105
|
+
throw new Error("Invalid callable result type");
|
|
106
|
+
}
|
|
107
|
+
return {
|
|
108
|
+
typeID: TypeID.function,
|
|
109
|
+
result,
|
|
110
|
+
args: args.map((arg, index) => ({ alias: `a${index + 1}`, type: arg }))
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
parseCallableResult() {
|
|
114
|
+
this.skipSpaces();
|
|
115
|
+
const lookahead = this.readToken();
|
|
116
|
+
this.index -= lookahead.length;
|
|
117
|
+
if (lookahead === "Logic") {
|
|
118
|
+
this.index += lookahead.length;
|
|
119
|
+
return LogicT;
|
|
120
|
+
}
|
|
121
|
+
return this.parseTypification();
|
|
122
|
+
}
|
|
123
|
+
parseTypification() {
|
|
124
|
+
this.skipSpaces();
|
|
125
|
+
if (this.match("\u212C")) {
|
|
126
|
+
this.skipSpaces();
|
|
127
|
+
if (this.peek() === "(") {
|
|
128
|
+
this.next();
|
|
129
|
+
const base = this.parseTypification();
|
|
130
|
+
this.expect(")");
|
|
131
|
+
return bool(base);
|
|
132
|
+
}
|
|
133
|
+
this.skipSpaces();
|
|
134
|
+
if (this.input.startsWith("\u212C", this.index)) {
|
|
135
|
+
const base = this.parseTypification();
|
|
136
|
+
return bool(base);
|
|
137
|
+
}
|
|
138
|
+
throw new Error('Expected "(" after "\u212C"');
|
|
139
|
+
}
|
|
140
|
+
const first = this.parseTypificationAtom();
|
|
141
|
+
const factors = [first];
|
|
142
|
+
while (true) {
|
|
143
|
+
this.skipSpaces();
|
|
144
|
+
if (!this.match("\xD7")) {
|
|
145
|
+
break;
|
|
146
|
+
}
|
|
147
|
+
factors.push(this.parseTypificationAtom());
|
|
148
|
+
}
|
|
149
|
+
if (factors.length === 1) {
|
|
150
|
+
return first;
|
|
151
|
+
}
|
|
152
|
+
return tuple(factors);
|
|
153
|
+
}
|
|
154
|
+
parseTypificationAtom() {
|
|
155
|
+
this.skipSpaces();
|
|
156
|
+
if (this.input.startsWith("\u212C", this.index)) {
|
|
157
|
+
return this.parseTypification();
|
|
158
|
+
}
|
|
159
|
+
if (this.peek() === "(") {
|
|
160
|
+
this.next();
|
|
161
|
+
const wrapped = this.parseTypification();
|
|
162
|
+
this.expect(")");
|
|
163
|
+
return wrapped;
|
|
164
|
+
}
|
|
165
|
+
const token = this.readToken();
|
|
166
|
+
if (token === "Z") {
|
|
167
|
+
return IntegerT;
|
|
168
|
+
}
|
|
169
|
+
if (token === "R0") {
|
|
170
|
+
return { typeID: TypeID.anyTypification };
|
|
171
|
+
}
|
|
172
|
+
if (!/^[A-Z]\d+$/.test(token)) {
|
|
173
|
+
throw new Error(`Unknown typification token "${token}"`);
|
|
174
|
+
}
|
|
175
|
+
return { typeID: TypeID.basic, baseID: token };
|
|
176
|
+
}
|
|
177
|
+
readToken() {
|
|
178
|
+
this.skipSpaces();
|
|
179
|
+
const start = this.index;
|
|
180
|
+
while (!this.eof()) {
|
|
181
|
+
const char = this.peek();
|
|
182
|
+
if (!char || /[\s,()[\]→×]/.test(char)) {
|
|
183
|
+
break;
|
|
184
|
+
}
|
|
185
|
+
this.next();
|
|
186
|
+
}
|
|
187
|
+
if (start === this.index) {
|
|
188
|
+
throw new Error("Expected typification token");
|
|
189
|
+
}
|
|
190
|
+
return this.input.slice(start, this.index);
|
|
191
|
+
}
|
|
192
|
+
skipSpaces() {
|
|
193
|
+
while (!this.eof() && /\s/.test(this.peek())) {
|
|
194
|
+
this.index += 1;
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
expect(symbol) {
|
|
198
|
+
this.skipSpaces();
|
|
199
|
+
if (!this.match(symbol)) {
|
|
200
|
+
throw new Error(`Expected "${symbol}"`);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
match(symbol) {
|
|
204
|
+
if (this.input.startsWith(symbol, this.index)) {
|
|
205
|
+
this.index += symbol.length;
|
|
206
|
+
return true;
|
|
207
|
+
}
|
|
208
|
+
return false;
|
|
209
|
+
}
|
|
210
|
+
peek() {
|
|
211
|
+
return this.input[this.index];
|
|
212
|
+
}
|
|
213
|
+
next() {
|
|
214
|
+
const value = this.input[this.index];
|
|
215
|
+
this.index += 1;
|
|
216
|
+
return value;
|
|
217
|
+
}
|
|
218
|
+
eof() {
|
|
219
|
+
return this.index >= this.input.length;
|
|
220
|
+
}
|
|
221
|
+
};
|
|
222
|
+
export {
|
|
223
|
+
applyAsciiTypeSubstitutions,
|
|
224
|
+
parseTypeText
|
|
225
|
+
};
|
|
226
|
+
//# sourceMappingURL=typification-parser.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/rslang/semantic/typification.ts","../../../src/rslang/semantic/typification-parser.ts"],"sourcesContent":["/*\n * Module: Typification for RSLang.\n */\n\nimport { type Branded } from '../../shared';\n\n/** Typification structure enumeration. */\nexport const TypeID = {\n anyTypification: 1,\n integer: 2,\n basic: 3,\n tuple: 4,\n collection: 5,\n logic: 6,\n function: 7,\n predicate: 8\n} as const;\nexport type TypeID = (typeof TypeID)[keyof typeof TypeID];\n\n/** Represents type class. */\nexport const TypeClass = {\n logic: 1,\n typification: 2,\n function: 3,\n predicate: 4\n} as const;\nexport type TypeClass = (typeof TypeClass)[keyof typeof TypeClass];\n\n/** Logic type object. */\nexport const LogicT = { typeID: TypeID.logic } as const;\n\n/** Integer type object. */\nexport const IntegerT = {\n typeID: TypeID.integer,\n isOrdered: true,\n isArithmetic: true,\n isIntegerCompatible: true\n} as const;\n\n/** Type transformation path. */\nexport type TypePath = Branded<number[], 'TypePath'>;\n\n/** Creates type path. */\nexport function makeTypePath(path: number[]): TypePath {\n return path as TypePath;\n}\n\n/** AnyTyped type object. */\nexport const AnyTypificationT = { typeID: TypeID.anyTypification } as const;\n\n/** Empty set typification. */\nexport const EmptySetT = bool(AnyTypificationT);\n\n/** Parametrized typification. */\nexport type Parametrized = EchelonFunctional | EchelonPredicate;\n\n/** General expression types. */\nexport type ExpressionType =\n | EchelonLogic\n | EchelonBase\n | EchelonTuple\n | EchelonCollection\n | EchelonFunctional\n | EchelonPredicate\n | EchelonAnyTyped\n | EchelonInteger;\n\n/** Setexpr type. */\nexport type Typification = EchelonBase | EchelonAnyTyped | EchelonInteger | EchelonCollection | EchelonTuple;\n\n/** Typification context. */\nexport type TypeContext = Map<string, ExpressionType>;\n\n/** Functional argument. */\nexport interface Argument {\n readonly alias: string;\n readonly type: Typification;\n}\n\n/** Type: Logic. */\nexport interface EchelonLogic {\n readonly typeID: typeof TypeID.logic;\n}\n\n/** Type: AnyTyped. */\nexport interface EchelonAnyTyped {\n readonly typeID: typeof TypeID.anyTypification;\n}\n\n/** Type: Integer. */\nexport interface EchelonInteger {\n readonly typeID: typeof TypeID.integer;\n readonly isOrdered: true;\n readonly isArithmetic: true;\n readonly isIntegerCompatible: true;\n}\n\n/** Type: Element of basic set. */\nexport interface EchelonBase {\n readonly typeID: typeof TypeID.basic;\n readonly baseID: string;\n readonly isOrdered?: boolean;\n readonly isArithmetic?: boolean;\n readonly isIntegerCompatible?: boolean;\n}\n\n/** Type: Tuple. */\nexport interface EchelonTuple {\n readonly typeID: typeof TypeID.tuple;\n readonly factors: readonly Typification[];\n}\n\n/** Type: Collection. */\nexport interface EchelonCollection {\n readonly typeID: typeof TypeID.collection;\n readonly base: Typification;\n}\n\n/** Type: Functional. */\nexport interface EchelonFunctional {\n readonly typeID: typeof TypeID.function;\n readonly result: Typification;\n readonly args: readonly Argument[];\n}\n\n/** Type: Predicate. */\nexport interface EchelonPredicate {\n readonly typeID: typeof TypeID.predicate;\n readonly result: EchelonLogic;\n readonly args: readonly Argument[];\n}\n\n/** Create basic element typification. */\nexport function basic(alias: string): EchelonBase {\n return { typeID: TypeID.basic, baseID: alias };\n}\n\n/** Create constant element typification. */\nexport function constant(alias: string): EchelonBase {\n return { typeID: TypeID.basic, baseID: alias, isOrdered: true, isArithmetic: true, isIntegerCompatible: true };\n}\n\n/** Create boolean typification. */\nexport function bool(base: Typification): EchelonCollection {\n return { typeID: TypeID.collection, base };\n}\n\n/** Create tuple typification. */\nexport function tuple(factors: Typification[]): EchelonTuple {\n if (factors.length < 2) {\n throw new Error('Tuple with less than two factors is not allowed');\n }\n return { typeID: TypeID.tuple, factors };\n}\n\n/** Remove boolean from typification. */\nexport function debool(target: EchelonCollection): Typification {\n return target.base;\n}\n\n/** Extract component from tuple. */\nexport function component(target: EchelonTuple, index: number): Typification | null {\n return target.factors[index - 1] ?? null;\n}\n\n/** Checks if given type is typification. */\nexport function isTypification(type: ExpressionType | null): boolean {\n return (\n type?.typeID === TypeID.basic ||\n type?.typeID === TypeID.anyTypification ||\n type?.typeID === TypeID.integer ||\n type?.typeID === TypeID.collection ||\n type?.typeID === TypeID.tuple\n );\n}\n\n/** Checks if given type is radical. */\nexport function isRadical(alias: string): boolean {\n return alias.length > 0 && alias.startsWith('R') && alias[1] !== '0';\n}\n","import {\n bool,\n type ExpressionType,\n IntegerT,\n isTypification,\n LogicT,\n tuple,\n TypeID,\n type Typification\n} from './typification';\n\nexport interface TypificationParseResult {\n type: ExpressionType | null;\n error: string | null;\n}\n\nexport function parseTypeText(input: string): TypificationParseResult {\n const normalized = input.trim().replaceAll('->', '→');\n if (normalized.length === 0) {\n return { type: null, error: null };\n }\n const parser = new TypificationParser(normalized);\n return parser.parse();\n}\n\n/** ASCII substitutions while editing typification text */\nexport function applyAsciiTypeSubstitutions(raw: string): string {\n return raw.replaceAll('->', '→').replaceAll('*', '×').replaceAll('B', 'ℬ');\n}\n\nclass TypificationParser {\n private index = 0;\n private input: string;\n\n constructor(input: string) {\n this.index = 0;\n this.input = input;\n }\n\n parse(): TypificationParseResult {\n try {\n const result = this.parseExpressionType();\n this.skipSpaces();\n if (!this.eof()) {\n throw new Error('Unexpected trailing symbols');\n }\n return { type: result, error: null };\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error);\n return { type: null, error: message };\n }\n }\n\n private parseExpressionType(): ExpressionType {\n this.skipSpaces();\n if (this.peek() === '[') {\n return this.parseCallableType();\n } else {\n return this.parseTypification();\n }\n }\n\n private parseCallableType(): ExpressionType {\n this.expect('[');\n const args: Typification[] = [];\n this.skipSpaces();\n if (this.peek() !== ']') {\n while (true) {\n args.push(this.parseTypification());\n this.skipSpaces();\n if (this.peek() === ',') {\n this.next();\n this.skipSpaces();\n if (this.peek() === ']') {\n throw new Error('Empty argument in callable typification');\n }\n continue;\n }\n break;\n }\n }\n this.expect(']');\n this.skipSpaces();\n this.expect('→');\n const result = this.parseCallableResult();\n if (result.typeID === TypeID.logic) {\n return {\n typeID: TypeID.predicate,\n result: LogicT,\n args: args.map((arg, index) => ({ alias: `a${index + 1}`, type: arg }))\n };\n }\n if (!isTypification(result)) {\n throw new Error('Invalid callable result type');\n }\n return {\n typeID: TypeID.function,\n result: result as Typification,\n args: args.map((arg, index) => ({ alias: `a${index + 1}`, type: arg }))\n };\n }\n\n private parseCallableResult(): ExpressionType {\n this.skipSpaces();\n const lookahead = this.readToken();\n this.index -= lookahead.length;\n if (lookahead === 'Logic') {\n this.index += lookahead.length;\n return LogicT;\n }\n return this.parseTypification();\n }\n\n private parseTypification(): Typification {\n this.skipSpaces();\n if (this.match('ℬ')) {\n this.skipSpaces();\n if (this.peek() === '(') {\n this.next();\n const base = this.parseTypification();\n this.expect(')');\n return bool(base);\n }\n this.skipSpaces();\n if (this.input.startsWith('ℬ', this.index)) {\n const base = this.parseTypification();\n return bool(base);\n }\n throw new Error('Expected \"(\" after \"ℬ\"');\n }\n const first = this.parseTypificationAtom();\n const factors: Typification[] = [first];\n while (true) {\n this.skipSpaces();\n if (!this.match('×')) {\n break;\n }\n factors.push(this.parseTypificationAtom());\n }\n if (factors.length === 1) {\n return first;\n }\n return tuple(factors);\n }\n\n private parseTypificationAtom(): Typification {\n this.skipSpaces();\n if (this.input.startsWith('ℬ', this.index)) {\n return this.parseTypification();\n }\n if (this.peek() === '(') {\n this.next();\n const wrapped = this.parseTypification();\n this.expect(')');\n return wrapped;\n }\n const token = this.readToken();\n if (token === 'Z') {\n return IntegerT;\n }\n if (token === 'R0') {\n return { typeID: TypeID.anyTypification };\n }\n if (!/^[A-Z]\\d+$/.test(token)) {\n throw new Error(`Unknown typification token \"${token}\"`);\n }\n return { typeID: TypeID.basic, baseID: token };\n }\n\n private readToken(): string {\n this.skipSpaces();\n const start = this.index;\n while (!this.eof()) {\n const char = this.peek();\n if (!char || /[\\s,()[\\]→×]/.test(char)) {\n break;\n }\n this.next();\n }\n if (start === this.index) {\n throw new Error('Expected typification token');\n }\n return this.input.slice(start, this.index);\n }\n\n private skipSpaces(): void {\n while (!this.eof() && /\\s/.test(this.peek()!)) {\n this.index += 1;\n }\n }\n\n private expect(symbol: string): void {\n this.skipSpaces();\n if (!this.match(symbol)) {\n throw new Error(`Expected \"${symbol}\"`);\n }\n }\n\n private match(symbol: string): boolean {\n if (this.input.startsWith(symbol, this.index)) {\n this.index += symbol.length;\n return true;\n }\n return false;\n }\n\n private peek(): string | undefined {\n return this.input[this.index];\n }\n\n private next(): string | undefined {\n const value = this.input[this.index];\n this.index += 1;\n return value;\n }\n\n private eof(): boolean {\n return this.index >= this.input.length;\n }\n}\n"],"mappings":";AAOO,IAAM,SAAS;AAAA,EACpB,iBAAiB;AAAA,EACjB,SAAS;AAAA,EACT,OAAO;AAAA,EACP,OAAO;AAAA,EACP,YAAY;AAAA,EACZ,OAAO;AAAA,EACP,UAAU;AAAA,EACV,WAAW;AACb;AAaO,IAAM,SAAS,EAAE,QAAQ,OAAO,MAAM;AAGtC,IAAM,WAAW;AAAA,EACt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AM,KAAK,KAAK;AACnC,SAAK,SAAS;AACd,WAAO;AAAA,EACT;AAAA,EAEQ,MAAe;AACrB,WAAO,KAAK,SAAS,KAAK,MAAM;AAAA,EAClC;AACF;","names":[]}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { Branded } from '../../shared/branded.js';
|
|
2
|
+
|
|
3
|
+
/** Typification structure enumeration. */
|
|
4
|
+
declare const TypeID: {
|
|
5
|
+
readonly anyTypification: 1;
|
|
6
|
+
readonly integer: 2;
|
|
7
|
+
readonly basic: 3;
|
|
8
|
+
readonly tuple: 4;
|
|
9
|
+
readonly collection: 5;
|
|
10
|
+
readonly logic: 6;
|
|
11
|
+
readonly function: 7;
|
|
12
|
+
readonly predicate: 8;
|
|
13
|
+
};
|
|
14
|
+
type TypeID = (typeof TypeID)[keyof typeof TypeID];
|
|
15
|
+
/** Represents type class. */
|
|
16
|
+
declare const TypeClass: {
|
|
17
|
+
readonly logic: 1;
|
|
18
|
+
readonly typification: 2;
|
|
19
|
+
readonly function: 3;
|
|
20
|
+
readonly predicate: 4;
|
|
21
|
+
};
|
|
22
|
+
type TypeClass = (typeof TypeClass)[keyof typeof TypeClass];
|
|
23
|
+
/** Logic type object. */
|
|
24
|
+
declare const LogicT: {
|
|
25
|
+
readonly typeID: 6;
|
|
26
|
+
};
|
|
27
|
+
/** Integer type object. */
|
|
28
|
+
declare const IntegerT: {
|
|
29
|
+
readonly typeID: 2;
|
|
30
|
+
readonly isOrdered: true;
|
|
31
|
+
readonly isArithmetic: true;
|
|
32
|
+
readonly isIntegerCompatible: true;
|
|
33
|
+
};
|
|
34
|
+
/** Type transformation path. */
|
|
35
|
+
type TypePath = Branded<number[], 'TypePath'>;
|
|
36
|
+
/** Creates type path. */
|
|
37
|
+
declare function makeTypePath(path: number[]): TypePath;
|
|
38
|
+
/** AnyTyped type object. */
|
|
39
|
+
declare const AnyTypificationT: {
|
|
40
|
+
readonly typeID: 1;
|
|
41
|
+
};
|
|
42
|
+
/** Empty set typification. */
|
|
43
|
+
declare const EmptySetT: EchelonCollection;
|
|
44
|
+
/** Parametrized typification. */
|
|
45
|
+
type Parametrized = EchelonFunctional | EchelonPredicate;
|
|
46
|
+
/** General expression types. */
|
|
47
|
+
type ExpressionType = EchelonLogic | EchelonBase | EchelonTuple | EchelonCollection | EchelonFunctional | EchelonPredicate | EchelonAnyTyped | EchelonInteger;
|
|
48
|
+
/** Setexpr type. */
|
|
49
|
+
type Typification = EchelonBase | EchelonAnyTyped | EchelonInteger | EchelonCollection | EchelonTuple;
|
|
50
|
+
/** Typification context. */
|
|
51
|
+
type TypeContext = Map<string, ExpressionType>;
|
|
52
|
+
/** Functional argument. */
|
|
53
|
+
interface Argument {
|
|
54
|
+
readonly alias: string;
|
|
55
|
+
readonly type: Typification;
|
|
56
|
+
}
|
|
57
|
+
/** Type: Logic. */
|
|
58
|
+
interface EchelonLogic {
|
|
59
|
+
readonly typeID: typeof TypeID.logic;
|
|
60
|
+
}
|
|
61
|
+
/** Type: AnyTyped. */
|
|
62
|
+
interface EchelonAnyTyped {
|
|
63
|
+
readonly typeID: typeof TypeID.anyTypification;
|
|
64
|
+
}
|
|
65
|
+
/** Type: Integer. */
|
|
66
|
+
interface EchelonInteger {
|
|
67
|
+
readonly typeID: typeof TypeID.integer;
|
|
68
|
+
readonly isOrdered: true;
|
|
69
|
+
readonly isArithmetic: true;
|
|
70
|
+
readonly isIntegerCompatible: true;
|
|
71
|
+
}
|
|
72
|
+
/** Type: Element of basic set. */
|
|
73
|
+
interface EchelonBase {
|
|
74
|
+
readonly typeID: typeof TypeID.basic;
|
|
75
|
+
readonly baseID: string;
|
|
76
|
+
readonly isOrdered?: boolean;
|
|
77
|
+
readonly isArithmetic?: boolean;
|
|
78
|
+
readonly isIntegerCompatible?: boolean;
|
|
79
|
+
}
|
|
80
|
+
/** Type: Tuple. */
|
|
81
|
+
interface EchelonTuple {
|
|
82
|
+
readonly typeID: typeof TypeID.tuple;
|
|
83
|
+
readonly factors: readonly Typification[];
|
|
84
|
+
}
|
|
85
|
+
/** Type: Collection. */
|
|
86
|
+
interface EchelonCollection {
|
|
87
|
+
readonly typeID: typeof TypeID.collection;
|
|
88
|
+
readonly base: Typification;
|
|
89
|
+
}
|
|
90
|
+
/** Type: Functional. */
|
|
91
|
+
interface EchelonFunctional {
|
|
92
|
+
readonly typeID: typeof TypeID.function;
|
|
93
|
+
readonly result: Typification;
|
|
94
|
+
readonly args: readonly Argument[];
|
|
95
|
+
}
|
|
96
|
+
/** Type: Predicate. */
|
|
97
|
+
interface EchelonPredicate {
|
|
98
|
+
readonly typeID: typeof TypeID.predicate;
|
|
99
|
+
readonly result: EchelonLogic;
|
|
100
|
+
readonly args: readonly Argument[];
|
|
101
|
+
}
|
|
102
|
+
/** Create basic element typification. */
|
|
103
|
+
declare function basic(alias: string): EchelonBase;
|
|
104
|
+
/** Create constant element typification. */
|
|
105
|
+
declare function constant(alias: string): EchelonBase;
|
|
106
|
+
/** Create boolean typification. */
|
|
107
|
+
declare function bool(base: Typification): EchelonCollection;
|
|
108
|
+
/** Create tuple typification. */
|
|
109
|
+
declare function tuple(factors: Typification[]): EchelonTuple;
|
|
110
|
+
/** Remove boolean from typification. */
|
|
111
|
+
declare function debool(target: EchelonCollection): Typification;
|
|
112
|
+
/** Extract component from tuple. */
|
|
113
|
+
declare function component(target: EchelonTuple, index: number): Typification | null;
|
|
114
|
+
/** Checks if given type is typification. */
|
|
115
|
+
declare function isTypification(type: ExpressionType | null): boolean;
|
|
116
|
+
/** Checks if given type is radical. */
|
|
117
|
+
declare function isRadical(alias: string): boolean;
|
|
118
|
+
|
|
119
|
+
export { AnyTypificationT, type Argument, type EchelonAnyTyped, type EchelonBase, type EchelonCollection, type EchelonFunctional, type EchelonInteger, type EchelonLogic, type EchelonPredicate, type EchelonTuple, EmptySetT, type ExpressionType, IntegerT, LogicT, type Parametrized, TypeClass, type TypeContext, TypeID, type TypePath, type Typification, basic, bool, component, constant, debool, isRadical, isTypification, makeTypePath, tuple };
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
// src/rslang/semantic/typification.ts
|
|
2
|
+
var TypeID = {
|
|
3
|
+
anyTypification: 1,
|
|
4
|
+
integer: 2,
|
|
5
|
+
basic: 3,
|
|
6
|
+
tuple: 4,
|
|
7
|
+
collection: 5,
|
|
8
|
+
logic: 6,
|
|
9
|
+
function: 7,
|
|
10
|
+
predicate: 8
|
|
11
|
+
};
|
|
12
|
+
var TypeClass = {
|
|
13
|
+
logic: 1,
|
|
14
|
+
typification: 2,
|
|
15
|
+
function: 3,
|
|
16
|
+
predicate: 4
|
|
17
|
+
};
|
|
18
|
+
var LogicT = { typeID: TypeID.logic };
|
|
19
|
+
var IntegerT = {
|
|
20
|
+
typeID: TypeID.integer,
|
|
21
|
+
isOrdered: true,
|
|
22
|
+
isArithmetic: true,
|
|
23
|
+
isIntegerCompatible: true
|
|
24
|
+
};
|
|
25
|
+
function makeTypePath(path) {
|
|
26
|
+
return path;
|
|
27
|
+
}
|
|
28
|
+
var AnyTypificationT = { typeID: TypeID.anyTypification };
|
|
29
|
+
var EmptySetT = bool(AnyTypificationT);
|
|
30
|
+
function basic(alias) {
|
|
31
|
+
return { typeID: TypeID.basic, baseID: alias };
|
|
32
|
+
}
|
|
33
|
+
function constant(alias) {
|
|
34
|
+
return { typeID: TypeID.basic, baseID: alias, isOrdered: true, isArithmetic: true, isIntegerCompatible: true };
|
|
35
|
+
}
|
|
36
|
+
function bool(base) {
|
|
37
|
+
return { typeID: TypeID.collection, base };
|
|
38
|
+
}
|
|
39
|
+
function tuple(factors) {
|
|
40
|
+
if (factors.length < 2) {
|
|
41
|
+
throw new Error("Tuple with less than two factors is not allowed");
|
|
42
|
+
}
|
|
43
|
+
return { typeID: TypeID.tuple, factors };
|
|
44
|
+
}
|
|
45
|
+
function debool(target) {
|
|
46
|
+
return target.base;
|
|
47
|
+
}
|
|
48
|
+
function component(target, index) {
|
|
49
|
+
return target.factors[index - 1] ?? null;
|
|
50
|
+
}
|
|
51
|
+
function isTypification(type) {
|
|
52
|
+
return type?.typeID === TypeID.basic || type?.typeID === TypeID.anyTypification || type?.typeID === TypeID.integer || type?.typeID === TypeID.collection || type?.typeID === TypeID.tuple;
|
|
53
|
+
}
|
|
54
|
+
function isRadical(alias) {
|
|
55
|
+
return alias.length > 0 && alias.startsWith("R") && alias[1] !== "0";
|
|
56
|
+
}
|
|
57
|
+
export {
|
|
58
|
+
AnyTypificationT,
|
|
59
|
+
EmptySetT,
|
|
60
|
+
IntegerT,
|
|
61
|
+
LogicT,
|
|
62
|
+
TypeClass,
|
|
63
|
+
TypeID,
|
|
64
|
+
basic,
|
|
65
|
+
bool,
|
|
66
|
+
component,
|
|
67
|
+
constant,
|
|
68
|
+
debool,
|
|
69
|
+
isRadical,
|
|
70
|
+
isTypification,
|
|
71
|
+
makeTypePath,
|
|
72
|
+
tuple
|
|
73
|
+
};
|
|
74
|
+
//# sourceMappingURL=typification.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/rslang/semantic/typification.ts"],"sourcesContent":["/*\n * Module: Typification for RSLang.\n */\n\nimport { type Branded } from '../../shared';\n\n/** Typification structure enumeration. */\nexport const TypeID = {\n anyTypification: 1,\n integer: 2,\n basic: 3,\n tuple: 4,\n collection: 5,\n logic: 6,\n function: 7,\n predicate: 8\n} as const;\nexport type TypeID = (typeof TypeID)[keyof typeof TypeID];\n\n/** Represents type class. */\nexport const TypeClass = {\n logic: 1,\n typification: 2,\n function: 3,\n predicate: 4\n} as const;\nexport type TypeClass = (typeof TypeClass)[keyof typeof TypeClass];\n\n/** Logic type object. */\nexport const LogicT = { typeID: TypeID.logic } as const;\n\n/** Integer type object. */\nexport const IntegerT = {\n typeID: TypeID.integer,\n isOrdered: true,\n isArithmetic: true,\n isIntegerCompatible: true\n} as const;\n\n/** Type transformation path. */\nexport type TypePath = Branded<number[], 'TypePath'>;\n\n/** Creates type path. */\nexport function makeTypePath(path: number[]): TypePath {\n return path as TypePath;\n}\n\n/** AnyTyped type object. */\nexport const AnyTypificationT = { typeID: TypeID.anyTypification } as const;\n\n/** Empty set typification. */\nexport const EmptySetT = bool(AnyTypificationT);\n\n/** Parametrized typification. */\nexport type Parametrized = EchelonFunctional | EchelonPredicate;\n\n/** General expression types. */\nexport type ExpressionType =\n | EchelonLogic\n | EchelonBase\n | EchelonTuple\n | EchelonCollection\n | EchelonFunctional\n | EchelonPredicate\n | EchelonAnyTyped\n | EchelonInteger;\n\n/** Setexpr type. */\nexport type Typification = EchelonBase | EchelonAnyTyped | EchelonInteger | EchelonCollection | EchelonTuple;\n\n/** Typification context. */\nexport type TypeContext = Map<string, ExpressionType>;\n\n/** Functional argument. */\nexport interface Argument {\n readonly alias: string;\n readonly type: Typification;\n}\n\n/** Type: Logic. */\nexport interface EchelonLogic {\n readonly typeID: typeof TypeID.logic;\n}\n\n/** Type: AnyTyped. */\nexport interface EchelonAnyTyped {\n readonly typeID: typeof TypeID.anyTypification;\n}\n\n/** Type: Integer. */\nexport interface EchelonInteger {\n readonly typeID: typeof TypeID.integer;\n readonly isOrdered: true;\n readonly isArithmetic: true;\n readonly isIntegerCompatible: true;\n}\n\n/** Type: Element of basic set. */\nexport interface EchelonBase {\n readonly typeID: typeof TypeID.basic;\n readonly baseID: string;\n readonly isOrdered?: boolean;\n readonly isArithmetic?: boolean;\n readonly isIntegerCompatible?: boolean;\n}\n\n/** Type: Tuple. */\nexport interface EchelonTuple {\n readonly typeID: typeof TypeID.tuple;\n readonly factors: readonly Typification[];\n}\n\n/** Type: Collection. */\nexport interface EchelonCollection {\n readonly typeID: typeof TypeID.collection;\n readonly base: Typification;\n}\n\n/** Type: Functional. */\nexport interface EchelonFunctional {\n readonly typeID: typeof TypeID.function;\n readonly result: Typification;\n readonly args: readonly Argument[];\n}\n\n/** Type: Predicate. */\nexport interface EchelonPredicate {\n readonly typeID: typeof TypeID.predicate;\n readonly result: EchelonLogic;\n readonly args: readonly Argument[];\n}\n\n/** Create basic element typification. */\nexport function basic(alias: string): EchelonBase {\n return { typeID: TypeID.basic, baseID: alias };\n}\n\n/** Create constant element typification. */\nexport function constant(alias: string): EchelonBase {\n return { typeID: TypeID.basic, baseID: alias, isOrdered: true, isArithmetic: true, isIntegerCompatible: true };\n}\n\n/** Create boolean typification. */\nexport function bool(base: Typification): EchelonCollection {\n return { typeID: TypeID.collection, base };\n}\n\n/** Create tuple typification. */\nexport function tuple(factors: Typification[]): EchelonTuple {\n if (factors.length < 2) {\n throw new Error('Tuple with less than two factors is not allowed');\n }\n return { typeID: TypeID.tuple, factors };\n}\n\n/** Remove boolean from typification. */\nexport function debool(target: EchelonCollection): Typification {\n return target.base;\n}\n\n/** Extract component from tuple. */\nexport function component(target: EchelonTuple, index: number): Typification | null {\n return target.factors[index - 1] ?? null;\n}\n\n/** Checks if given type is typification. */\nexport function isTypification(type: ExpressionType | null): boolean {\n return (\n type?.typeID === TypeID.basic ||\n type?.typeID === TypeID.anyTypification ||\n type?.typeID === TypeID.integer ||\n type?.typeID === TypeID.collection ||\n type?.typeID === TypeID.tuple\n );\n}\n\n/** Checks if given type is radical. */\nexport function isRadical(alias: string): boolean {\n return alias.length > 0 && alias.startsWith('R') && alias[1] !== '0';\n}\n"],"mappings":";AAOO,IAAM,SAAS;AAAA,EACpB,iBAAiB;AAAA,EACjB,SAAS;AAAA,EACT,OAAO;AAAA,EACP,OAAO;AAAA,EACP,YAAY;AAAA,EACZ,OAAO;AAAA,EACP,UAAU;AAAA,EACV,WAAW;AACb;AAIO,IAAM,YAAY;AAAA,EACvB,OAAO;AAAA,EACP,cAAc;AAAA,EACd,UAAU;AAAA,EACV,WAAW;AACb;AAIO,IAAM,SAAS,EAAE,QAAQ,OAAO,MAAM;AAGtC,IAAM,WAAW;AAAA,EACtB,QAAQ,OAAO;AAAA,EACf,WAAW;AAAA,EACX,cAAc;AAAA,EACd,qBAAqB;AACvB;AAMO,SAAS,aAAa,MAA0B;AACrD,SAAO;AACT;AAGO,IAAM,mBAAmB,EAAE,QAAQ,OAAO,gBAAgB;AAG1D,IAAM,YAAY,KAAK,gBAAgB;AAkFvC,SAAS,MAAM,OAA4B;AAChD,SAAO,EAAE,QAAQ,OAAO,OAAO,QAAQ,MAAM;AAC/C;AAGO,SAAS,SAAS,OAA4B;AACnD,SAAO,EAAE,QAAQ,OAAO,OAAO,QAAQ,OAAO,WAAW,MAAM,cAAc,MAAM,qBAAqB,KAAK;AAC/G;AAGO,SAAS,KAAK,MAAuC;AAC1D,SAAO,EAAE,QAAQ,OAAO,YAAY,KAAK;AAC3C;AAGO,SAAS,MAAM,SAAuC;AAC3D,MAAI,QAAQ,SAAS,GAAG;AACtB,UAAM,IAAI,MAAM,iDAAiD;AAAA,EACnE;AACA,SAAO,EAAE,QAAQ,OAAO,OAAO,QAAQ;AACzC;AAGO,SAAS,OAAO,QAAyC;AAC9D,SAAO,OAAO;AAChB;AAGO,SAAS,UAAU,QAAsB,OAAoC;AAClF,SAAO,OAAO,QAAQ,QAAQ,CAAC,KAAK;AACtC;AAGO,SAAS,eAAe,MAAsC;AACnE,SACE,MAAM,WAAW,OAAO,SACxB,MAAM,WAAW,OAAO,mBACxB,MAAM,WAAW,OAAO,WACxB,MAAM,WAAW,OAAO,cACxB,MAAM,WAAW,OAAO;AAE5B;AAGO,SAAS,UAAU,OAAwB;AAChD,SAAO,MAAM,SAAS,KAAK,MAAM,WAAW,GAAG,KAAK,MAAM,CAAC,MAAM;AACnE;","names":[]}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { AstNode } from '../../parsing/ast.js';
|
|
2
|
+
import { ErrorReporter } from '../error.js';
|
|
3
|
+
import { ValueClassContext, ValueClass } from './value-class.js';
|
|
4
|
+
import '@lezer/common';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Module: Value auditor for AST value class checking.
|
|
8
|
+
*
|
|
9
|
+
* Determines whether an expression yields a concrete value (computable)
|
|
10
|
+
* or a property (e.g., depends on a quantified variable).
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
/** Value auditor for AST value class checking. */
|
|
14
|
+
declare class ValueAuditor {
|
|
15
|
+
private context;
|
|
16
|
+
private annotateErrors;
|
|
17
|
+
private reporter?;
|
|
18
|
+
constructor(context: ValueClassContext);
|
|
19
|
+
/**
|
|
20
|
+
* Runs value audit on the AST. Returns the value class on success, null on failure.
|
|
21
|
+
*/
|
|
22
|
+
run(ast: AstNode, reporter?: ErrorReporter, annotateErrors?: boolean): ValueClass | null;
|
|
23
|
+
private dispatchVisit;
|
|
24
|
+
private onError;
|
|
25
|
+
private visitChild;
|
|
26
|
+
private visitAllAndReturn;
|
|
27
|
+
private assertChildIsValue;
|
|
28
|
+
private assertAllValues;
|
|
29
|
+
private visitFunctionDefinition;
|
|
30
|
+
private visitFunctionCall;
|
|
31
|
+
private visitGlobal;
|
|
32
|
+
private visitQuantifier;
|
|
33
|
+
private visitSetexprPredicate;
|
|
34
|
+
private visitDeclarative;
|
|
35
|
+
private visitImperative;
|
|
36
|
+
private visitIterateOrAssign;
|
|
37
|
+
private visitDecart;
|
|
38
|
+
private visitBoolean;
|
|
39
|
+
private visitFilter;
|
|
40
|
+
private visitSetexprBinary;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export { ValueAuditor };
|