@rsconcept/domain 1.0.0 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (185) hide show
  1. package/README.md +3 -3
  2. package/dist/analyzer-DlSq3Y3r.d.ts +39 -0
  3. package/dist/arguments-extractor-1acwjQNc.d.ts +38 -0
  4. package/dist/ast-C8sIpKdL.d.ts +51 -0
  5. package/dist/ast-annotations-BiMjkKvz.d.ts +16 -0
  6. package/dist/branded-ZlzIcxzu.d.ts +9 -0
  7. package/dist/calculator-C9W2jkSx.d.ts +39 -0
  8. package/dist/cctext/index.d.ts +2 -1
  9. package/dist/cctext/index.js +2 -42
  10. package/dist/cctext/language-api.d.ts +10 -12
  11. package/dist/cctext/language-api.js +157 -227
  12. package/dist/cctext/language-api.js.map +1 -1
  13. package/dist/cctext/language.d.ts +24 -22
  14. package/dist/cctext/language.js +43 -39
  15. package/dist/cctext/language.js.map +1 -1
  16. package/dist/error-E1LVq_3w.d.ts +87 -0
  17. package/dist/graph/graph.d.ts +2 -62
  18. package/dist/graph/graph.js +339 -382
  19. package/dist/graph/graph.js.map +1 -1
  20. package/dist/graph/index.d.ts +2 -1
  21. package/dist/graph/index.js +2 -384
  22. package/dist/graph-DR8rL2o3.d.ts +64 -0
  23. package/dist/hash-Y8I4c6Al.d.ts +8 -0
  24. package/dist/index-BKZ67WMa.d.ts +1 -0
  25. package/dist/index-BVVgDSdq.d.ts +1 -0
  26. package/dist/index-DmtQKWjk.d.ts +1 -0
  27. package/dist/index-_6s0AX1B.d.ts +1 -0
  28. package/dist/index.d.ts +27 -28
  29. package/dist/index.js +23 -5851
  30. package/dist/lezer-tree-iS7LpLBJ.d.ts +14 -0
  31. package/dist/library/folder-tree.d.ts +22 -20
  32. package/dist/library/folder-tree.js +108 -130
  33. package/dist/library/folder-tree.js.map +1 -1
  34. package/dist/library/index.d.ts +8 -17
  35. package/dist/library/index.js +7 -2800
  36. package/dist/library/library-api.d.ts +3 -1
  37. package/dist/library/library-api.js +9 -8
  38. package/dist/library/library-api.js.map +1 -1
  39. package/dist/library/library.d.ts +2 -56
  40. package/dist/library/library.js +23 -19
  41. package/dist/library/library.js.map +1 -1
  42. package/dist/library/oss-api.d.ts +26 -37
  43. package/dist/library/oss-api.js +258 -1096
  44. package/dist/library/oss-api.js.map +1 -1
  45. package/dist/library/oss-layout-api.d.ts +28 -28
  46. package/dist/library/oss-layout-api.js +239 -316
  47. package/dist/library/oss-layout-api.js.map +1 -1
  48. package/dist/library/oss-layout.d.ts +2 -25
  49. package/dist/library/oss-layout.js +1 -1
  50. package/dist/library/oss.d.ts +87 -89
  51. package/dist/library/oss.js +27 -26
  52. package/dist/library/oss.js.map +1 -1
  53. package/dist/library/rsengine.d.ts +100 -106
  54. package/dist/library/rsengine.js +439 -2599
  55. package/dist/library/rsengine.js.map +1 -1
  56. package/dist/library/rsform-api.d.ts +11 -16
  57. package/dist/library/rsform-api.js +313 -825
  58. package/dist/library/rsform-api.js.map +1 -1
  59. package/dist/library/rsform.d.ts +159 -167
  60. package/dist/library/rsform.js +29 -28
  61. package/dist/library/rsform.js.map +1 -1
  62. package/dist/library/rsmodel-api.d.ts +8 -15
  63. package/dist/library/rsmodel-api.js +172 -813
  64. package/dist/library/rsmodel-api.js.map +1 -1
  65. package/dist/library/rsmodel.d.ts +27 -33
  66. package/dist/library/rsmodel.js +16 -23
  67. package/dist/library/rsmodel.js.map +1 -1
  68. package/dist/library/structure-planner.d.ts +20 -26
  69. package/dist/library/structure-planner.js +106 -474
  70. package/dist/library/structure-planner.js.map +1 -1
  71. package/dist/library-CYun28Xz.d.ts +58 -0
  72. package/dist/oss-layout-3glgAqfn.d.ts +27 -0
  73. package/dist/parser-Bwd8LxJ1.d.ts +7 -0
  74. package/dist/parsing/ast.d.ts +2 -49
  75. package/dist/parsing/ast.js +68 -76
  76. package/dist/parsing/ast.js.map +1 -1
  77. package/dist/parsing/index.d.ts +3 -3
  78. package/dist/parsing/index.js +3 -141
  79. package/dist/parsing/lezer-tree.d.ts +2 -13
  80. package/dist/parsing/lezer-tree.js +50 -43
  81. package/dist/parsing/lezer-tree.js.map +1 -1
  82. package/dist/rslang/api.d.ts +9 -14
  83. package/dist/rslang/api.js +114 -827
  84. package/dist/rslang/api.js.map +1 -1
  85. package/dist/rslang/ast-annotations.d.ts +2 -18
  86. package/dist/rslang/ast-annotations.js +34 -45
  87. package/dist/rslang/ast-annotations.js.map +1 -1
  88. package/dist/rslang/error.d.ts +2 -85
  89. package/dist/rslang/error.js +88 -150
  90. package/dist/rslang/error.js.map +1 -1
  91. package/dist/rslang/eval/calculator.d.ts +2 -43
  92. package/dist/rslang/eval/calculator.js +81 -1636
  93. package/dist/rslang/eval/calculator.js.map +1 -1
  94. package/dist/rslang/eval/evaluation-cache.d.ts +22 -26
  95. package/dist/rslang/eval/evaluation-cache.js +168 -287
  96. package/dist/rslang/eval/evaluation-cache.js.map +1 -1
  97. package/dist/rslang/eval/evaluator.d.ts +59 -63
  98. package/dist/rslang/eval/evaluator.js +602 -1509
  99. package/dist/rslang/eval/evaluator.js.map +1 -1
  100. package/dist/rslang/eval/value-api.d.ts +2 -48
  101. package/dist/rslang/eval/value-api.js +2 -490
  102. package/dist/rslang/eval/value.d.ts +2 -36
  103. package/dist/rslang/eval/value.js +2 -118
  104. package/dist/rslang/index.d.ts +14 -17
  105. package/dist/rslang/index.js +12 -4314
  106. package/dist/rslang/labels.d.ts +6 -6
  107. package/dist/rslang/labels.js +139 -305
  108. package/dist/rslang/labels.js.map +1 -1
  109. package/dist/rslang/parser/expression-generator.d.ts +5 -5
  110. package/dist/rslang/parser/expression-generator.js +248 -446
  111. package/dist/rslang/parser/expression-generator.js.map +1 -1
  112. package/dist/rslang/parser/normalize.d.ts +4 -8
  113. package/dist/rslang/parser/normalize.js +286 -481
  114. package/dist/rslang/parser/normalize.js.map +1 -1
  115. package/dist/rslang/parser/parser.d.ts +2 -5
  116. package/dist/rslang/parser/parser.js +30 -21
  117. package/dist/rslang/parser/parser.js.map +1 -1
  118. package/dist/rslang/parser/parser.terms.d.ts +43 -41
  119. package/dist/rslang/parser/parser.terms.js +44 -83
  120. package/dist/rslang/parser/parser.terms.js.map +1 -1
  121. package/dist/rslang/parser/syntax-errors.d.ts +5 -8
  122. package/dist/rslang/parser/syntax-errors.js +113 -382
  123. package/dist/rslang/parser/syntax-errors.js.map +1 -1
  124. package/dist/rslang/parser/token.d.ts +2 -79
  125. package/dist/rslang/parser/token.js +81 -93
  126. package/dist/rslang/parser/token.js.map +1 -1
  127. package/dist/rslang/semantic/analyzer.d.ts +2 -39
  128. package/dist/rslang/semantic/analyzer.js +186 -2600
  129. package/dist/rslang/semantic/analyzer.js.map +1 -1
  130. package/dist/rslang/semantic/arguments-extractor.d.ts +2 -42
  131. package/dist/rslang/semantic/arguments-extractor.js +202 -361
  132. package/dist/rslang/semantic/arguments-extractor.js.map +1 -1
  133. package/dist/rslang/semantic/type-auditor.d.ts +64 -68
  134. package/dist/rslang/semantic/type-auditor.js +594 -1564
  135. package/dist/rslang/semantic/type-auditor.js.map +1 -1
  136. package/dist/rslang/semantic/typification-api.d.ts +4 -7
  137. package/dist/rslang/semantic/typification-api.js +162 -303
  138. package/dist/rslang/semantic/typification-api.js.map +1 -1
  139. package/dist/rslang/semantic/typification-parser.d.ts +2 -12
  140. package/dist/rslang/semantic/typification-parser.js +165 -219
  141. package/dist/rslang/semantic/typification-parser.js.map +1 -1
  142. package/dist/rslang/semantic/typification.d.ts +2 -119
  143. package/dist/rslang/semantic/typification.js +66 -52
  144. package/dist/rslang/semantic/typification.js.map +1 -1
  145. package/dist/rslang/semantic/value-auditor.d.ts +32 -38
  146. package/dist/rslang/semantic/value-auditor.js +206 -518
  147. package/dist/rslang/semantic/value-auditor.js.map +1 -1
  148. package/dist/rslang/semantic/value-class.d.ts +2 -10
  149. package/dist/rslang/semantic/value-class.js +8 -7
  150. package/dist/rslang/semantic/value-class.js.map +1 -1
  151. package/dist/rslang/typification-graph.d.ts +2 -33
  152. package/dist/rslang/typification-graph.js +94 -306
  153. package/dist/rslang/typification-graph.js.map +1 -1
  154. package/dist/shared/branded.d.ts +2 -7
  155. package/dist/shared/branded.js +1 -1
  156. package/dist/shared/hash.d.ts +2 -6
  157. package/dist/shared/hash.js +13 -13
  158. package/dist/shared/hash.js.map +1 -1
  159. package/dist/shared/index.d.ts +3 -2
  160. package/dist/shared/index.js +2 -18
  161. package/dist/token-DeXAmzwr.d.ts +81 -0
  162. package/dist/typification-Dk-fisgO.d.ts +120 -0
  163. package/dist/typification-graph-6HcZ-rKH.d.ts +30 -0
  164. package/dist/typification-parser-BBVx1RxP.d.ts +13 -0
  165. package/dist/value-B8UtCqaK.js +366 -0
  166. package/dist/value-B8UtCqaK.js.map +1 -0
  167. package/dist/value-CTjX6825.d.ts +33 -0
  168. package/dist/value-api-Bw-SgaYY.d.ts +49 -0
  169. package/dist/value-class-CNI-lqXJ.d.ts +12 -0
  170. package/package.json +8 -8
  171. package/src/library/oss-api.test.ts +76 -0
  172. package/src/library/oss-api.ts +4 -1
  173. package/src/library/rsform-api.test.ts +24 -0
  174. package/src/library/rsform-api.ts +12 -4
  175. package/dist/cctext/index.js.map +0 -1
  176. package/dist/graph/index.js.map +0 -1
  177. package/dist/index.js.map +0 -1
  178. package/dist/library/index.js.map +0 -1
  179. package/dist/library/oss-layout.js.map +0 -1
  180. package/dist/parsing/index.js.map +0 -1
  181. package/dist/rslang/eval/value-api.js.map +0 -1
  182. package/dist/rslang/eval/value.js.map +0 -1
  183. package/dist/rslang/index.js.map +0 -1
  184. package/dist/shared/branded.js.map +0 -1
  185. package/dist/shared/index.js.map +0 -1
@@ -1,226 +1,172 @@
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
1
+ import { IntegerT, LogicT, TypeID, bool, isTypification, tuple } from "./typification.js";
2
+ //#region src/rslang/semantic/typification-parser.ts
35
3
  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();
4
+ const normalized = input.trim().replaceAll("->", "");
5
+ if (normalized.length === 0) return {
6
+ type: null,
7
+ error: null
8
+ };
9
+ return new TypificationParser(normalized).parse();
42
10
  }
11
+ /** ASCII substitutions while editing typification text */
43
12
  function applyAsciiTypeSubstitutions(raw) {
44
- return raw.replaceAll("->", "\u2192").replaceAll("*", "\xD7").replaceAll("B", "\u212C");
13
+ return raw.replaceAll("->", "").replaceAll("*", "×").replaceAll("B", "");
45
14
  }
46
15
  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
16
+ index = 0;
17
+ input;
18
+ constructor(input) {
19
+ this.index = 0;
20
+ this.input = input;
21
+ }
22
+ parse() {
23
+ try {
24
+ const result = this.parseExpressionType();
25
+ this.skipSpaces();
26
+ if (!this.eof()) throw new Error("Unexpected trailing symbols");
27
+ return {
28
+ type: result,
29
+ error: null
30
+ };
31
+ } catch (error) {
32
+ return {
33
+ type: null,
34
+ error: error instanceof Error ? error.message : String(error)
35
+ };
36
+ }
37
+ }
38
+ parseExpressionType() {
39
+ this.skipSpaces();
40
+ if (this.peek() === "[") return this.parseCallableType();
41
+ else return this.parseTypification();
42
+ }
43
+ parseCallableType() {
44
+ this.expect("[");
45
+ const args = [];
46
+ this.skipSpaces();
47
+ if (this.peek() !== "]") while (true) {
48
+ args.push(this.parseTypification());
49
+ this.skipSpaces();
50
+ if (this.peek() === ",") {
51
+ this.next();
52
+ this.skipSpaces();
53
+ if (this.peek() === "]") throw new Error("Empty argument in callable typification");
54
+ continue;
55
+ }
56
+ break;
57
+ }
58
+ this.expect("]");
59
+ this.skipSpaces();
60
+ this.expect("→");
61
+ const result = this.parseCallableResult();
62
+ if (result.typeID === TypeID.logic) return {
63
+ typeID: TypeID.predicate,
64
+ result: LogicT,
65
+ args: args.map((arg, index) => ({
66
+ alias: `a${index + 1}`,
67
+ type: arg
68
+ }))
69
+ };
70
+ if (!isTypification(result)) throw new Error("Invalid callable result type");
71
+ return {
72
+ typeID: TypeID.function,
73
+ result,
74
+ args: args.map((arg, index) => ({
75
+ alias: `a${index + 1}`,
76
+ type: arg
77
+ }))
78
+ };
79
+ }
80
+ parseCallableResult() {
81
+ this.skipSpaces();
82
+ const lookahead = this.readToken();
83
+ this.index -= lookahead.length;
84
+ if (lookahead === "Logic") {
85
+ this.index += lookahead.length;
86
+ return LogicT;
87
+ }
88
+ return this.parseTypification();
89
+ }
90
+ parseTypification() {
91
+ this.skipSpaces();
92
+ if (this.match("ℬ")) {
93
+ this.skipSpaces();
94
+ if (this.peek() === "(") {
95
+ this.next();
96
+ const base = this.parseTypification();
97
+ this.expect(")");
98
+ return bool(base);
99
+ }
100
+ this.skipSpaces();
101
+ if (this.input.startsWith("ℬ", this.index)) return bool(this.parseTypification());
102
+ throw new Error("Expected \"(\" after \"ℬ\"");
103
+ }
104
+ const first = this.parseTypificationAtom();
105
+ const factors = [first];
106
+ while (true) {
107
+ this.skipSpaces();
108
+ if (!this.match("×")) break;
109
+ factors.push(this.parseTypificationAtom());
110
+ }
111
+ if (factors.length === 1) return first;
112
+ return tuple(factors);
113
+ }
114
+ parseTypificationAtom() {
115
+ this.skipSpaces();
116
+ if (this.input.startsWith("ℬ", this.index)) return this.parseTypification();
117
+ if (this.peek() === "(") {
118
+ this.next();
119
+ const wrapped = this.parseTypification();
120
+ this.expect(")");
121
+ return wrapped;
122
+ }
123
+ const token = this.readToken();
124
+ if (token === "Z") return IntegerT;
125
+ if (token === "R0") return { typeID: TypeID.anyTypification };
126
+ if (!/^[A-Z]\d+$/.test(token)) throw new Error(`Unknown typification token "${token}"`);
127
+ return {
128
+ typeID: TypeID.basic,
129
+ baseID: token
130
+ };
131
+ }
132
+ readToken() {
133
+ this.skipSpaces();
134
+ const start = this.index;
135
+ while (!this.eof()) {
136
+ const char = this.peek();
137
+ if (!char || /[\s,()[\]→×]/.test(char)) break;
138
+ this.next();
139
+ }
140
+ if (start === this.index) throw new Error("Expected typification token");
141
+ return this.input.slice(start, this.index);
142
+ }
143
+ skipSpaces() {
144
+ while (!this.eof() && /\s/.test(this.peek())) this.index += 1;
145
+ }
146
+ expect(symbol) {
147
+ this.skipSpaces();
148
+ if (!this.match(symbol)) throw new Error(`Expected "${symbol}"`);
149
+ }
150
+ match(symbol) {
151
+ if (this.input.startsWith(symbol, this.index)) {
152
+ this.index += symbol.length;
153
+ return true;
154
+ }
155
+ return false;
156
+ }
157
+ peek() {
158
+ return this.input[this.index];
159
+ }
160
+ next() {
161
+ const value = this.input[this.index];
162
+ this.index += 1;
163
+ return value;
164
+ }
165
+ eof() {
166
+ return this.index >= this.input.length;
167
+ }
225
168
  };
169
+ //#endregion
170
+ export { applyAsciiTypeSubstitutions, parseTypeText };
171
+
226
172
  //# sourceMappingURL=typification-parser.js.map
@@ -1 +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,EACtB,QAAQ,OAAO;AAAA,EACf,WAAW;AAAA,EACX,cAAc;AAAA,EACd,qBAAqB;AACvB;AAWO,IAAM,mBAAmB,EAAE,QAAQ,OAAO,gBAAgB;AAG1D,IAAM,YAAY,KAAK,gBAAgB;AA4FvC,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;AAaO,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;;;AC9JO,SAAS,cAAc,OAAwC;AACpE,QAAM,aAAa,MAAM,KAAK,EAAE,WAAW,MAAM,QAAG;AACpD,MAAI,WAAW,WAAW,GAAG;AAC3B,WAAO,EAAE,MAAM,MAAM,OAAO,KAAK;AAAA,EACnC;AACA,QAAM,SAAS,IAAI,mBAAmB,UAAU;AA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K,CAAE,GAAG;AAC7C,WAAK,SAAS;AAAA,IAChB;AAAA,EACF;AAAA,EAEQ,OAAO,QAAsB;AACnC,SAAK,WAAW;AAChB,QAAI,CAAC,KAAK,MAAM,MAAM,GAAG;AACvB,YAAM,IAAI,MAAM,aAAa,MAAM,GAAG;AAAA,IACxC;AAAA,EACF;AAAA,EAEQ,MAAM,QAAyB;AACrC,QAAI,KAAK,MAAM,WAAW,QAAQ,KAAK,KAAK,GAAG;AAC7C,WAAK,SAAS,OAAO;AACrB,aAAO;AAAA,IACT;AACA,WAAO;AAAA,EACT;AAAA,EAEQ,OAA2B;AACjC,WAAO,KAAK,MAAM,KAAK,KAAK;AAAA,EAC9B;AAAA,EAEQ,OAA2B;AACjC,UAAM,QAAQ,KAAK,MAAM,KAAK,KAAK;AACnC,SAAK,SAAS;AACd,WAAO;AAAA,EACT;AAAA,EAEQ,MAAe;AACrB,WAAO,KAAK,SAAS,KAAK,MAAM;AAAA,EAClC;AACF;","names":[]}
1
+ {"version":3,"file":"typification-parser.js","names":[],"sources":["../../../src/rslang/semantic/typification-parser.ts"],"sourcesContent":["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":";;AAgBA,SAAgB,cAAc,OAAwC;CACpE,MAAM,aAAa,MAAM,KAAK,CAAC,CAAC,WAAW,MAAM,GAAG;CACpD,IAAI,WAAW,WAAW,GACxB,OAAO;EAAE,MAAM;EAAM,OAAO;CAAK;CAGnC,OAAO,IADY,mBAAmB,UAC/B,CAAA,CAAO,MAAM;AACtB;;AAGA,SAAgB,4BAA4B,KAAqB;CAC/D,OAAO,IAAI,WAAW,MAAM,GAAG,CAAC,CAAC,WAAW,KAAK,GAAG,CAAC,CAAC,WAAW,KAAK,GAAG;AAC3E;AAEA,IAAM,qBAAN,MAAyB;CACvB,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,KAAK,KAAK,GAC1B,MAAM,IAAI,MAAM,+BAA+B,MAAM,EAAE;EAEzD,OAAO;GAAE,QAAQ,OAAO;GAAO,QAAQ;EAAM;CAC/C;CAEA,YAA4B;EAC1B,KAAK,WAAW;EAChB,MAAM,QAAQ,KAAK;EACnB,OAAO,CAAC,KAAK,IAAI,GAAG;GAClB,MAAM,OAAO,KAAK,KAAK;GACvB,IAAI,CAAC,QAAQ,eAAe,KAAK,IAAI,GACnC;GAEF,KAAK,KAAK;EACZ;EACA,IAAI,UAAU,KAAK,OACjB,MAAM,IAAI,MAAM,6BAA6B;EAE/C,OAAO,KAAK,MAAM,MAAM,OAAO,KAAK,KAAK;CAC3C;CAEA,aAA2B;EACzB,OAAO,CAAC,KAAK,IAAI,KAAK,KAAK,KAAK,KAAK,KAAK,CAAE,GAC1C,KAAK,SAAS;CAElB;CAEA,OAAe,QAAsB;EACnC,KAAK,WAAW;EAChB,IAAI,CAAC,KAAK,MAAM,MAAM,GACpB,MAAM,IAAI,MAAM,aAAa,OAAO,EAAE;CAE1C;CAEA,MAAc,QAAyB;EACrC,IAAI,KAAK,MAAM,WAAW,QAAQ,KAAK,KAAK,GAAG;GAC7C,KAAK,SAAS,OAAO;GACrB,OAAO;EACT;EACA,OAAO;CACT;CAEA,OAAmC;EACjC,OAAO,KAAK,MAAM,KAAK;CACzB;CAEA,OAAmC;EACjC,MAAM,QAAQ,KAAK,MAAM,KAAK;EAC9B,KAAK,SAAS;EACd,OAAO;CACT;CAEA,MAAuB;EACrB,OAAO,KAAK,SAAS,KAAK,MAAM;CAClC;AACF"}
@@ -1,119 +1,2 @@
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 };
1
+ import { C as component, D as isTypification, E as isRadical, O as makeTypePath, S as bool, T as debool, _ as TypeContext, a as EchelonCollection, b as Typification, c as EchelonLogic, d as EmptySetT, f as ExpressionType, g as TypeClass, h as Parametrized, i as EchelonBase, k as tuple, l as EchelonPredicate, m as LogicT, n as Argument, o as EchelonFunctional, p as IntegerT, r as EchelonAnyTyped, s as EchelonInteger, t as AnyTypificationT, u as EchelonTuple, v as TypeID, w as constant, x as basic, y as TypePath } from "../../typification-Dk-fisgO.js";
2
+ export { AnyTypificationT, Argument, EchelonAnyTyped, EchelonBase, EchelonCollection, EchelonFunctional, EchelonInteger, EchelonLogic, EchelonPredicate, EchelonTuple, EmptySetT, ExpressionType, IntegerT, LogicT, Parametrized, TypeClass, TypeContext, TypeID, TypePath, Typification, basic, bool, component, constant, debool, isRadical, isTypification, makeTypePath, tuple };