enyosx-ai 0.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/LICENSE +18 -0
- package/README.md +740 -0
- package/dist/chunk-2WM5L76D.js +320 -0
- package/dist/chunk-3BNDFBX3.js +324 -0
- package/dist/chunk-4LJILSCT.js +30 -0
- package/dist/chunk-4ZV5JV6W.js +298 -0
- package/dist/chunk-76PHNPTY.js +631 -0
- package/dist/chunk-BSSA33NY.js +677 -0
- package/dist/chunk-EK6IDRY7.js +105 -0
- package/dist/chunk-FI2EBH2N.js +2232 -0
- package/dist/chunk-GAKKLY4M.js +276 -0
- package/dist/chunk-HR4G5XQI.js +319 -0
- package/dist/chunk-HROGCEE5.js +30 -0
- package/dist/chunk-MMH7M7MG.js +30 -0
- package/dist/chunk-NGLRXS6G.js +2079 -0
- package/dist/chunk-NSE6LQJC.js +681 -0
- package/dist/chunk-O5XZOSBW.js +2484 -0
- package/dist/chunk-OVCMUPMP.js +677 -0
- package/dist/chunk-P2YBRE3X.js +2484 -0
- package/dist/chunk-VVIL5NIM.js +318 -0
- package/dist/chunk-ZNGEBY33.js +273 -0
- package/dist/cli.cjs +2509 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +99 -0
- package/dist/index.cjs +2912 -0
- package/dist/index.d.ts +672 -0
- package/dist/index.js +379 -0
- package/dist/parser-4JXKOWKY.js +8 -0
- package/dist/parser-UUB6D2CZ.js +8 -0
- package/dist/parser-V44AIVNI.js +8 -0
- package/examples/README.md +13 -0
- package/examples/ia-demo.eny +37 -0
- package/examples/sample.eny +15 -0
- package/examples/simple/system.eny +7 -0
- package/examples/spec/sample.eny +19 -0
- package/examples/starter/README.md +96 -0
- package/examples/starter/main.eny +39 -0
- package/examples/starter/run.js +68 -0
- package/examples/starter.eny +16 -0
- package/examples/wasm-demo.eny +34 -0
- package/package.json +49 -0
|
@@ -0,0 +1,2232 @@
|
|
|
1
|
+
// src/lexer/tokenize.ts
|
|
2
|
+
var TokenType = /* @__PURE__ */ ((TokenType2) => {
|
|
3
|
+
TokenType2["SYMBOL"] = "SYMBOL";
|
|
4
|
+
TokenType2["IDENTIFIER"] = "IDENTIFIER";
|
|
5
|
+
TokenType2["STRING"] = "STRING";
|
|
6
|
+
TokenType2["NUMBER"] = "NUMBER";
|
|
7
|
+
TokenType2["ARROW"] = "ARROW";
|
|
8
|
+
TokenType2["LBRACE"] = "LBRACE";
|
|
9
|
+
TokenType2["RBRACE"] = "RBRACE";
|
|
10
|
+
TokenType2["COLON"] = "COLON";
|
|
11
|
+
TokenType2["COMMA"] = "COMMA";
|
|
12
|
+
TokenType2["LPAREN"] = "LPAREN";
|
|
13
|
+
TokenType2["RPAREN"] = "RPAREN";
|
|
14
|
+
TokenType2["LBRACKET"] = "LBRACKET";
|
|
15
|
+
TokenType2["RBRACKET"] = "RBRACKET";
|
|
16
|
+
TokenType2["NEWLINE"] = "NEWLINE";
|
|
17
|
+
TokenType2["COMPARATOR"] = "COMPARATOR";
|
|
18
|
+
TokenType2["OPERATOR"] = "OPERATOR";
|
|
19
|
+
TokenType2["EOF"] = "EOF";
|
|
20
|
+
return TokenType2;
|
|
21
|
+
})(TokenType || {});
|
|
22
|
+
var SYMBOLS_STATE = /* @__PURE__ */ new Set([
|
|
23
|
+
"\u03A3",
|
|
24
|
+
// STATE - Estado global
|
|
25
|
+
"\u03C3",
|
|
26
|
+
// SUBSTATE - Estado local
|
|
27
|
+
"\xD8",
|
|
28
|
+
// VOID - Não-existência
|
|
29
|
+
"\u{1F512}",
|
|
30
|
+
// LOCK - Imutável
|
|
31
|
+
"\u{1F513}"
|
|
32
|
+
// UNLOCK - Mutável
|
|
33
|
+
]);
|
|
34
|
+
var SYMBOLS_EXEC = /* @__PURE__ */ new Set([
|
|
35
|
+
"\u0394",
|
|
36
|
+
// ACTION - Ação/função
|
|
37
|
+
"\u0192",
|
|
38
|
+
// FUNCTION - Capacidade lógica
|
|
39
|
+
"\u21C9",
|
|
40
|
+
// PARALLEL - Execução paralela
|
|
41
|
+
"\u25B3",
|
|
42
|
+
// DEPEND - Dependência
|
|
43
|
+
"\u25CF",
|
|
44
|
+
// CORE - Núcleo
|
|
45
|
+
"\u23F3"
|
|
46
|
+
// DELAY - Espera temporal
|
|
47
|
+
]);
|
|
48
|
+
var SYMBOLS_STRUCT = /* @__PURE__ */ new Set([
|
|
49
|
+
"\u03A9",
|
|
50
|
+
// OBJECT - Objeto
|
|
51
|
+
"\u25A0",
|
|
52
|
+
// OBJECT ALT - Entidade concreta
|
|
53
|
+
"\u25CB",
|
|
54
|
+
// CLASS - Classe/molde
|
|
55
|
+
"\u2B12",
|
|
56
|
+
// INHERIT - Herança
|
|
57
|
+
"\u2283",
|
|
58
|
+
// CONTAINS - Composição
|
|
59
|
+
"\u2254",
|
|
60
|
+
// ASSIGN - Atribuição
|
|
61
|
+
"\u29C9"
|
|
62
|
+
// MODULE - Módulo
|
|
63
|
+
]);
|
|
64
|
+
var SYMBOLS_TIME = /* @__PURE__ */ new Set([
|
|
65
|
+
"\u26A1",
|
|
66
|
+
// CAUSE - Causa/origem
|
|
67
|
+
"\u2726",
|
|
68
|
+
// CONSEQUENCE - Resultado
|
|
69
|
+
"\u21BB",
|
|
70
|
+
// LOOP - Repetição
|
|
71
|
+
"\u25CC",
|
|
72
|
+
// EVENT - Evento
|
|
73
|
+
"\u21C4",
|
|
74
|
+
// SYNC - Sincronização
|
|
75
|
+
"\u231B"
|
|
76
|
+
// TIMEOUT - Limite temporal
|
|
77
|
+
]);
|
|
78
|
+
var SYMBOLS_ENERGY = /* @__PURE__ */ new Set([
|
|
79
|
+
"\u03A8",
|
|
80
|
+
// ENERGY - Energia vital
|
|
81
|
+
"\u23EC",
|
|
82
|
+
// THROTTLE - Limitar
|
|
83
|
+
"\u23EB",
|
|
84
|
+
// BOOST - Acelerar
|
|
85
|
+
"\u20B5"
|
|
86
|
+
// COST - Custo
|
|
87
|
+
]);
|
|
88
|
+
var SYMBOLS_MEMORY = /* @__PURE__ */ new Set([
|
|
89
|
+
"\u{1D4DC}",
|
|
90
|
+
// MEMORY - Memória
|
|
91
|
+
"\u267E",
|
|
92
|
+
// PERSIST - Persistência
|
|
93
|
+
"\u2302"
|
|
94
|
+
// ROOT - Raiz do sistema
|
|
95
|
+
]);
|
|
96
|
+
var SYMBOLS_UI = /* @__PURE__ */ new Set([
|
|
97
|
+
"\u03A6",
|
|
98
|
+
// FORM - Form/UI
|
|
99
|
+
"\u0398",
|
|
100
|
+
// ANIMATION - Animação
|
|
101
|
+
"\u2610",
|
|
102
|
+
// INTERFACE - Interface
|
|
103
|
+
"\u{1F441}",
|
|
104
|
+
// VISUAL - Percepção visual
|
|
105
|
+
"\u2328",
|
|
106
|
+
// INPUT - Entrada
|
|
107
|
+
"\u{1F9ED}"
|
|
108
|
+
// POINTER - Ponteiro/direção
|
|
109
|
+
]);
|
|
110
|
+
var SYMBOLS_SECURITY = /* @__PURE__ */ new Set([
|
|
111
|
+
"\u{1F6E1}",
|
|
112
|
+
// SECURITY - Segurança
|
|
113
|
+
"\u{1F511}",
|
|
114
|
+
// KEY - Chave/autorização
|
|
115
|
+
"\u26A0",
|
|
116
|
+
// RISK - Risco
|
|
117
|
+
"\u26D4",
|
|
118
|
+
// BLOCK - Bloqueio
|
|
119
|
+
"\u{1F9EA}"
|
|
120
|
+
// SANDBOX - Isolamento
|
|
121
|
+
]);
|
|
122
|
+
var SYMBOLS_EVOLVE = /* @__PURE__ */ new Set([
|
|
123
|
+
"\u2301",
|
|
124
|
+
// EVOLVE BLOCK - Bloco de evolução
|
|
125
|
+
"\u27F3",
|
|
126
|
+
// EVOLVE - Evoluir
|
|
127
|
+
"\u2714",
|
|
128
|
+
// VERIFY - Verificar
|
|
129
|
+
"\u2713",
|
|
130
|
+
// VALID - Válido
|
|
131
|
+
"\u2716",
|
|
132
|
+
// INVALID - Inválido
|
|
133
|
+
"\u{1F4DC}"
|
|
134
|
+
// LOG - Registro
|
|
135
|
+
]);
|
|
136
|
+
var SYMBOLS_LOGIC = /* @__PURE__ */ new Set([
|
|
137
|
+
"\u039B",
|
|
138
|
+
// LOGIC - Lógica condicional
|
|
139
|
+
"\u2297"
|
|
140
|
+
// PARALLEL BLOCK - Bloco paralelo
|
|
141
|
+
]);
|
|
142
|
+
var SYMBOLS = /* @__PURE__ */ new Set([
|
|
143
|
+
...SYMBOLS_STATE,
|
|
144
|
+
...SYMBOLS_EXEC,
|
|
145
|
+
...SYMBOLS_STRUCT,
|
|
146
|
+
...SYMBOLS_TIME,
|
|
147
|
+
...SYMBOLS_ENERGY,
|
|
148
|
+
...SYMBOLS_MEMORY,
|
|
149
|
+
...SYMBOLS_UI,
|
|
150
|
+
...SYMBOLS_SECURITY,
|
|
151
|
+
...SYMBOLS_EVOLVE,
|
|
152
|
+
...SYMBOLS_LOGIC
|
|
153
|
+
]);
|
|
154
|
+
var SYMBOL_NAMES = {
|
|
155
|
+
"\u03A3": "STATE",
|
|
156
|
+
"\u03C3": "SUBSTATE",
|
|
157
|
+
"\xD8": "VOID",
|
|
158
|
+
"\u{1F512}": "LOCK",
|
|
159
|
+
"\u{1F513}": "UNLOCK",
|
|
160
|
+
"\u0394": "ACTION",
|
|
161
|
+
"\u0192": "FUNCTION",
|
|
162
|
+
"\u21C9": "PARALLEL",
|
|
163
|
+
"\u25B3": "DEPEND",
|
|
164
|
+
"\u25CF": "CORE",
|
|
165
|
+
"\u23F3": "DELAY",
|
|
166
|
+
"\u03A9": "OBJECT",
|
|
167
|
+
"\u25A0": "OBJECT_ALT",
|
|
168
|
+
"\u25CB": "CLASS",
|
|
169
|
+
"\u2B12": "INHERIT",
|
|
170
|
+
"\u2283": "CONTAINS",
|
|
171
|
+
"\u2254": "ASSIGN",
|
|
172
|
+
"\u29C9": "MODULE",
|
|
173
|
+
"\u26A1": "CAUSE",
|
|
174
|
+
"\u2726": "CONSEQUENCE",
|
|
175
|
+
"\u21BB": "LOOP",
|
|
176
|
+
"\u25CC": "EVENT",
|
|
177
|
+
"\u21C4": "SYNC",
|
|
178
|
+
"\u231B": "TIMEOUT",
|
|
179
|
+
"\u03A8": "ENERGY",
|
|
180
|
+
"\u23EC": "THROTTLE",
|
|
181
|
+
"\u23EB": "BOOST",
|
|
182
|
+
"\u20B5": "COST",
|
|
183
|
+
"\u{1D4DC}": "MEMORY",
|
|
184
|
+
"\u267E": "PERSIST",
|
|
185
|
+
"\u2302": "ROOT",
|
|
186
|
+
"\u03A6": "FORM",
|
|
187
|
+
"\u0398": "ANIMATION",
|
|
188
|
+
"\u2610": "INTERFACE",
|
|
189
|
+
"\u{1F441}": "VISUAL",
|
|
190
|
+
"\u2328": "INPUT",
|
|
191
|
+
"\u{1F9ED}": "POINTER",
|
|
192
|
+
"\u{1F6E1}": "SECURITY",
|
|
193
|
+
"\u{1F511}": "KEY",
|
|
194
|
+
"\u26A0": "RISK",
|
|
195
|
+
"\u26D4": "BLOCK",
|
|
196
|
+
"\u{1F9EA}": "SANDBOX",
|
|
197
|
+
"\u2301": "EVOLVE_BLOCK",
|
|
198
|
+
"\u27F3": "EVOLVE",
|
|
199
|
+
"\u2714": "VERIFY",
|
|
200
|
+
"\u2713": "VALID",
|
|
201
|
+
"\u2716": "INVALID",
|
|
202
|
+
"\u{1F4DC}": "LOG",
|
|
203
|
+
"\u039B": "LOGIC",
|
|
204
|
+
"\u2297": "PARALLEL_BLOCK"
|
|
205
|
+
};
|
|
206
|
+
var OPERATORS = /* @__PURE__ */ new Set(["+", "\u2212", "-", "\u2254"]);
|
|
207
|
+
function isWhitespace(ch) {
|
|
208
|
+
return ch === " " || ch === " " || ch === "\r";
|
|
209
|
+
}
|
|
210
|
+
function isNewline(ch) {
|
|
211
|
+
return ch === "\n";
|
|
212
|
+
}
|
|
213
|
+
function isDigit(ch) {
|
|
214
|
+
return /[0-9]/.test(ch);
|
|
215
|
+
}
|
|
216
|
+
function isIdentifierStart(ch) {
|
|
217
|
+
return /[A-Za-z_\p{L}]/u.test(ch);
|
|
218
|
+
}
|
|
219
|
+
function isIdentifierPart(ch) {
|
|
220
|
+
return /[A-Za-z0-9_\p{L}]/u.test(ch);
|
|
221
|
+
}
|
|
222
|
+
function getCodePoint(str, pos) {
|
|
223
|
+
const code = str.codePointAt(pos);
|
|
224
|
+
if (code === void 0)
|
|
225
|
+
return { char: "", len: 0 };
|
|
226
|
+
const char = String.fromCodePoint(code);
|
|
227
|
+
const len = code > 65535 ? 2 : 1;
|
|
228
|
+
return { char, len };
|
|
229
|
+
}
|
|
230
|
+
function tokenize(input) {
|
|
231
|
+
const tokens = [];
|
|
232
|
+
const len = input.length;
|
|
233
|
+
let i = 0;
|
|
234
|
+
while (i < len) {
|
|
235
|
+
const { char: ch, len: charLen } = getCodePoint(input, i);
|
|
236
|
+
if (charLen === 0) {
|
|
237
|
+
i++;
|
|
238
|
+
continue;
|
|
239
|
+
}
|
|
240
|
+
if (isWhitespace(ch)) {
|
|
241
|
+
i += charLen;
|
|
242
|
+
continue;
|
|
243
|
+
}
|
|
244
|
+
if (isNewline(ch)) {
|
|
245
|
+
tokens.push({ type: "NEWLINE" /* NEWLINE */, value: "\n", pos: i });
|
|
246
|
+
i += charLen;
|
|
247
|
+
continue;
|
|
248
|
+
}
|
|
249
|
+
if (SYMBOLS.has(ch)) {
|
|
250
|
+
tokens.push({ type: "SYMBOL" /* SYMBOL */, value: ch, pos: i });
|
|
251
|
+
i += charLen;
|
|
252
|
+
continue;
|
|
253
|
+
}
|
|
254
|
+
if (ch === "\u2192" || ch === "-" && input[i + 1] === ">") {
|
|
255
|
+
if (ch === "\u2192") {
|
|
256
|
+
tokens.push({ type: "ARROW" /* ARROW */, value: "\u2192", pos: i });
|
|
257
|
+
i++;
|
|
258
|
+
} else {
|
|
259
|
+
tokens.push({ type: "ARROW" /* ARROW */, value: "->", pos: i });
|
|
260
|
+
i += 2;
|
|
261
|
+
}
|
|
262
|
+
continue;
|
|
263
|
+
}
|
|
264
|
+
if (ch === "{") {
|
|
265
|
+
tokens.push({ type: "LBRACE" /* LBRACE */, value: "{", pos: i });
|
|
266
|
+
i++;
|
|
267
|
+
continue;
|
|
268
|
+
}
|
|
269
|
+
if (ch === "}") {
|
|
270
|
+
tokens.push({ type: "RBRACE" /* RBRACE */, value: "}", pos: i });
|
|
271
|
+
i++;
|
|
272
|
+
continue;
|
|
273
|
+
}
|
|
274
|
+
if (ch === "(") {
|
|
275
|
+
tokens.push({ type: "LPAREN" /* LPAREN */, value: "(", pos: i });
|
|
276
|
+
i++;
|
|
277
|
+
continue;
|
|
278
|
+
}
|
|
279
|
+
if (ch === ")") {
|
|
280
|
+
tokens.push({ type: "RPAREN" /* RPAREN */, value: ")", pos: i });
|
|
281
|
+
i++;
|
|
282
|
+
continue;
|
|
283
|
+
}
|
|
284
|
+
if (ch === "[") {
|
|
285
|
+
tokens.push({ type: "LBRACKET" /* LBRACKET */, value: "[", pos: i });
|
|
286
|
+
i++;
|
|
287
|
+
continue;
|
|
288
|
+
}
|
|
289
|
+
if (ch === "]") {
|
|
290
|
+
tokens.push({ type: "RBRACKET" /* RBRACKET */, value: "]", pos: i });
|
|
291
|
+
i++;
|
|
292
|
+
continue;
|
|
293
|
+
}
|
|
294
|
+
if (ch === ":") {
|
|
295
|
+
tokens.push({ type: "COLON" /* COLON */, value: ":", pos: i });
|
|
296
|
+
i++;
|
|
297
|
+
continue;
|
|
298
|
+
}
|
|
299
|
+
if (ch === ",") {
|
|
300
|
+
tokens.push({ type: "COMMA" /* COMMA */, value: ",", pos: i });
|
|
301
|
+
i++;
|
|
302
|
+
continue;
|
|
303
|
+
}
|
|
304
|
+
if (ch === "=" && input[i + 1] === "=" || ch === "!" && input[i + 1] === "=" || ch === ">" && input[i + 1] === "=" || ch === "<" && input[i + 1] === "=") {
|
|
305
|
+
tokens.push({ type: "COMPARATOR" /* COMPARATOR */, value: input.substr(i, 2), pos: i });
|
|
306
|
+
i += 2;
|
|
307
|
+
continue;
|
|
308
|
+
}
|
|
309
|
+
if (ch === ">" || ch === "<") {
|
|
310
|
+
tokens.push({ type: "COMPARATOR" /* COMPARATOR */, value: ch, pos: i });
|
|
311
|
+
i++;
|
|
312
|
+
continue;
|
|
313
|
+
}
|
|
314
|
+
if (ch === "\u2260") {
|
|
315
|
+
tokens.push({ type: "COMPARATOR" /* COMPARATOR */, value: "\u2260", pos: i });
|
|
316
|
+
i++;
|
|
317
|
+
continue;
|
|
318
|
+
}
|
|
319
|
+
if (OPERATORS.has(ch) && !SYMBOLS.has(ch)) {
|
|
320
|
+
tokens.push({ type: "OPERATOR" /* OPERATOR */, value: ch, pos: i });
|
|
321
|
+
i++;
|
|
322
|
+
continue;
|
|
323
|
+
}
|
|
324
|
+
if (ch === '"') {
|
|
325
|
+
let j = i + 1;
|
|
326
|
+
let out = "";
|
|
327
|
+
while (j < len) {
|
|
328
|
+
if (input[j] === "\\" && j + 1 < len) {
|
|
329
|
+
out += input[j + 1];
|
|
330
|
+
j += 2;
|
|
331
|
+
continue;
|
|
332
|
+
}
|
|
333
|
+
if (input[j] === '"') {
|
|
334
|
+
break;
|
|
335
|
+
}
|
|
336
|
+
out += input[j];
|
|
337
|
+
j++;
|
|
338
|
+
}
|
|
339
|
+
tokens.push({ type: "STRING" /* STRING */, value: out, pos: i });
|
|
340
|
+
i = j + 1;
|
|
341
|
+
continue;
|
|
342
|
+
}
|
|
343
|
+
if (isDigit(ch)) {
|
|
344
|
+
let j = i;
|
|
345
|
+
let val = "";
|
|
346
|
+
while (j < len && isDigit(input[j])) {
|
|
347
|
+
val += input[j];
|
|
348
|
+
j++;
|
|
349
|
+
}
|
|
350
|
+
tokens.push({ type: "NUMBER" /* NUMBER */, value: val, pos: i });
|
|
351
|
+
i = j;
|
|
352
|
+
continue;
|
|
353
|
+
}
|
|
354
|
+
if (isIdentifierStart(ch)) {
|
|
355
|
+
let j = i;
|
|
356
|
+
let val = "";
|
|
357
|
+
while (j < len && isIdentifierPart(input[j])) {
|
|
358
|
+
val += input[j];
|
|
359
|
+
j++;
|
|
360
|
+
}
|
|
361
|
+
tokens.push({ type: "IDENTIFIER" /* IDENTIFIER */, value: val, pos: i });
|
|
362
|
+
i = j;
|
|
363
|
+
continue;
|
|
364
|
+
}
|
|
365
|
+
tokens.push({ type: "IDENTIFIER" /* IDENTIFIER */, value: ch, pos: i });
|
|
366
|
+
i += charLen;
|
|
367
|
+
}
|
|
368
|
+
tokens.push({ type: "EOF" /* EOF */, value: "", pos: i });
|
|
369
|
+
return tokens;
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
// src/semantic/validate.ts
|
|
373
|
+
function validateSemantic(ast, options) {
|
|
374
|
+
const errors = [];
|
|
375
|
+
const onLog = (e) => {
|
|
376
|
+
const entry = { timestamp: (/* @__PURE__ */ new Date()).toISOString(), ...e };
|
|
377
|
+
if (options?.onLog)
|
|
378
|
+
options.onLog(entry);
|
|
379
|
+
};
|
|
380
|
+
ast.functions = ast.functions || [];
|
|
381
|
+
ast.modules = ast.modules || [];
|
|
382
|
+
const fnMap = /* @__PURE__ */ new Map();
|
|
383
|
+
for (const fn of ast.functions) {
|
|
384
|
+
const name = fn.name;
|
|
385
|
+
fnMap.set(name, (fnMap.get(name) || 0) + 1);
|
|
386
|
+
}
|
|
387
|
+
for (const [name, count] of fnMap.entries()) {
|
|
388
|
+
if (count > 1) {
|
|
389
|
+
const msg = `Duplicate function name: ${name}`;
|
|
390
|
+
errors.push(msg);
|
|
391
|
+
onLog({ level: "error", event: "parse.semantic.error", detail: { error: msg } });
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
const knownFns = new Set((ast.functions || []).map((f) => f.name));
|
|
395
|
+
for (const fn of ast.functions || []) {
|
|
396
|
+
for (const step of fn.steps || []) {
|
|
397
|
+
const token = step.raw.trim();
|
|
398
|
+
if (/^[A-Za-z_][A-Za-z0-9_]*$/.test(token)) {
|
|
399
|
+
if (!knownFns.has(token)) {
|
|
400
|
+
const msg = `Undefined function reference in '${fn.name}': '${token}'`;
|
|
401
|
+
errors.push(msg);
|
|
402
|
+
onLog({ level: "warn", event: "parse.semantic.error", detail: { error: msg } });
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
ast.errors = errors;
|
|
408
|
+
if (errors.length > 0)
|
|
409
|
+
console.debug("[semantic] errors", errors);
|
|
410
|
+
return errors;
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
// src/evolve/stub.ts
|
|
414
|
+
function applyEvolve(ast, options) {
|
|
415
|
+
if (!ast.evolve || !ast.evolve.steps || ast.evolve.steps.length === 0)
|
|
416
|
+
return { changed: false };
|
|
417
|
+
const onLog = options?.onLog;
|
|
418
|
+
const steps = ast.evolve.steps;
|
|
419
|
+
let changed = false;
|
|
420
|
+
for (const step of steps) {
|
|
421
|
+
const parts = step.split(/\s+/);
|
|
422
|
+
if (parts[0] === "rename" && parts.length === 3) {
|
|
423
|
+
const [, oldName, newName] = parts;
|
|
424
|
+
for (const fn of ast.functions || []) {
|
|
425
|
+
if (fn.name === oldName) {
|
|
426
|
+
fn.name = newName;
|
|
427
|
+
changed = true;
|
|
428
|
+
if (onLog)
|
|
429
|
+
onLog({ timestamp: (/* @__PURE__ */ new Date()).toISOString(), level: "info", event: "parse.evolve.applied", detail: { action: "rename", from: oldName, to: newName } });
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
if (parts[0] === "optimize" && parts.length === 2) {
|
|
434
|
+
const [, fnName] = parts;
|
|
435
|
+
for (const fn of ast.functions || []) {
|
|
436
|
+
if (fn.name === fnName) {
|
|
437
|
+
fn.optimized = true;
|
|
438
|
+
changed = true;
|
|
439
|
+
if (onLog)
|
|
440
|
+
onLog({ timestamp: (/* @__PURE__ */ new Date()).toISOString(), level: "info", event: "parse.evolve.applied", detail: { action: "optimize", target: fnName } });
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
if (changed && onLog)
|
|
446
|
+
onLog({ timestamp: (/* @__PURE__ */ new Date()).toISOString(), level: "info", event: "parse.evolve.changed", detail: { steps } });
|
|
447
|
+
return { changed };
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
// src/parser/ebnfParser.ts
|
|
451
|
+
function peek(cx) {
|
|
452
|
+
return cx.tokens[cx.i];
|
|
453
|
+
}
|
|
454
|
+
function next(cx) {
|
|
455
|
+
return cx.tokens[cx.i++];
|
|
456
|
+
}
|
|
457
|
+
function eat(cx, type, value) {
|
|
458
|
+
const t = peek(cx);
|
|
459
|
+
if (!t)
|
|
460
|
+
throw new Error(`Unexpected EOF, expected ${type}`);
|
|
461
|
+
if (t.type !== type)
|
|
462
|
+
throw new Error(`Expected token ${type} but got ${t.type} ('${t.value}') at ${t.pos}`);
|
|
463
|
+
if (value !== void 0 && t.value !== value)
|
|
464
|
+
throw new Error(`Expected token value ${value} but got '${t.value}' at ${t.pos}`);
|
|
465
|
+
return next(cx);
|
|
466
|
+
}
|
|
467
|
+
function skipNewlines(cx) {
|
|
468
|
+
while (peek(cx) && peek(cx).type === "NEWLINE" /* NEWLINE */)
|
|
469
|
+
next(cx);
|
|
470
|
+
}
|
|
471
|
+
function parseTokens(tokens, options) {
|
|
472
|
+
const cx = { tokens, i: 0 };
|
|
473
|
+
const ast = {
|
|
474
|
+
raw: tokens.map((t) => t.value).join(" "),
|
|
475
|
+
// Core collections
|
|
476
|
+
functions: [],
|
|
477
|
+
ias: [],
|
|
478
|
+
nodes: [],
|
|
479
|
+
modules: [],
|
|
480
|
+
objects: [],
|
|
481
|
+
forms: [],
|
|
482
|
+
animations: [],
|
|
483
|
+
logic: [],
|
|
484
|
+
parallels: [],
|
|
485
|
+
build: null,
|
|
486
|
+
evolve: null,
|
|
487
|
+
targets: [],
|
|
488
|
+
version: null,
|
|
489
|
+
logs: [],
|
|
490
|
+
// Extended collections from full alphabet
|
|
491
|
+
substates: [],
|
|
492
|
+
classes: [],
|
|
493
|
+
loops: [],
|
|
494
|
+
events: [],
|
|
495
|
+
syncs: [],
|
|
496
|
+
timeouts: [],
|
|
497
|
+
delays: [],
|
|
498
|
+
securities: [],
|
|
499
|
+
keys: [],
|
|
500
|
+
sandboxes: [],
|
|
501
|
+
causes: [],
|
|
502
|
+
consequences: [],
|
|
503
|
+
memories: [],
|
|
504
|
+
persists: [],
|
|
505
|
+
roots: [],
|
|
506
|
+
interfaces: [],
|
|
507
|
+
visuals: [],
|
|
508
|
+
inputs: [],
|
|
509
|
+
throttles: [],
|
|
510
|
+
boosts: [],
|
|
511
|
+
costs: [],
|
|
512
|
+
locks: [],
|
|
513
|
+
unlocks: [],
|
|
514
|
+
voids: [],
|
|
515
|
+
inherits: [],
|
|
516
|
+
contains: [],
|
|
517
|
+
verifies: [],
|
|
518
|
+
logNodes: [],
|
|
519
|
+
database: null,
|
|
520
|
+
kernel: null,
|
|
521
|
+
training: null
|
|
522
|
+
};
|
|
523
|
+
const onLog = (e) => {
|
|
524
|
+
const entry = { timestamp: (/* @__PURE__ */ new Date()).toISOString(), ...e };
|
|
525
|
+
ast.logs.push(entry);
|
|
526
|
+
if (options?.onLog)
|
|
527
|
+
options.onLog(entry);
|
|
528
|
+
};
|
|
529
|
+
skipNewlines(cx);
|
|
530
|
+
while (peek(cx) && peek(cx).type !== "EOF" /* EOF */) {
|
|
531
|
+
const t = peek(cx);
|
|
532
|
+
if (t.type === "SYMBOL" /* SYMBOL */) {
|
|
533
|
+
const sym = t.value;
|
|
534
|
+
next(cx);
|
|
535
|
+
skipNewlines(cx);
|
|
536
|
+
while (peek(cx) && peek(cx).type === "NEWLINE" /* NEWLINE */)
|
|
537
|
+
next(cx);
|
|
538
|
+
const ident = peek(cx);
|
|
539
|
+
if (!ident)
|
|
540
|
+
break;
|
|
541
|
+
const kw = ident.type === "IDENTIFIER" /* IDENTIFIER */ ? ident.value.toUpperCase() : void 0;
|
|
542
|
+
if (sym === "\u03A3" && kw === "SYSTEM") {
|
|
543
|
+
next(cx);
|
|
544
|
+
skipNewlines(cx);
|
|
545
|
+
const nameTok = eat(cx, "STRING" /* STRING */);
|
|
546
|
+
ast.system = nameTok.value;
|
|
547
|
+
onLog({ level: "info", event: "parse.system", detail: { name: ast.system } });
|
|
548
|
+
skipNewlines(cx);
|
|
549
|
+
continue;
|
|
550
|
+
}
|
|
551
|
+
if (sym === "\u03A3" && kw === "TARGET") {
|
|
552
|
+
next(cx);
|
|
553
|
+
skipNewlines(cx);
|
|
554
|
+
const targets = [];
|
|
555
|
+
while (peek(cx) && peek(cx).type !== "NEWLINE" /* NEWLINE */ && peek(cx).type !== "EOF" /* EOF */) {
|
|
556
|
+
const v = peek(cx);
|
|
557
|
+
if (v.type === "IDENTIFIER" /* IDENTIFIER */ || v.type === "STRING" /* STRING */) {
|
|
558
|
+
targets.push(v.value);
|
|
559
|
+
next(cx);
|
|
560
|
+
} else if (v.type === "COMMA" /* COMMA */) {
|
|
561
|
+
next(cx);
|
|
562
|
+
} else {
|
|
563
|
+
break;
|
|
564
|
+
}
|
|
565
|
+
}
|
|
566
|
+
ast.targets = [...ast.targets || [], ...targets];
|
|
567
|
+
onLog({ level: "info", event: "parse.target", detail: { targets } });
|
|
568
|
+
skipNewlines(cx);
|
|
569
|
+
continue;
|
|
570
|
+
}
|
|
571
|
+
if (sym === "\u03A3" && kw === "MODE") {
|
|
572
|
+
next(cx);
|
|
573
|
+
skipNewlines(cx);
|
|
574
|
+
const v = eat(cx, "IDENTIFIER" /* IDENTIFIER */);
|
|
575
|
+
ast.mode = v.value;
|
|
576
|
+
onLog({ level: "info", event: "parse.mode", detail: { mode: ast.mode } });
|
|
577
|
+
skipNewlines(cx);
|
|
578
|
+
continue;
|
|
579
|
+
}
|
|
580
|
+
if (sym === "\u03A3" && kw === "UI") {
|
|
581
|
+
next(cx);
|
|
582
|
+
skipNewlines(cx);
|
|
583
|
+
const v = eat(cx, "IDENTIFIER" /* IDENTIFIER */);
|
|
584
|
+
ast.ui = v.value;
|
|
585
|
+
onLog({ level: "info", event: "parse.ui", detail: { ui: ast.ui } });
|
|
586
|
+
skipNewlines(cx);
|
|
587
|
+
continue;
|
|
588
|
+
}
|
|
589
|
+
if (sym === "\u03A3" && kw === "MODULE") {
|
|
590
|
+
next(cx);
|
|
591
|
+
skipNewlines(cx);
|
|
592
|
+
const nameTok = eat(cx, "STRING" /* STRING */);
|
|
593
|
+
const module = { type: "module", name: nameTok.value };
|
|
594
|
+
ast.modules.push(module);
|
|
595
|
+
ast.nodes.push(module);
|
|
596
|
+
onLog({ level: "info", event: "parse.module", detail: module });
|
|
597
|
+
skipNewlines(cx);
|
|
598
|
+
continue;
|
|
599
|
+
}
|
|
600
|
+
if (sym === "\u03A3" && kw === "BUILD") {
|
|
601
|
+
next(cx);
|
|
602
|
+
skipNewlines(cx);
|
|
603
|
+
eat(cx, "LBRACE" /* LBRACE */);
|
|
604
|
+
const targets = [];
|
|
605
|
+
skipNewlines(cx);
|
|
606
|
+
while (peek(cx) && peek(cx).type !== "RBRACE" /* RBRACE */) {
|
|
607
|
+
const key = eat(cx, "IDENTIFIER" /* IDENTIFIER */);
|
|
608
|
+
eat(cx, "COLON" /* COLON */);
|
|
609
|
+
const val = peek(cx);
|
|
610
|
+
if (val.type === "IDENTIFIER" /* IDENTIFIER */ || val.type === "STRING" /* STRING */) {
|
|
611
|
+
targets.push(val.value);
|
|
612
|
+
next(cx);
|
|
613
|
+
} else {
|
|
614
|
+
throw new Error("Expected identifier or string for build target");
|
|
615
|
+
}
|
|
616
|
+
skipNewlines(cx);
|
|
617
|
+
if (peek(cx) && peek(cx).type === "COMMA" /* COMMA */)
|
|
618
|
+
next(cx);
|
|
619
|
+
skipNewlines(cx);
|
|
620
|
+
}
|
|
621
|
+
eat(cx, "RBRACE" /* RBRACE */);
|
|
622
|
+
const b = { type: "build", targets };
|
|
623
|
+
ast.build = b;
|
|
624
|
+
ast.nodes.push(b);
|
|
625
|
+
onLog({ level: "info", event: "parse.build", detail: b });
|
|
626
|
+
skipNewlines(cx);
|
|
627
|
+
continue;
|
|
628
|
+
}
|
|
629
|
+
if (sym === "\u03A3" && kw === "EVOLVE") {
|
|
630
|
+
next(cx);
|
|
631
|
+
skipNewlines(cx);
|
|
632
|
+
const v = peek(cx);
|
|
633
|
+
if (v && (v.type === "IDENTIFIER" /* IDENTIFIER */ || v.type === "STRING" /* STRING */)) {
|
|
634
|
+
const ev = { type: "evolve", steps: [next(cx).value] };
|
|
635
|
+
ast.evolve = ev;
|
|
636
|
+
onLog({ level: "info", event: "parse.evolve", detail: ev });
|
|
637
|
+
}
|
|
638
|
+
skipNewlines(cx);
|
|
639
|
+
continue;
|
|
640
|
+
}
|
|
641
|
+
if (sym === "\u03A3" && kw === "DATABASE") {
|
|
642
|
+
next(cx);
|
|
643
|
+
skipNewlines(cx);
|
|
644
|
+
const v = peek(cx);
|
|
645
|
+
if (v && v.type === "IDENTIFIER" /* IDENTIFIER */) {
|
|
646
|
+
const mode = next(cx).value;
|
|
647
|
+
const db = { type: "database", mode };
|
|
648
|
+
ast.database = db;
|
|
649
|
+
ast.nodes.push(db);
|
|
650
|
+
onLog({ level: "info", event: "parse.database", detail: db });
|
|
651
|
+
}
|
|
652
|
+
skipNewlines(cx);
|
|
653
|
+
continue;
|
|
654
|
+
}
|
|
655
|
+
if (sym === "\u03A3" && kw === "KERNEL") {
|
|
656
|
+
next(cx);
|
|
657
|
+
skipNewlines(cx);
|
|
658
|
+
const hooks = [];
|
|
659
|
+
if (peek(cx) && peek(cx).type === "LBRACE" /* LBRACE */) {
|
|
660
|
+
next(cx);
|
|
661
|
+
skipNewlines(cx);
|
|
662
|
+
while (peek(cx) && peek(cx).type !== "RBRACE" /* RBRACE */) {
|
|
663
|
+
const p = peek(cx);
|
|
664
|
+
if (p.type === "IDENTIFIER" /* IDENTIFIER */) {
|
|
665
|
+
const hookName = next(cx).value;
|
|
666
|
+
if (peek(cx) && peek(cx).type === "IDENTIFIER" /* IDENTIFIER */) {
|
|
667
|
+
hooks.push(hookName + " " + next(cx).value);
|
|
668
|
+
} else {
|
|
669
|
+
hooks.push(hookName);
|
|
670
|
+
}
|
|
671
|
+
} else {
|
|
672
|
+
next(cx);
|
|
673
|
+
}
|
|
674
|
+
skipNewlines(cx);
|
|
675
|
+
}
|
|
676
|
+
if (peek(cx) && peek(cx).type === "RBRACE" /* RBRACE */)
|
|
677
|
+
next(cx);
|
|
678
|
+
}
|
|
679
|
+
const kernel = { type: "kernel", hooks };
|
|
680
|
+
ast.kernel = kernel;
|
|
681
|
+
ast.nodes.push(kernel);
|
|
682
|
+
onLog({ level: "info", event: "parse.kernel", detail: kernel });
|
|
683
|
+
skipNewlines(cx);
|
|
684
|
+
continue;
|
|
685
|
+
}
|
|
686
|
+
if (sym === "\u03A3" && kw === "TRAINING") {
|
|
687
|
+
next(cx);
|
|
688
|
+
skipNewlines(cx);
|
|
689
|
+
const v = peek(cx);
|
|
690
|
+
if (v && (v.type === "IDENTIFIER" /* IDENTIFIER */ || v.type === "STRING" /* STRING */)) {
|
|
691
|
+
const training = { type: "training", topic: next(cx).value };
|
|
692
|
+
ast.training = training;
|
|
693
|
+
ast.nodes.push(training);
|
|
694
|
+
onLog({ level: "info", event: "parse.training", detail: training });
|
|
695
|
+
}
|
|
696
|
+
skipNewlines(cx);
|
|
697
|
+
continue;
|
|
698
|
+
}
|
|
699
|
+
if (sym === "\u03A3" && kw === "LEVEL") {
|
|
700
|
+
next(cx);
|
|
701
|
+
skipNewlines(cx);
|
|
702
|
+
const v = peek(cx);
|
|
703
|
+
if (v && v.type === "NUMBER" /* NUMBER */) {
|
|
704
|
+
if (ast.training) {
|
|
705
|
+
ast.training.level = parseInt(next(cx).value, 10);
|
|
706
|
+
} else {
|
|
707
|
+
next(cx);
|
|
708
|
+
}
|
|
709
|
+
}
|
|
710
|
+
skipNewlines(cx);
|
|
711
|
+
continue;
|
|
712
|
+
}
|
|
713
|
+
if (sym === "\u0394") {
|
|
714
|
+
let nameTok = null;
|
|
715
|
+
if (kw === "FUNCTION") {
|
|
716
|
+
next(cx);
|
|
717
|
+
skipNewlines(cx);
|
|
718
|
+
const tname = eat(cx, "IDENTIFIER" /* IDENTIFIER */);
|
|
719
|
+
nameTok = tname;
|
|
720
|
+
} else {
|
|
721
|
+
if (ident.type === "IDENTIFIER" /* IDENTIFIER */) {
|
|
722
|
+
nameTok = next(cx);
|
|
723
|
+
}
|
|
724
|
+
}
|
|
725
|
+
if (!nameTok) {
|
|
726
|
+
onLog({ level: "warn", event: "parse.function.missing.name" });
|
|
727
|
+
skipNewlines(cx);
|
|
728
|
+
continue;
|
|
729
|
+
}
|
|
730
|
+
skipNewlines(cx);
|
|
731
|
+
let args = [];
|
|
732
|
+
if (peek(cx) && peek(cx).type === "LPAREN" /* LPAREN */) {
|
|
733
|
+
next(cx);
|
|
734
|
+
skipNewlines(cx);
|
|
735
|
+
while (peek(cx) && peek(cx).type !== "RPAREN" /* RPAREN */) {
|
|
736
|
+
const arg = eat(cx, "IDENTIFIER" /* IDENTIFIER */);
|
|
737
|
+
args.push(arg.value);
|
|
738
|
+
if (peek(cx) && peek(cx).type === "COMMA" /* COMMA */)
|
|
739
|
+
next(cx);
|
|
740
|
+
skipNewlines(cx);
|
|
741
|
+
}
|
|
742
|
+
eat(cx, "RPAREN" /* RPAREN */);
|
|
743
|
+
}
|
|
744
|
+
const steps = [];
|
|
745
|
+
skipNewlines(cx);
|
|
746
|
+
while (peek(cx) && peek(cx).type === "ARROW" /* ARROW */) {
|
|
747
|
+
next(cx);
|
|
748
|
+
const bodyTok = peek(cx);
|
|
749
|
+
if (bodyTok && (bodyTok.type === "IDENTIFIER" /* IDENTIFIER */ || bodyTok.type === "STRING" /* STRING */)) {
|
|
750
|
+
steps.push({ raw: bodyTok.value });
|
|
751
|
+
next(cx);
|
|
752
|
+
}
|
|
753
|
+
skipNewlines(cx);
|
|
754
|
+
}
|
|
755
|
+
onLog({ level: "info", event: "parse.function.start", detail: { name: nameTok.value, args } });
|
|
756
|
+
const fn = { type: "function", name: nameTok.value, args, steps };
|
|
757
|
+
ast.functions.push(fn);
|
|
758
|
+
ast.nodes.push(fn);
|
|
759
|
+
onLog({ level: "info", event: "parse.function.end", detail: fn });
|
|
760
|
+
continue;
|
|
761
|
+
}
|
|
762
|
+
if (sym === "\u03A8") {
|
|
763
|
+
if (kw === "IA") {
|
|
764
|
+
next(cx);
|
|
765
|
+
skipNewlines(cx);
|
|
766
|
+
const nameTok = peek(cx);
|
|
767
|
+
let name = "ia";
|
|
768
|
+
if (nameTok && (nameTok.type === "STRING" /* STRING */ || nameTok.type === "IDENTIFIER" /* IDENTIFIER */)) {
|
|
769
|
+
name = next(cx).value;
|
|
770
|
+
}
|
|
771
|
+
const body = [];
|
|
772
|
+
skipNewlines(cx);
|
|
773
|
+
if (peek(cx) && peek(cx).type === "LBRACE" /* LBRACE */) {
|
|
774
|
+
next(cx);
|
|
775
|
+
skipNewlines(cx);
|
|
776
|
+
while (peek(cx) && peek(cx).type !== "RBRACE" /* RBRACE */) {
|
|
777
|
+
const cap = peek(cx);
|
|
778
|
+
if (cap.type === "IDENTIFIER" /* IDENTIFIER */ || cap.type === "STRING" /* STRING */) {
|
|
779
|
+
body.push(cap.value);
|
|
780
|
+
next(cx);
|
|
781
|
+
} else {
|
|
782
|
+
next(cx);
|
|
783
|
+
}
|
|
784
|
+
skipNewlines(cx);
|
|
785
|
+
}
|
|
786
|
+
if (peek(cx) && peek(cx).type === "RBRACE" /* RBRACE */)
|
|
787
|
+
next(cx);
|
|
788
|
+
} else {
|
|
789
|
+
while (peek(cx) && peek(cx).type !== "SYMBOL" /* SYMBOL */ && peek(cx).type !== "EOF" /* EOF */ && peek(cx).type !== "NEWLINE" /* NEWLINE */) {
|
|
790
|
+
const cap = peek(cx);
|
|
791
|
+
if (cap.type === "IDENTIFIER" /* IDENTIFIER */ || cap.type === "STRING" /* STRING */) {
|
|
792
|
+
body.push(cap.value);
|
|
793
|
+
next(cx);
|
|
794
|
+
} else
|
|
795
|
+
break;
|
|
796
|
+
skipNewlines(cx);
|
|
797
|
+
}
|
|
798
|
+
}
|
|
799
|
+
const ia = { type: "ia", name, body };
|
|
800
|
+
ast.ias.push(ia);
|
|
801
|
+
ast.nodes.push(ia);
|
|
802
|
+
onLog({ level: "info", event: "parse.ia", detail: ia });
|
|
803
|
+
continue;
|
|
804
|
+
}
|
|
805
|
+
skipNewlines(cx);
|
|
806
|
+
continue;
|
|
807
|
+
}
|
|
808
|
+
if (sym === "\u03A9") {
|
|
809
|
+
skipNewlines(cx);
|
|
810
|
+
const nameTok = eat(cx, "IDENTIFIER" /* IDENTIFIER */);
|
|
811
|
+
const name = nameTok.value;
|
|
812
|
+
const props = {};
|
|
813
|
+
skipNewlines(cx);
|
|
814
|
+
if (peek(cx) && peek(cx).type === "LBRACE" /* LBRACE */) {
|
|
815
|
+
next(cx);
|
|
816
|
+
skipNewlines(cx);
|
|
817
|
+
while (peek(cx) && peek(cx).type !== "RBRACE" /* RBRACE */) {
|
|
818
|
+
const p = eat(cx, "IDENTIFIER" /* IDENTIFIER */);
|
|
819
|
+
skipNewlines(cx);
|
|
820
|
+
if (peek(cx) && peek(cx).type === "COLON" /* COLON */) {
|
|
821
|
+
next(cx);
|
|
822
|
+
skipNewlines(cx);
|
|
823
|
+
const val = peek(cx);
|
|
824
|
+
if (val && (val.type === "STRING" /* STRING */ || val.type === "IDENTIFIER" /* IDENTIFIER */ || val.type === "NUMBER" /* NUMBER */)) {
|
|
825
|
+
props[p.value] = val.value;
|
|
826
|
+
next(cx);
|
|
827
|
+
} else {
|
|
828
|
+
props[p.value] = null;
|
|
829
|
+
}
|
|
830
|
+
} else {
|
|
831
|
+
props[p.value] = null;
|
|
832
|
+
}
|
|
833
|
+
skipNewlines(cx);
|
|
834
|
+
}
|
|
835
|
+
if (peek(cx) && peek(cx).type === "RBRACE" /* RBRACE */)
|
|
836
|
+
next(cx);
|
|
837
|
+
}
|
|
838
|
+
const obj = { type: "object", name, props };
|
|
839
|
+
ast.objects.push(obj);
|
|
840
|
+
ast.nodes.push(obj);
|
|
841
|
+
onLog({ level: "info", event: "parse.object", detail: obj });
|
|
842
|
+
continue;
|
|
843
|
+
}
|
|
844
|
+
if (sym === "\u03A6") {
|
|
845
|
+
skipNewlines(cx);
|
|
846
|
+
let name = "form";
|
|
847
|
+
if (peek(cx) && peek(cx).type === "IDENTIFIER" /* IDENTIFIER */ && cx.tokens[cx.i + 1] && cx.tokens[cx.i + 1].type !== "LBRACE" /* LBRACE */) {
|
|
848
|
+
name = next(cx).value;
|
|
849
|
+
}
|
|
850
|
+
const props = {};
|
|
851
|
+
skipNewlines(cx);
|
|
852
|
+
if (peek(cx) && peek(cx).type === "LBRACE" /* LBRACE */) {
|
|
853
|
+
next(cx);
|
|
854
|
+
skipNewlines(cx);
|
|
855
|
+
while (peek(cx) && peek(cx).type !== "RBRACE" /* RBRACE */) {
|
|
856
|
+
if (peek(cx) && peek(cx).type === "IDENTIFIER" /* IDENTIFIER */) {
|
|
857
|
+
const key = eat(cx, "IDENTIFIER" /* IDENTIFIER */);
|
|
858
|
+
eat(cx, "COLON" /* COLON */);
|
|
859
|
+
const val = peek(cx);
|
|
860
|
+
if (val && (val.type === "STRING" /* STRING */ || val.type === "IDENTIFIER" /* IDENTIFIER */ || val.type === "NUMBER" /* NUMBER */)) {
|
|
861
|
+
props[key.value] = val.value;
|
|
862
|
+
next(cx);
|
|
863
|
+
} else {
|
|
864
|
+
props[key.value] = true;
|
|
865
|
+
}
|
|
866
|
+
} else {
|
|
867
|
+
next(cx);
|
|
868
|
+
}
|
|
869
|
+
skipNewlines(cx);
|
|
870
|
+
}
|
|
871
|
+
if (peek(cx) && peek(cx).type === "RBRACE" /* RBRACE */)
|
|
872
|
+
next(cx);
|
|
873
|
+
}
|
|
874
|
+
const form = { type: "form", name, props };
|
|
875
|
+
ast.forms.push(form);
|
|
876
|
+
ast.nodes.push(form);
|
|
877
|
+
onLog({ level: "info", event: "parse.form", detail: form });
|
|
878
|
+
continue;
|
|
879
|
+
}
|
|
880
|
+
if (sym === "\u0398") {
|
|
881
|
+
skipNewlines(cx);
|
|
882
|
+
const maybeAnim = eat(cx, "IDENTIFIER" /* IDENTIFIER */);
|
|
883
|
+
if (maybeAnim.value.toLowerCase() !== "animation") {
|
|
884
|
+
onLog({ level: "warn", event: "parse.animation.missing.keyword" });
|
|
885
|
+
continue;
|
|
886
|
+
}
|
|
887
|
+
skipNewlines(cx);
|
|
888
|
+
const nameTok = peek(cx);
|
|
889
|
+
let name = "animation";
|
|
890
|
+
if (nameTok && (nameTok.type === "STRING" /* STRING */ || nameTok.type === "IDENTIFIER" /* IDENTIFIER */)) {
|
|
891
|
+
name = next(cx).value;
|
|
892
|
+
}
|
|
893
|
+
const props = {};
|
|
894
|
+
skipNewlines(cx);
|
|
895
|
+
while (peek(cx) && peek(cx).type !== "SYMBOL" /* SYMBOL */ && peek(cx).type !== "EOF" /* EOF */) {
|
|
896
|
+
if (peek(cx).type === "IDENTIFIER" /* IDENTIFIER */) {
|
|
897
|
+
const key = next(cx).value;
|
|
898
|
+
if (peek(cx) && peek(cx).type === "COLON" /* COLON */) {
|
|
899
|
+
next(cx);
|
|
900
|
+
const val = peek(cx);
|
|
901
|
+
if (val && (val.type === "STRING" /* STRING */ || val.type === "NUMBER" /* NUMBER */ || val.type === "IDENTIFIER" /* IDENTIFIER */)) {
|
|
902
|
+
props[key] = val.value;
|
|
903
|
+
next(cx);
|
|
904
|
+
}
|
|
905
|
+
} else {
|
|
906
|
+
props[key] = true;
|
|
907
|
+
}
|
|
908
|
+
} else {
|
|
909
|
+
break;
|
|
910
|
+
}
|
|
911
|
+
skipNewlines(cx);
|
|
912
|
+
}
|
|
913
|
+
const anim = { type: "animation", name, props };
|
|
914
|
+
ast.animations.push(anim);
|
|
915
|
+
ast.nodes.push(anim);
|
|
916
|
+
onLog({ level: "info", event: "parse.animation", detail: anim });
|
|
917
|
+
continue;
|
|
918
|
+
}
|
|
919
|
+
if (sym === "\u039B") {
|
|
920
|
+
skipNewlines(cx);
|
|
921
|
+
const ifTok = eat(cx, "IDENTIFIER" /* IDENTIFIER */);
|
|
922
|
+
if (ifTok.value.toLowerCase() !== "if") {
|
|
923
|
+
onLog({ level: "warn", event: "parse.logic.missing.if" });
|
|
924
|
+
continue;
|
|
925
|
+
}
|
|
926
|
+
const leftTok = eat(cx, "IDENTIFIER" /* IDENTIFIER */);
|
|
927
|
+
let leftName = leftTok.value;
|
|
928
|
+
while (peek(cx) && peek(cx).type === "IDENTIFIER" /* IDENTIFIER */ && peek(cx).value === ".") {
|
|
929
|
+
next(cx);
|
|
930
|
+
const p = eat(cx, "IDENTIFIER" /* IDENTIFIER */);
|
|
931
|
+
leftName += "." + p.value;
|
|
932
|
+
}
|
|
933
|
+
const comp = eat(cx, "COMPARATOR" /* COMPARATOR */);
|
|
934
|
+
const right = peek(cx);
|
|
935
|
+
if (!right || !(right.type === "STRING" /* STRING */ || right.type === "NUMBER" /* NUMBER */ || right.type === "IDENTIFIER" /* IDENTIFIER */))
|
|
936
|
+
throw new Error("Invalid logic right-hand side");
|
|
937
|
+
next(cx);
|
|
938
|
+
const rule = `${leftName} ${comp.value} ${right.value}`;
|
|
939
|
+
const trueFlow = [];
|
|
940
|
+
const falseFlow = [];
|
|
941
|
+
skipNewlines(cx);
|
|
942
|
+
while (peek(cx) && peek(cx).type === "ARROW" /* ARROW */) {
|
|
943
|
+
next(cx);
|
|
944
|
+
const step = eat(cx, "IDENTIFIER" /* IDENTIFIER */);
|
|
945
|
+
trueFlow.push(step.value);
|
|
946
|
+
skipNewlines(cx);
|
|
947
|
+
}
|
|
948
|
+
if (peek(cx) && peek(cx).type === "IDENTIFIER" /* IDENTIFIER */ && peek(cx).value.toLowerCase() === "else") {
|
|
949
|
+
next(cx);
|
|
950
|
+
skipNewlines(cx);
|
|
951
|
+
while (peek(cx) && peek(cx).type === "ARROW" /* ARROW */) {
|
|
952
|
+
next(cx);
|
|
953
|
+
const step = eat(cx, "IDENTIFIER" /* IDENTIFIER */);
|
|
954
|
+
falseFlow.push(step.value);
|
|
955
|
+
skipNewlines(cx);
|
|
956
|
+
}
|
|
957
|
+
}
|
|
958
|
+
const logic = { type: "logic", rule, trueFlow, falseFlow };
|
|
959
|
+
ast.logic.push(logic);
|
|
960
|
+
ast.nodes.push(logic);
|
|
961
|
+
onLog({ level: "info", event: "parse.logic", detail: logic });
|
|
962
|
+
continue;
|
|
963
|
+
}
|
|
964
|
+
if (sym === "\u2297") {
|
|
965
|
+
skipNewlines(cx);
|
|
966
|
+
const items = [];
|
|
967
|
+
if (peek(cx) && peek(cx).type === "LBRACE" /* LBRACE */) {
|
|
968
|
+
next(cx);
|
|
969
|
+
skipNewlines(cx);
|
|
970
|
+
while (peek(cx) && peek(cx).type !== "RBRACE" /* RBRACE */) {
|
|
971
|
+
const parts = [];
|
|
972
|
+
while (peek(cx) && peek(cx).type !== "NEWLINE" /* NEWLINE */ && peek(cx).type !== "RBRACE" /* RBRACE */) {
|
|
973
|
+
const p = peek(cx);
|
|
974
|
+
if (p.type === "IDENTIFIER" /* IDENTIFIER */ || p.type === "STRING" /* STRING */ || p.type === "NUMBER" /* NUMBER */) {
|
|
975
|
+
parts.push(next(cx).value);
|
|
976
|
+
} else {
|
|
977
|
+
next(cx);
|
|
978
|
+
}
|
|
979
|
+
}
|
|
980
|
+
if (parts.length > 0)
|
|
981
|
+
items.push(parts.join(" "));
|
|
982
|
+
if (peek(cx) && peek(cx).type === "NEWLINE" /* NEWLINE */)
|
|
983
|
+
next(cx);
|
|
984
|
+
skipNewlines(cx);
|
|
985
|
+
}
|
|
986
|
+
if (peek(cx) && peek(cx).type === "RBRACE" /* RBRACE */)
|
|
987
|
+
next(cx);
|
|
988
|
+
}
|
|
989
|
+
const par = { type: "parallel", items };
|
|
990
|
+
ast.parallels.push(par);
|
|
991
|
+
ast.nodes.push(par);
|
|
992
|
+
onLog({ level: "info", event: "parse.parallel", detail: par });
|
|
993
|
+
continue;
|
|
994
|
+
}
|
|
995
|
+
if (sym === "\u2301" && kw === "EVOLVE") {
|
|
996
|
+
next(cx);
|
|
997
|
+
skipNewlines(cx);
|
|
998
|
+
if (peek(cx) && peek(cx).type === "LBRACE" /* LBRACE */) {
|
|
999
|
+
next(cx);
|
|
1000
|
+
skipNewlines(cx);
|
|
1001
|
+
const steps = [];
|
|
1002
|
+
while (peek(cx) && peek(cx).type !== "RBRACE" /* RBRACE */) {
|
|
1003
|
+
const p = peek(cx);
|
|
1004
|
+
if (p.type === "IDENTIFIER" /* IDENTIFIER */ || p.type === "STRING" /* STRING */) {
|
|
1005
|
+
steps.push(p.value);
|
|
1006
|
+
next(cx);
|
|
1007
|
+
} else {
|
|
1008
|
+
next(cx);
|
|
1009
|
+
}
|
|
1010
|
+
skipNewlines(cx);
|
|
1011
|
+
}
|
|
1012
|
+
if (peek(cx) && peek(cx).type === "RBRACE" /* RBRACE */)
|
|
1013
|
+
next(cx);
|
|
1014
|
+
const ev = { type: "evolve", steps };
|
|
1015
|
+
ast.evolve = ev;
|
|
1016
|
+
ast.nodes.push(ev);
|
|
1017
|
+
onLog({ level: "info", event: "parse.evolve", detail: ev });
|
|
1018
|
+
continue;
|
|
1019
|
+
}
|
|
1020
|
+
}
|
|
1021
|
+
if (sym === "\u03C3") {
|
|
1022
|
+
skipNewlines(cx);
|
|
1023
|
+
let name = "substate";
|
|
1024
|
+
if (peek(cx) && peek(cx).type === "IDENTIFIER" /* IDENTIFIER */) {
|
|
1025
|
+
name = next(cx).value;
|
|
1026
|
+
}
|
|
1027
|
+
const props = {};
|
|
1028
|
+
skipNewlines(cx);
|
|
1029
|
+
if (peek(cx) && peek(cx).type === "LBRACE" /* LBRACE */) {
|
|
1030
|
+
next(cx);
|
|
1031
|
+
skipNewlines(cx);
|
|
1032
|
+
while (peek(cx) && peek(cx).type !== "RBRACE" /* RBRACE */) {
|
|
1033
|
+
if (peek(cx).type === "IDENTIFIER" /* IDENTIFIER */) {
|
|
1034
|
+
const key = next(cx).value;
|
|
1035
|
+
if (peek(cx) && peek(cx).type === "COLON" /* COLON */) {
|
|
1036
|
+
next(cx);
|
|
1037
|
+
const val = peek(cx);
|
|
1038
|
+
if (val && (val.type === "STRING" /* STRING */ || val.type === "IDENTIFIER" /* IDENTIFIER */ || val.type === "NUMBER" /* NUMBER */)) {
|
|
1039
|
+
props[key] = next(cx).value;
|
|
1040
|
+
}
|
|
1041
|
+
} else {
|
|
1042
|
+
props[key] = true;
|
|
1043
|
+
}
|
|
1044
|
+
} else {
|
|
1045
|
+
next(cx);
|
|
1046
|
+
}
|
|
1047
|
+
skipNewlines(cx);
|
|
1048
|
+
}
|
|
1049
|
+
if (peek(cx) && peek(cx).type === "RBRACE" /* RBRACE */)
|
|
1050
|
+
next(cx);
|
|
1051
|
+
}
|
|
1052
|
+
const substate = { type: "substate", name, props };
|
|
1053
|
+
ast.substates.push(substate);
|
|
1054
|
+
ast.nodes.push(substate);
|
|
1055
|
+
onLog({ level: "info", event: "parse.substate", detail: substate });
|
|
1056
|
+
continue;
|
|
1057
|
+
}
|
|
1058
|
+
if (sym === "\u25CB") {
|
|
1059
|
+
skipNewlines(cx);
|
|
1060
|
+
let name = "class";
|
|
1061
|
+
if (peek(cx) && peek(cx).type === "IDENTIFIER" /* IDENTIFIER */) {
|
|
1062
|
+
name = next(cx).value;
|
|
1063
|
+
}
|
|
1064
|
+
let extendsClass;
|
|
1065
|
+
if (peek(cx) && peek(cx).type === "IDENTIFIER" /* IDENTIFIER */ && peek(cx).value.toLowerCase() === "extends") {
|
|
1066
|
+
next(cx);
|
|
1067
|
+
if (peek(cx) && peek(cx).type === "IDENTIFIER" /* IDENTIFIER */) {
|
|
1068
|
+
extendsClass = next(cx).value;
|
|
1069
|
+
}
|
|
1070
|
+
}
|
|
1071
|
+
const props = {};
|
|
1072
|
+
const methods = [];
|
|
1073
|
+
skipNewlines(cx);
|
|
1074
|
+
if (peek(cx) && peek(cx).type === "LBRACE" /* LBRACE */) {
|
|
1075
|
+
next(cx);
|
|
1076
|
+
skipNewlines(cx);
|
|
1077
|
+
while (peek(cx) && peek(cx).type !== "RBRACE" /* RBRACE */) {
|
|
1078
|
+
if (peek(cx).type === "IDENTIFIER" /* IDENTIFIER */) {
|
|
1079
|
+
const key = next(cx).value;
|
|
1080
|
+
if (peek(cx) && peek(cx).type === "LPAREN" /* LPAREN */) {
|
|
1081
|
+
methods.push(key);
|
|
1082
|
+
next(cx);
|
|
1083
|
+
while (peek(cx) && peek(cx).type !== "RPAREN" /* RPAREN */)
|
|
1084
|
+
next(cx);
|
|
1085
|
+
if (peek(cx))
|
|
1086
|
+
next(cx);
|
|
1087
|
+
} else if (peek(cx) && peek(cx).type === "COLON" /* COLON */) {
|
|
1088
|
+
next(cx);
|
|
1089
|
+
const val = peek(cx);
|
|
1090
|
+
if (val && (val.type === "STRING" /* STRING */ || val.type === "IDENTIFIER" /* IDENTIFIER */ || val.type === "NUMBER" /* NUMBER */)) {
|
|
1091
|
+
props[key] = next(cx).value;
|
|
1092
|
+
}
|
|
1093
|
+
} else {
|
|
1094
|
+
props[key] = true;
|
|
1095
|
+
}
|
|
1096
|
+
} else {
|
|
1097
|
+
next(cx);
|
|
1098
|
+
}
|
|
1099
|
+
skipNewlines(cx);
|
|
1100
|
+
}
|
|
1101
|
+
if (peek(cx) && peek(cx).type === "RBRACE" /* RBRACE */)
|
|
1102
|
+
next(cx);
|
|
1103
|
+
}
|
|
1104
|
+
const classNode = { type: "class", name, extends: extendsClass, props, methods };
|
|
1105
|
+
ast.classes.push(classNode);
|
|
1106
|
+
ast.nodes.push(classNode);
|
|
1107
|
+
onLog({ level: "info", event: "parse.class", detail: classNode });
|
|
1108
|
+
continue;
|
|
1109
|
+
}
|
|
1110
|
+
if (sym === "\u21BB") {
|
|
1111
|
+
skipNewlines(cx);
|
|
1112
|
+
let count;
|
|
1113
|
+
let condition;
|
|
1114
|
+
const body = [];
|
|
1115
|
+
if (peek(cx) && peek(cx).type === "NUMBER" /* NUMBER */) {
|
|
1116
|
+
count = parseInt(next(cx).value, 10);
|
|
1117
|
+
} else if (peek(cx) && peek(cx).type === "IDENTIFIER" /* IDENTIFIER */) {
|
|
1118
|
+
condition = next(cx).value;
|
|
1119
|
+
}
|
|
1120
|
+
skipNewlines(cx);
|
|
1121
|
+
if (peek(cx) && peek(cx).type === "LBRACE" /* LBRACE */) {
|
|
1122
|
+
next(cx);
|
|
1123
|
+
skipNewlines(cx);
|
|
1124
|
+
while (peek(cx) && peek(cx).type !== "RBRACE" /* RBRACE */) {
|
|
1125
|
+
if (peek(cx).type === "IDENTIFIER" /* IDENTIFIER */ || peek(cx).type === "STRING" /* STRING */) {
|
|
1126
|
+
body.push(next(cx).value);
|
|
1127
|
+
} else {
|
|
1128
|
+
next(cx);
|
|
1129
|
+
}
|
|
1130
|
+
skipNewlines(cx);
|
|
1131
|
+
}
|
|
1132
|
+
if (peek(cx) && peek(cx).type === "RBRACE" /* RBRACE */)
|
|
1133
|
+
next(cx);
|
|
1134
|
+
}
|
|
1135
|
+
const loop = { type: "loop", count, condition, body };
|
|
1136
|
+
ast.loops.push(loop);
|
|
1137
|
+
ast.nodes.push(loop);
|
|
1138
|
+
onLog({ level: "info", event: "parse.loop", detail: loop });
|
|
1139
|
+
continue;
|
|
1140
|
+
}
|
|
1141
|
+
if (sym === "\u25CC") {
|
|
1142
|
+
skipNewlines(cx);
|
|
1143
|
+
let name = "event";
|
|
1144
|
+
if (peek(cx) && (peek(cx).type === "IDENTIFIER" /* IDENTIFIER */ || peek(cx).type === "STRING" /* STRING */)) {
|
|
1145
|
+
name = next(cx).value;
|
|
1146
|
+
}
|
|
1147
|
+
const handler = [];
|
|
1148
|
+
skipNewlines(cx);
|
|
1149
|
+
while (peek(cx) && peek(cx).type === "ARROW" /* ARROW */) {
|
|
1150
|
+
next(cx);
|
|
1151
|
+
if (peek(cx) && (peek(cx).type === "IDENTIFIER" /* IDENTIFIER */ || peek(cx).type === "STRING" /* STRING */)) {
|
|
1152
|
+
handler.push(next(cx).value);
|
|
1153
|
+
}
|
|
1154
|
+
skipNewlines(cx);
|
|
1155
|
+
}
|
|
1156
|
+
const event = { type: "event", name, handler };
|
|
1157
|
+
ast.events.push(event);
|
|
1158
|
+
ast.nodes.push(event);
|
|
1159
|
+
onLog({ level: "info", event: "parse.event", detail: event });
|
|
1160
|
+
continue;
|
|
1161
|
+
}
|
|
1162
|
+
if (sym === "\u21C4") {
|
|
1163
|
+
skipNewlines(cx);
|
|
1164
|
+
const sources = [];
|
|
1165
|
+
while (peek(cx) && (peek(cx).type === "IDENTIFIER" /* IDENTIFIER */ || peek(cx).type === "STRING" /* STRING */)) {
|
|
1166
|
+
sources.push(next(cx).value);
|
|
1167
|
+
if (peek(cx) && peek(cx).type === "COMMA" /* COMMA */)
|
|
1168
|
+
next(cx);
|
|
1169
|
+
skipNewlines(cx);
|
|
1170
|
+
}
|
|
1171
|
+
const sync = { type: "sync", sources };
|
|
1172
|
+
ast.syncs.push(sync);
|
|
1173
|
+
ast.nodes.push(sync);
|
|
1174
|
+
onLog({ level: "info", event: "parse.sync", detail: sync });
|
|
1175
|
+
continue;
|
|
1176
|
+
}
|
|
1177
|
+
if (sym === "\u231B") {
|
|
1178
|
+
skipNewlines(cx);
|
|
1179
|
+
let duration = 0;
|
|
1180
|
+
let unit = "ms";
|
|
1181
|
+
if (peek(cx) && peek(cx).type === "NUMBER" /* NUMBER */) {
|
|
1182
|
+
duration = parseInt(next(cx).value, 10);
|
|
1183
|
+
}
|
|
1184
|
+
if (peek(cx) && peek(cx).type === "IDENTIFIER" /* IDENTIFIER */) {
|
|
1185
|
+
const u = peek(cx).value.toLowerCase();
|
|
1186
|
+
if (u === "ms" || u === "s" || u === "m") {
|
|
1187
|
+
unit = u;
|
|
1188
|
+
next(cx);
|
|
1189
|
+
}
|
|
1190
|
+
}
|
|
1191
|
+
const timeout = { type: "timeout", duration, unit };
|
|
1192
|
+
ast.timeouts.push(timeout);
|
|
1193
|
+
ast.nodes.push(timeout);
|
|
1194
|
+
onLog({ level: "info", event: "parse.timeout", detail: timeout });
|
|
1195
|
+
continue;
|
|
1196
|
+
}
|
|
1197
|
+
if (sym === "\u23F3") {
|
|
1198
|
+
skipNewlines(cx);
|
|
1199
|
+
let duration = 0;
|
|
1200
|
+
let unit = "ms";
|
|
1201
|
+
if (peek(cx) && peek(cx).type === "NUMBER" /* NUMBER */) {
|
|
1202
|
+
duration = parseInt(next(cx).value, 10);
|
|
1203
|
+
}
|
|
1204
|
+
if (peek(cx) && peek(cx).type === "IDENTIFIER" /* IDENTIFIER */) {
|
|
1205
|
+
const u = peek(cx).value.toLowerCase();
|
|
1206
|
+
if (u === "ms" || u === "s" || u === "m") {
|
|
1207
|
+
unit = u;
|
|
1208
|
+
next(cx);
|
|
1209
|
+
}
|
|
1210
|
+
}
|
|
1211
|
+
const delay = { type: "delay", duration, unit };
|
|
1212
|
+
ast.delays.push(delay);
|
|
1213
|
+
ast.nodes.push(delay);
|
|
1214
|
+
onLog({ level: "info", event: "parse.delay", detail: delay });
|
|
1215
|
+
continue;
|
|
1216
|
+
}
|
|
1217
|
+
if (sym === "\u{1F6E1}") {
|
|
1218
|
+
skipNewlines(cx);
|
|
1219
|
+
let level;
|
|
1220
|
+
const rules = [];
|
|
1221
|
+
if (peek(cx) && peek(cx).type === "IDENTIFIER" /* IDENTIFIER */) {
|
|
1222
|
+
const lv = peek(cx).value.toLowerCase();
|
|
1223
|
+
if (["low", "medium", "high", "critical"].includes(lv)) {
|
|
1224
|
+
level = lv;
|
|
1225
|
+
next(cx);
|
|
1226
|
+
}
|
|
1227
|
+
}
|
|
1228
|
+
skipNewlines(cx);
|
|
1229
|
+
if (peek(cx) && peek(cx).type === "LBRACE" /* LBRACE */) {
|
|
1230
|
+
next(cx);
|
|
1231
|
+
skipNewlines(cx);
|
|
1232
|
+
while (peek(cx) && peek(cx).type !== "RBRACE" /* RBRACE */) {
|
|
1233
|
+
if (peek(cx).type === "IDENTIFIER" /* IDENTIFIER */ || peek(cx).type === "STRING" /* STRING */) {
|
|
1234
|
+
rules.push(next(cx).value);
|
|
1235
|
+
} else {
|
|
1236
|
+
next(cx);
|
|
1237
|
+
}
|
|
1238
|
+
skipNewlines(cx);
|
|
1239
|
+
}
|
|
1240
|
+
if (peek(cx) && peek(cx).type === "RBRACE" /* RBRACE */)
|
|
1241
|
+
next(cx);
|
|
1242
|
+
}
|
|
1243
|
+
const security = { type: "security", level, rules };
|
|
1244
|
+
ast.securities.push(security);
|
|
1245
|
+
ast.nodes.push(security);
|
|
1246
|
+
onLog({ level: "info", event: "parse.security", detail: security });
|
|
1247
|
+
continue;
|
|
1248
|
+
}
|
|
1249
|
+
if (sym === "\u{1F511}") {
|
|
1250
|
+
skipNewlines(cx);
|
|
1251
|
+
let name = "key";
|
|
1252
|
+
if (peek(cx) && peek(cx).type === "IDENTIFIER" /* IDENTIFIER */) {
|
|
1253
|
+
name = next(cx).value;
|
|
1254
|
+
}
|
|
1255
|
+
const permissions = [];
|
|
1256
|
+
skipNewlines(cx);
|
|
1257
|
+
if (peek(cx) && peek(cx).type === "LBRACE" /* LBRACE */) {
|
|
1258
|
+
next(cx);
|
|
1259
|
+
skipNewlines(cx);
|
|
1260
|
+
while (peek(cx) && peek(cx).type !== "RBRACE" /* RBRACE */) {
|
|
1261
|
+
if (peek(cx).type === "IDENTIFIER" /* IDENTIFIER */ || peek(cx).type === "STRING" /* STRING */) {
|
|
1262
|
+
permissions.push(next(cx).value);
|
|
1263
|
+
} else {
|
|
1264
|
+
next(cx);
|
|
1265
|
+
}
|
|
1266
|
+
skipNewlines(cx);
|
|
1267
|
+
}
|
|
1268
|
+
if (peek(cx) && peek(cx).type === "RBRACE" /* RBRACE */)
|
|
1269
|
+
next(cx);
|
|
1270
|
+
}
|
|
1271
|
+
const key = { type: "key", name, permissions };
|
|
1272
|
+
ast.keys.push(key);
|
|
1273
|
+
ast.nodes.push(key);
|
|
1274
|
+
onLog({ level: "info", event: "parse.key", detail: key });
|
|
1275
|
+
continue;
|
|
1276
|
+
}
|
|
1277
|
+
if (sym === "\u{1F9EA}") {
|
|
1278
|
+
skipNewlines(cx);
|
|
1279
|
+
let name = "sandbox";
|
|
1280
|
+
if (peek(cx) && peek(cx).type === "IDENTIFIER" /* IDENTIFIER */) {
|
|
1281
|
+
name = next(cx).value;
|
|
1282
|
+
}
|
|
1283
|
+
const body = [];
|
|
1284
|
+
skipNewlines(cx);
|
|
1285
|
+
if (peek(cx) && peek(cx).type === "LBRACE" /* LBRACE */) {
|
|
1286
|
+
next(cx);
|
|
1287
|
+
skipNewlines(cx);
|
|
1288
|
+
while (peek(cx) && peek(cx).type !== "RBRACE" /* RBRACE */) {
|
|
1289
|
+
if (peek(cx).type === "IDENTIFIER" /* IDENTIFIER */ || peek(cx).type === "STRING" /* STRING */) {
|
|
1290
|
+
body.push(next(cx).value);
|
|
1291
|
+
} else {
|
|
1292
|
+
next(cx);
|
|
1293
|
+
}
|
|
1294
|
+
skipNewlines(cx);
|
|
1295
|
+
}
|
|
1296
|
+
if (peek(cx) && peek(cx).type === "RBRACE" /* RBRACE */)
|
|
1297
|
+
next(cx);
|
|
1298
|
+
}
|
|
1299
|
+
const sandbox = { type: "sandbox", name, body };
|
|
1300
|
+
ast.sandboxes.push(sandbox);
|
|
1301
|
+
ast.nodes.push(sandbox);
|
|
1302
|
+
onLog({ level: "info", event: "parse.sandbox", detail: sandbox });
|
|
1303
|
+
continue;
|
|
1304
|
+
}
|
|
1305
|
+
if (sym === "\u26A1") {
|
|
1306
|
+
skipNewlines(cx);
|
|
1307
|
+
let trigger = "";
|
|
1308
|
+
if (peek(cx) && (peek(cx).type === "IDENTIFIER" /* IDENTIFIER */ || peek(cx).type === "STRING" /* STRING */)) {
|
|
1309
|
+
trigger = next(cx).value;
|
|
1310
|
+
}
|
|
1311
|
+
const effects = [];
|
|
1312
|
+
skipNewlines(cx);
|
|
1313
|
+
while (peek(cx) && peek(cx).type === "ARROW" /* ARROW */) {
|
|
1314
|
+
next(cx);
|
|
1315
|
+
if (peek(cx) && (peek(cx).type === "IDENTIFIER" /* IDENTIFIER */ || peek(cx).type === "STRING" /* STRING */)) {
|
|
1316
|
+
effects.push(next(cx).value);
|
|
1317
|
+
}
|
|
1318
|
+
skipNewlines(cx);
|
|
1319
|
+
}
|
|
1320
|
+
const cause = { type: "cause", trigger, effects };
|
|
1321
|
+
ast.causes.push(cause);
|
|
1322
|
+
ast.nodes.push(cause);
|
|
1323
|
+
onLog({ level: "info", event: "parse.cause", detail: cause });
|
|
1324
|
+
continue;
|
|
1325
|
+
}
|
|
1326
|
+
if (sym === "\u2726") {
|
|
1327
|
+
skipNewlines(cx);
|
|
1328
|
+
let source = "";
|
|
1329
|
+
let result = "";
|
|
1330
|
+
if (peek(cx) && (peek(cx).type === "IDENTIFIER" /* IDENTIFIER */ || peek(cx).type === "STRING" /* STRING */)) {
|
|
1331
|
+
source = next(cx).value;
|
|
1332
|
+
}
|
|
1333
|
+
skipNewlines(cx);
|
|
1334
|
+
if (peek(cx) && peek(cx).type === "ARROW" /* ARROW */) {
|
|
1335
|
+
next(cx);
|
|
1336
|
+
if (peek(cx) && (peek(cx).type === "IDENTIFIER" /* IDENTIFIER */ || peek(cx).type === "STRING" /* STRING */)) {
|
|
1337
|
+
result = next(cx).value;
|
|
1338
|
+
}
|
|
1339
|
+
}
|
|
1340
|
+
const consequence = { type: "consequence", source, result };
|
|
1341
|
+
ast.consequences.push(consequence);
|
|
1342
|
+
ast.nodes.push(consequence);
|
|
1343
|
+
onLog({ level: "info", event: "parse.consequence", detail: consequence });
|
|
1344
|
+
continue;
|
|
1345
|
+
}
|
|
1346
|
+
if (sym === "\u{1D4DC}") {
|
|
1347
|
+
skipNewlines(cx);
|
|
1348
|
+
let name = "memory";
|
|
1349
|
+
if (peek(cx) && peek(cx).type === "IDENTIFIER" /* IDENTIFIER */) {
|
|
1350
|
+
name = next(cx).value;
|
|
1351
|
+
}
|
|
1352
|
+
let size;
|
|
1353
|
+
let persist = false;
|
|
1354
|
+
skipNewlines(cx);
|
|
1355
|
+
if (peek(cx) && peek(cx).type === "NUMBER" /* NUMBER */) {
|
|
1356
|
+
size = parseInt(next(cx).value, 10);
|
|
1357
|
+
}
|
|
1358
|
+
if (peek(cx) && peek(cx).type === "IDENTIFIER" /* IDENTIFIER */ && peek(cx).value.toLowerCase() === "persist") {
|
|
1359
|
+
persist = true;
|
|
1360
|
+
next(cx);
|
|
1361
|
+
}
|
|
1362
|
+
const memory = { type: "memory", name, size, persist };
|
|
1363
|
+
ast.memories.push(memory);
|
|
1364
|
+
ast.nodes.push(memory);
|
|
1365
|
+
onLog({ level: "info", event: "parse.memory", detail: memory });
|
|
1366
|
+
continue;
|
|
1367
|
+
}
|
|
1368
|
+
if (sym === "\u267E") {
|
|
1369
|
+
skipNewlines(cx);
|
|
1370
|
+
let target = "";
|
|
1371
|
+
let storage;
|
|
1372
|
+
if (peek(cx) && (peek(cx).type === "IDENTIFIER" /* IDENTIFIER */ || peek(cx).type === "STRING" /* STRING */)) {
|
|
1373
|
+
target = next(cx).value;
|
|
1374
|
+
}
|
|
1375
|
+
skipNewlines(cx);
|
|
1376
|
+
if (peek(cx) && peek(cx).type === "IDENTIFIER" /* IDENTIFIER */) {
|
|
1377
|
+
const s = peek(cx).value.toLowerCase();
|
|
1378
|
+
if (["local", "session", "db", "file"].includes(s)) {
|
|
1379
|
+
storage = s;
|
|
1380
|
+
next(cx);
|
|
1381
|
+
}
|
|
1382
|
+
}
|
|
1383
|
+
const persist = { type: "persist", target, storage };
|
|
1384
|
+
ast.persists.push(persist);
|
|
1385
|
+
ast.nodes.push(persist);
|
|
1386
|
+
onLog({ level: "info", event: "parse.persist", detail: persist });
|
|
1387
|
+
continue;
|
|
1388
|
+
}
|
|
1389
|
+
if (sym === "\u2302") {
|
|
1390
|
+
skipNewlines(cx);
|
|
1391
|
+
let name = "root";
|
|
1392
|
+
if (peek(cx) && peek(cx).type === "IDENTIFIER" /* IDENTIFIER */) {
|
|
1393
|
+
name = next(cx).value;
|
|
1394
|
+
}
|
|
1395
|
+
const children = [];
|
|
1396
|
+
skipNewlines(cx);
|
|
1397
|
+
if (peek(cx) && peek(cx).type === "LBRACE" /* LBRACE */) {
|
|
1398
|
+
next(cx);
|
|
1399
|
+
skipNewlines(cx);
|
|
1400
|
+
while (peek(cx) && peek(cx).type !== "RBRACE" /* RBRACE */) {
|
|
1401
|
+
if (peek(cx).type === "IDENTIFIER" /* IDENTIFIER */ || peek(cx).type === "STRING" /* STRING */) {
|
|
1402
|
+
children.push(next(cx).value);
|
|
1403
|
+
} else {
|
|
1404
|
+
next(cx);
|
|
1405
|
+
}
|
|
1406
|
+
skipNewlines(cx);
|
|
1407
|
+
}
|
|
1408
|
+
if (peek(cx) && peek(cx).type === "RBRACE" /* RBRACE */)
|
|
1409
|
+
next(cx);
|
|
1410
|
+
}
|
|
1411
|
+
const root = { type: "root", name, children };
|
|
1412
|
+
ast.roots.push(root);
|
|
1413
|
+
ast.nodes.push(root);
|
|
1414
|
+
onLog({ level: "info", event: "parse.root", detail: root });
|
|
1415
|
+
continue;
|
|
1416
|
+
}
|
|
1417
|
+
if (sym === "\u2610") {
|
|
1418
|
+
skipNewlines(cx);
|
|
1419
|
+
let name = "interface";
|
|
1420
|
+
if (peek(cx) && peek(cx).type === "IDENTIFIER" /* IDENTIFIER */) {
|
|
1421
|
+
name = next(cx).value;
|
|
1422
|
+
}
|
|
1423
|
+
const methods = [];
|
|
1424
|
+
skipNewlines(cx);
|
|
1425
|
+
if (peek(cx) && peek(cx).type === "LBRACE" /* LBRACE */) {
|
|
1426
|
+
next(cx);
|
|
1427
|
+
skipNewlines(cx);
|
|
1428
|
+
while (peek(cx) && peek(cx).type !== "RBRACE" /* RBRACE */) {
|
|
1429
|
+
if (peek(cx).type === "IDENTIFIER" /* IDENTIFIER */) {
|
|
1430
|
+
methods.push(next(cx).value);
|
|
1431
|
+
} else {
|
|
1432
|
+
next(cx);
|
|
1433
|
+
}
|
|
1434
|
+
skipNewlines(cx);
|
|
1435
|
+
}
|
|
1436
|
+
if (peek(cx) && peek(cx).type === "RBRACE" /* RBRACE */)
|
|
1437
|
+
next(cx);
|
|
1438
|
+
}
|
|
1439
|
+
const iface = { type: "interface", name, methods };
|
|
1440
|
+
ast.interfaces.push(iface);
|
|
1441
|
+
ast.nodes.push(iface);
|
|
1442
|
+
onLog({ level: "info", event: "parse.interface", detail: iface });
|
|
1443
|
+
continue;
|
|
1444
|
+
}
|
|
1445
|
+
if (sym === "\u{1F441}") {
|
|
1446
|
+
skipNewlines(cx);
|
|
1447
|
+
let name = "visual";
|
|
1448
|
+
if (peek(cx) && peek(cx).type === "IDENTIFIER" /* IDENTIFIER */) {
|
|
1449
|
+
name = next(cx).value;
|
|
1450
|
+
}
|
|
1451
|
+
const props = {};
|
|
1452
|
+
skipNewlines(cx);
|
|
1453
|
+
if (peek(cx) && peek(cx).type === "LBRACE" /* LBRACE */) {
|
|
1454
|
+
next(cx);
|
|
1455
|
+
skipNewlines(cx);
|
|
1456
|
+
while (peek(cx) && peek(cx).type !== "RBRACE" /* RBRACE */) {
|
|
1457
|
+
if (peek(cx).type === "IDENTIFIER" /* IDENTIFIER */) {
|
|
1458
|
+
const key = next(cx).value;
|
|
1459
|
+
if (peek(cx) && peek(cx).type === "COLON" /* COLON */) {
|
|
1460
|
+
next(cx);
|
|
1461
|
+
const val = peek(cx);
|
|
1462
|
+
if (val && (val.type === "STRING" /* STRING */ || val.type === "IDENTIFIER" /* IDENTIFIER */ || val.type === "NUMBER" /* NUMBER */)) {
|
|
1463
|
+
props[key] = next(cx).value;
|
|
1464
|
+
}
|
|
1465
|
+
} else {
|
|
1466
|
+
props[key] = true;
|
|
1467
|
+
}
|
|
1468
|
+
} else {
|
|
1469
|
+
next(cx);
|
|
1470
|
+
}
|
|
1471
|
+
skipNewlines(cx);
|
|
1472
|
+
}
|
|
1473
|
+
if (peek(cx) && peek(cx).type === "RBRACE" /* RBRACE */)
|
|
1474
|
+
next(cx);
|
|
1475
|
+
}
|
|
1476
|
+
const visual = { type: "visual", name, props };
|
|
1477
|
+
ast.visuals.push(visual);
|
|
1478
|
+
ast.nodes.push(visual);
|
|
1479
|
+
onLog({ level: "info", event: "parse.visual", detail: visual });
|
|
1480
|
+
continue;
|
|
1481
|
+
}
|
|
1482
|
+
if (sym === "\u2328") {
|
|
1483
|
+
skipNewlines(cx);
|
|
1484
|
+
let name = "input";
|
|
1485
|
+
let inputType = "text";
|
|
1486
|
+
if (peek(cx) && peek(cx).type === "IDENTIFIER" /* IDENTIFIER */) {
|
|
1487
|
+
name = next(cx).value;
|
|
1488
|
+
}
|
|
1489
|
+
skipNewlines(cx);
|
|
1490
|
+
if (peek(cx) && peek(cx).type === "IDENTIFIER" /* IDENTIFIER */) {
|
|
1491
|
+
const t2 = peek(cx).value.toLowerCase();
|
|
1492
|
+
if (["text", "number", "file", "event"].includes(t2)) {
|
|
1493
|
+
inputType = t2;
|
|
1494
|
+
next(cx);
|
|
1495
|
+
}
|
|
1496
|
+
}
|
|
1497
|
+
const input = { type: "input", name, inputType };
|
|
1498
|
+
ast.inputs.push(input);
|
|
1499
|
+
ast.nodes.push(input);
|
|
1500
|
+
onLog({ level: "info", event: "parse.input", detail: input });
|
|
1501
|
+
continue;
|
|
1502
|
+
}
|
|
1503
|
+
if (sym === "\u23EC") {
|
|
1504
|
+
skipNewlines(cx);
|
|
1505
|
+
let target = "";
|
|
1506
|
+
let limit = 0;
|
|
1507
|
+
if (peek(cx) && peek(cx).type === "IDENTIFIER" /* IDENTIFIER */) {
|
|
1508
|
+
target = next(cx).value;
|
|
1509
|
+
}
|
|
1510
|
+
skipNewlines(cx);
|
|
1511
|
+
if (peek(cx) && peek(cx).type === "NUMBER" /* NUMBER */) {
|
|
1512
|
+
limit = parseInt(next(cx).value, 10);
|
|
1513
|
+
}
|
|
1514
|
+
const throttle = { type: "throttle", target, limit };
|
|
1515
|
+
ast.throttles.push(throttle);
|
|
1516
|
+
ast.nodes.push(throttle);
|
|
1517
|
+
onLog({ level: "info", event: "parse.throttle", detail: throttle });
|
|
1518
|
+
continue;
|
|
1519
|
+
}
|
|
1520
|
+
if (sym === "\u23EB") {
|
|
1521
|
+
skipNewlines(cx);
|
|
1522
|
+
let target = "";
|
|
1523
|
+
let factor;
|
|
1524
|
+
if (peek(cx) && peek(cx).type === "IDENTIFIER" /* IDENTIFIER */) {
|
|
1525
|
+
target = next(cx).value;
|
|
1526
|
+
}
|
|
1527
|
+
skipNewlines(cx);
|
|
1528
|
+
if (peek(cx) && peek(cx).type === "NUMBER" /* NUMBER */) {
|
|
1529
|
+
factor = parseFloat(next(cx).value);
|
|
1530
|
+
}
|
|
1531
|
+
const boost = { type: "boost", target, factor };
|
|
1532
|
+
ast.boosts.push(boost);
|
|
1533
|
+
ast.nodes.push(boost);
|
|
1534
|
+
onLog({ level: "info", event: "parse.boost", detail: boost });
|
|
1535
|
+
continue;
|
|
1536
|
+
}
|
|
1537
|
+
if (sym === "\u20B5") {
|
|
1538
|
+
skipNewlines(cx);
|
|
1539
|
+
let operation = "";
|
|
1540
|
+
let value = 0;
|
|
1541
|
+
if (peek(cx) && peek(cx).type === "IDENTIFIER" /* IDENTIFIER */) {
|
|
1542
|
+
operation = next(cx).value;
|
|
1543
|
+
}
|
|
1544
|
+
skipNewlines(cx);
|
|
1545
|
+
if (peek(cx) && peek(cx).type === "NUMBER" /* NUMBER */) {
|
|
1546
|
+
value = parseFloat(next(cx).value);
|
|
1547
|
+
}
|
|
1548
|
+
const cost = { type: "cost", operation, value };
|
|
1549
|
+
ast.costs.push(cost);
|
|
1550
|
+
ast.nodes.push(cost);
|
|
1551
|
+
onLog({ level: "info", event: "parse.cost", detail: cost });
|
|
1552
|
+
continue;
|
|
1553
|
+
}
|
|
1554
|
+
if (sym === "\u{1F512}") {
|
|
1555
|
+
skipNewlines(cx);
|
|
1556
|
+
let target = "";
|
|
1557
|
+
if (peek(cx) && (peek(cx).type === "IDENTIFIER" /* IDENTIFIER */ || peek(cx).type === "STRING" /* STRING */)) {
|
|
1558
|
+
target = next(cx).value;
|
|
1559
|
+
}
|
|
1560
|
+
const lock = { type: "lock", target };
|
|
1561
|
+
ast.locks.push(lock);
|
|
1562
|
+
ast.nodes.push(lock);
|
|
1563
|
+
onLog({ level: "info", event: "parse.lock", detail: lock });
|
|
1564
|
+
continue;
|
|
1565
|
+
}
|
|
1566
|
+
if (sym === "\u{1F513}") {
|
|
1567
|
+
skipNewlines(cx);
|
|
1568
|
+
let target = "";
|
|
1569
|
+
if (peek(cx) && (peek(cx).type === "IDENTIFIER" /* IDENTIFIER */ || peek(cx).type === "STRING" /* STRING */)) {
|
|
1570
|
+
target = next(cx).value;
|
|
1571
|
+
}
|
|
1572
|
+
const unlock = { type: "unlock", target };
|
|
1573
|
+
ast.unlocks.push(unlock);
|
|
1574
|
+
ast.nodes.push(unlock);
|
|
1575
|
+
onLog({ level: "info", event: "parse.unlock", detail: unlock });
|
|
1576
|
+
continue;
|
|
1577
|
+
}
|
|
1578
|
+
if (sym === "\xD8") {
|
|
1579
|
+
skipNewlines(cx);
|
|
1580
|
+
let target;
|
|
1581
|
+
if (peek(cx) && (peek(cx).type === "IDENTIFIER" /* IDENTIFIER */ || peek(cx).type === "STRING" /* STRING */)) {
|
|
1582
|
+
target = next(cx).value;
|
|
1583
|
+
}
|
|
1584
|
+
const voidNode = { type: "void", target };
|
|
1585
|
+
ast.voids.push(voidNode);
|
|
1586
|
+
ast.nodes.push(voidNode);
|
|
1587
|
+
onLog({ level: "info", event: "parse.void", detail: voidNode });
|
|
1588
|
+
continue;
|
|
1589
|
+
}
|
|
1590
|
+
if (sym === "\u2B12") {
|
|
1591
|
+
skipNewlines(cx);
|
|
1592
|
+
let child = "";
|
|
1593
|
+
let parent = "";
|
|
1594
|
+
if (peek(cx) && peek(cx).type === "IDENTIFIER" /* IDENTIFIER */) {
|
|
1595
|
+
child = next(cx).value;
|
|
1596
|
+
}
|
|
1597
|
+
skipNewlines(cx);
|
|
1598
|
+
if (peek(cx) && peek(cx).type === "ARROW" /* ARROW */) {
|
|
1599
|
+
next(cx);
|
|
1600
|
+
if (peek(cx) && peek(cx).type === "IDENTIFIER" /* IDENTIFIER */) {
|
|
1601
|
+
parent = next(cx).value;
|
|
1602
|
+
}
|
|
1603
|
+
}
|
|
1604
|
+
const inherit = { type: "inherit", child, parent };
|
|
1605
|
+
ast.inherits.push(inherit);
|
|
1606
|
+
ast.nodes.push(inherit);
|
|
1607
|
+
onLog({ level: "info", event: "parse.inherit", detail: inherit });
|
|
1608
|
+
continue;
|
|
1609
|
+
}
|
|
1610
|
+
if (sym === "\u2283") {
|
|
1611
|
+
skipNewlines(cx);
|
|
1612
|
+
let container = "";
|
|
1613
|
+
const items = [];
|
|
1614
|
+
if (peek(cx) && peek(cx).type === "IDENTIFIER" /* IDENTIFIER */) {
|
|
1615
|
+
container = next(cx).value;
|
|
1616
|
+
}
|
|
1617
|
+
skipNewlines(cx);
|
|
1618
|
+
if (peek(cx) && peek(cx).type === "LBRACE" /* LBRACE */) {
|
|
1619
|
+
next(cx);
|
|
1620
|
+
skipNewlines(cx);
|
|
1621
|
+
while (peek(cx) && peek(cx).type !== "RBRACE" /* RBRACE */) {
|
|
1622
|
+
if (peek(cx).type === "IDENTIFIER" /* IDENTIFIER */ || peek(cx).type === "STRING" /* STRING */) {
|
|
1623
|
+
items.push(next(cx).value);
|
|
1624
|
+
} else {
|
|
1625
|
+
next(cx);
|
|
1626
|
+
}
|
|
1627
|
+
skipNewlines(cx);
|
|
1628
|
+
}
|
|
1629
|
+
if (peek(cx) && peek(cx).type === "RBRACE" /* RBRACE */)
|
|
1630
|
+
next(cx);
|
|
1631
|
+
}
|
|
1632
|
+
const contains = { type: "contains", container, items };
|
|
1633
|
+
ast.contains.push(contains);
|
|
1634
|
+
ast.nodes.push(contains);
|
|
1635
|
+
onLog({ level: "info", event: "parse.contains", detail: contains });
|
|
1636
|
+
continue;
|
|
1637
|
+
}
|
|
1638
|
+
if (sym === "\u2714") {
|
|
1639
|
+
skipNewlines(cx);
|
|
1640
|
+
let target = "";
|
|
1641
|
+
const rules = [];
|
|
1642
|
+
if (peek(cx) && (peek(cx).type === "IDENTIFIER" /* IDENTIFIER */ || peek(cx).type === "STRING" /* STRING */)) {
|
|
1643
|
+
target = next(cx).value;
|
|
1644
|
+
}
|
|
1645
|
+
skipNewlines(cx);
|
|
1646
|
+
if (peek(cx) && peek(cx).type === "LBRACE" /* LBRACE */) {
|
|
1647
|
+
next(cx);
|
|
1648
|
+
skipNewlines(cx);
|
|
1649
|
+
while (peek(cx) && peek(cx).type !== "RBRACE" /* RBRACE */) {
|
|
1650
|
+
if (peek(cx).type === "IDENTIFIER" /* IDENTIFIER */ || peek(cx).type === "STRING" /* STRING */) {
|
|
1651
|
+
rules.push(next(cx).value);
|
|
1652
|
+
} else {
|
|
1653
|
+
next(cx);
|
|
1654
|
+
}
|
|
1655
|
+
skipNewlines(cx);
|
|
1656
|
+
}
|
|
1657
|
+
if (peek(cx) && peek(cx).type === "RBRACE" /* RBRACE */)
|
|
1658
|
+
next(cx);
|
|
1659
|
+
}
|
|
1660
|
+
const verify = { type: "verify", target, rules };
|
|
1661
|
+
ast.verifies.push(verify);
|
|
1662
|
+
ast.nodes.push(verify);
|
|
1663
|
+
onLog({ level: "info", event: "parse.verify", detail: verify });
|
|
1664
|
+
continue;
|
|
1665
|
+
}
|
|
1666
|
+
if (sym === "\u{1F4DC}") {
|
|
1667
|
+
skipNewlines(cx);
|
|
1668
|
+
let message = "";
|
|
1669
|
+
let level = "info";
|
|
1670
|
+
if (peek(cx) && (peek(cx).type === "STRING" /* STRING */ || peek(cx).type === "IDENTIFIER" /* IDENTIFIER */)) {
|
|
1671
|
+
message = next(cx).value;
|
|
1672
|
+
}
|
|
1673
|
+
skipNewlines(cx);
|
|
1674
|
+
if (peek(cx) && peek(cx).type === "IDENTIFIER" /* IDENTIFIER */) {
|
|
1675
|
+
const lv = peek(cx).value.toLowerCase();
|
|
1676
|
+
if (["debug", "info", "warn", "error"].includes(lv)) {
|
|
1677
|
+
level = lv;
|
|
1678
|
+
next(cx);
|
|
1679
|
+
}
|
|
1680
|
+
}
|
|
1681
|
+
const logNode = { type: "log", message, level };
|
|
1682
|
+
ast.logNodes.push(logNode);
|
|
1683
|
+
ast.nodes.push(logNode);
|
|
1684
|
+
onLog({ level: "info", event: "parse.log", detail: logNode });
|
|
1685
|
+
continue;
|
|
1686
|
+
}
|
|
1687
|
+
if (sym === "\u27F3") {
|
|
1688
|
+
skipNewlines(cx);
|
|
1689
|
+
const steps = [];
|
|
1690
|
+
if (peek(cx) && peek(cx).type === "LBRACE" /* LBRACE */) {
|
|
1691
|
+
next(cx);
|
|
1692
|
+
skipNewlines(cx);
|
|
1693
|
+
while (peek(cx) && peek(cx).type !== "RBRACE" /* RBRACE */) {
|
|
1694
|
+
if (peek(cx).type === "IDENTIFIER" /* IDENTIFIER */ || peek(cx).type === "STRING" /* STRING */) {
|
|
1695
|
+
steps.push(next(cx).value);
|
|
1696
|
+
} else {
|
|
1697
|
+
next(cx);
|
|
1698
|
+
}
|
|
1699
|
+
skipNewlines(cx);
|
|
1700
|
+
}
|
|
1701
|
+
if (peek(cx) && peek(cx).type === "RBRACE" /* RBRACE */)
|
|
1702
|
+
next(cx);
|
|
1703
|
+
} else if (peek(cx) && (peek(cx).type === "IDENTIFIER" /* IDENTIFIER */ || peek(cx).type === "STRING" /* STRING */)) {
|
|
1704
|
+
steps.push(next(cx).value);
|
|
1705
|
+
}
|
|
1706
|
+
const ev = { type: "evolve", steps };
|
|
1707
|
+
ast.evolve = ev;
|
|
1708
|
+
ast.nodes.push(ev);
|
|
1709
|
+
onLog({ level: "info", event: "parse.evolve", detail: ev });
|
|
1710
|
+
continue;
|
|
1711
|
+
}
|
|
1712
|
+
if (sym === "\u25A0") {
|
|
1713
|
+
skipNewlines(cx);
|
|
1714
|
+
const nameTok = peek(cx);
|
|
1715
|
+
if (!nameTok || nameTok.type !== "IDENTIFIER" /* IDENTIFIER */) {
|
|
1716
|
+
skipNewlines(cx);
|
|
1717
|
+
continue;
|
|
1718
|
+
}
|
|
1719
|
+
const name = next(cx).value;
|
|
1720
|
+
const props = {};
|
|
1721
|
+
skipNewlines(cx);
|
|
1722
|
+
if (peek(cx) && peek(cx).type === "LBRACE" /* LBRACE */) {
|
|
1723
|
+
next(cx);
|
|
1724
|
+
skipNewlines(cx);
|
|
1725
|
+
while (peek(cx) && peek(cx).type !== "RBRACE" /* RBRACE */) {
|
|
1726
|
+
const p = peek(cx);
|
|
1727
|
+
if (p && p.type === "IDENTIFIER" /* IDENTIFIER */) {
|
|
1728
|
+
const key = next(cx).value;
|
|
1729
|
+
if (peek(cx) && peek(cx).type === "COLON" /* COLON */) {
|
|
1730
|
+
next(cx);
|
|
1731
|
+
const val = peek(cx);
|
|
1732
|
+
if (val && (val.type === "STRING" /* STRING */ || val.type === "IDENTIFIER" /* IDENTIFIER */ || val.type === "NUMBER" /* NUMBER */)) {
|
|
1733
|
+
props[key] = next(cx).value;
|
|
1734
|
+
} else {
|
|
1735
|
+
props[key] = null;
|
|
1736
|
+
}
|
|
1737
|
+
} else {
|
|
1738
|
+
props[key] = null;
|
|
1739
|
+
}
|
|
1740
|
+
} else {
|
|
1741
|
+
next(cx);
|
|
1742
|
+
}
|
|
1743
|
+
skipNewlines(cx);
|
|
1744
|
+
}
|
|
1745
|
+
if (peek(cx) && peek(cx).type === "RBRACE" /* RBRACE */)
|
|
1746
|
+
next(cx);
|
|
1747
|
+
}
|
|
1748
|
+
const obj = { type: "object", name, props };
|
|
1749
|
+
ast.objects.push(obj);
|
|
1750
|
+
ast.nodes.push(obj);
|
|
1751
|
+
onLog({ level: "info", event: "parse.object", detail: obj });
|
|
1752
|
+
continue;
|
|
1753
|
+
}
|
|
1754
|
+
skipNewlines(cx);
|
|
1755
|
+
continue;
|
|
1756
|
+
}
|
|
1757
|
+
if (t.type === "SYMBOL" /* SYMBOL */ && t.value === "\u0394") {
|
|
1758
|
+
next(cx);
|
|
1759
|
+
}
|
|
1760
|
+
if (t.type === "IDENTIFIER" /* IDENTIFIER */ && t.value.toLowerCase() === "\u0394") {
|
|
1761
|
+
next(cx);
|
|
1762
|
+
continue;
|
|
1763
|
+
}
|
|
1764
|
+
if (t.type === "IDENTIFIER" /* IDENTIFIER */) {
|
|
1765
|
+
const val = t.value.toLowerCase();
|
|
1766
|
+
next(cx);
|
|
1767
|
+
skipNewlines(cx);
|
|
1768
|
+
continue;
|
|
1769
|
+
}
|
|
1770
|
+
next(cx);
|
|
1771
|
+
skipNewlines(cx);
|
|
1772
|
+
}
|
|
1773
|
+
return ast;
|
|
1774
|
+
}
|
|
1775
|
+
function parseFromCode(code, options) {
|
|
1776
|
+
const tokens = tokenize(code);
|
|
1777
|
+
return parseTokens(tokens, options);
|
|
1778
|
+
}
|
|
1779
|
+
|
|
1780
|
+
// src/parser.ts
|
|
1781
|
+
async function writeWithRetry(entry, filePath, attempts = 3, delay = 1e3, onLog) {
|
|
1782
|
+
const fsPromises = await import("fs/promises");
|
|
1783
|
+
let attempt = 0;
|
|
1784
|
+
const tryWrite = async () => {
|
|
1785
|
+
attempt++;
|
|
1786
|
+
try {
|
|
1787
|
+
await fsPromises.appendFile(filePath, JSON.stringify(entry) + "\n", { encoding: "utf8" });
|
|
1788
|
+
if (onLog)
|
|
1789
|
+
onLog({ timestamp: (/* @__PURE__ */ new Date()).toISOString(), level: "info", event: "logfile.write.success", detail: { file: filePath } });
|
|
1790
|
+
return;
|
|
1791
|
+
} catch (err) {
|
|
1792
|
+
const errEntry = { timestamp: (/* @__PURE__ */ new Date()).toISOString(), level: "warn", event: "logfile.write.retry", detail: { attempt, error: String(err) } };
|
|
1793
|
+
if (onLog)
|
|
1794
|
+
onLog(errEntry);
|
|
1795
|
+
if (attempt < attempts) {
|
|
1796
|
+
setTimeout(() => {
|
|
1797
|
+
tryWrite().catch(() => {
|
|
1798
|
+
});
|
|
1799
|
+
}, delay);
|
|
1800
|
+
} else {
|
|
1801
|
+
const fatal = { timestamp: (/* @__PURE__ */ new Date()).toISOString(), level: "error", event: "logfile.write.fatal", detail: { attempt, error: String(err) } };
|
|
1802
|
+
if (onLog)
|
|
1803
|
+
onLog(fatal);
|
|
1804
|
+
}
|
|
1805
|
+
}
|
|
1806
|
+
};
|
|
1807
|
+
tryWrite().catch(() => {
|
|
1808
|
+
});
|
|
1809
|
+
}
|
|
1810
|
+
function parse(code, options) {
|
|
1811
|
+
const ast = parseFromCode(code, options);
|
|
1812
|
+
ast.logs = ast.logs || [];
|
|
1813
|
+
return ast;
|
|
1814
|
+
}
|
|
1815
|
+
|
|
1816
|
+
// src/runENY.ts
|
|
1817
|
+
function runENY(code, options) {
|
|
1818
|
+
const hasSystem = /Σ\s+SYSTEM/i.test(code);
|
|
1819
|
+
if (!hasSystem) {
|
|
1820
|
+
if (options?.onLog) {
|
|
1821
|
+
options.onLog({ timestamp: (/* @__PURE__ */ new Date()).toISOString(), level: "warn", event: "runENY.no-system", detail: { length: code.length } });
|
|
1822
|
+
}
|
|
1823
|
+
if (options?.logFile) {
|
|
1824
|
+
const attempts = options?.logRetryAttempts ?? 3;
|
|
1825
|
+
const delay = options?.logRetryDelayMs ?? 1e3;
|
|
1826
|
+
writeWithRetry({ timestamp: (/* @__PURE__ */ new Date()).toISOString(), level: "warn", event: "runENY.no-system", detail: { length: code.length } }, options.logFile, attempts, delay, options?.onLog);
|
|
1827
|
+
}
|
|
1828
|
+
return { raw: code, isEny: false, logs: [] };
|
|
1829
|
+
}
|
|
1830
|
+
const userOnLog = options?.onLog;
|
|
1831
|
+
let wrappedOnLog = userOnLog;
|
|
1832
|
+
if (options?.logFile) {
|
|
1833
|
+
const attempts = options?.logRetryAttempts ?? 3;
|
|
1834
|
+
const delay = options?.logRetryDelayMs ?? 1e3;
|
|
1835
|
+
wrappedOnLog = (e) => {
|
|
1836
|
+
if (userOnLog)
|
|
1837
|
+
userOnLog(e);
|
|
1838
|
+
writeWithRetry(e, options.logFile, attempts, delay, userOnLog);
|
|
1839
|
+
};
|
|
1840
|
+
}
|
|
1841
|
+
const ast = parse(code, { ...options, onLog: wrappedOnLog });
|
|
1842
|
+
try {
|
|
1843
|
+
const errors = validateSemantic(ast, { onLog: wrappedOnLog });
|
|
1844
|
+
if (errors && errors.length > 0) {
|
|
1845
|
+
if (options?.onLog)
|
|
1846
|
+
options.onLog({ timestamp: (/* @__PURE__ */ new Date()).toISOString(), level: "warn", event: "parse.semantic.summary", detail: { count: errors.length } });
|
|
1847
|
+
}
|
|
1848
|
+
} catch (err) {
|
|
1849
|
+
if (wrappedOnLog)
|
|
1850
|
+
wrappedOnLog({ timestamp: (/* @__PURE__ */ new Date()).toISOString(), level: "error", event: "parse.semantic.failed", detail: { error: String(err) } });
|
|
1851
|
+
}
|
|
1852
|
+
if (ast.evolve && ast.evolve.steps && ast.evolve.steps.length > 0) {
|
|
1853
|
+
try {
|
|
1854
|
+
const evolveResult = applyEvolve(ast, { onLog: wrappedOnLog });
|
|
1855
|
+
if (evolveResult.changed && wrappedOnLog) {
|
|
1856
|
+
wrappedOnLog({ timestamp: (/* @__PURE__ */ new Date()).toISOString(), level: "info", event: "parse.evolve.summary", detail: { changed: true, stepsApplied: ast.evolve.steps.length } });
|
|
1857
|
+
}
|
|
1858
|
+
} catch (err) {
|
|
1859
|
+
if (wrappedOnLog)
|
|
1860
|
+
wrappedOnLog({ timestamp: (/* @__PURE__ */ new Date()).toISOString(), level: "error", event: "parse.evolve.failed", detail: { error: String(err) } });
|
|
1861
|
+
}
|
|
1862
|
+
}
|
|
1863
|
+
ast.isEny = true;
|
|
1864
|
+
return ast;
|
|
1865
|
+
}
|
|
1866
|
+
|
|
1867
|
+
// src/transpile.ts
|
|
1868
|
+
function transpileToJS(ast, options) {
|
|
1869
|
+
const parts = [];
|
|
1870
|
+
const format = options?.moduleFormat || "esm";
|
|
1871
|
+
const isESM = format === "esm";
|
|
1872
|
+
parts.push("// Generated by enyosx-ai (transpiler)");
|
|
1873
|
+
if (ast.system) {
|
|
1874
|
+
parts.push(isESM ? `export const SYSTEM = ${JSON.stringify(ast.system)};` : `const SYSTEM = ${JSON.stringify(ast.system)};
|
|
1875
|
+
module.exports.SYSTEM = SYSTEM;`);
|
|
1876
|
+
}
|
|
1877
|
+
if (ast.mode) {
|
|
1878
|
+
parts.push(isESM ? `export const MODE = ${JSON.stringify(ast.mode)};` : `const MODE = ${JSON.stringify(ast.mode)};
|
|
1879
|
+
module.exports.MODE = MODE;`);
|
|
1880
|
+
}
|
|
1881
|
+
if (ast.ui) {
|
|
1882
|
+
parts.push(isESM ? `export const UI = ${JSON.stringify(ast.ui)};` : `const UI = ${JSON.stringify(ast.ui)};
|
|
1883
|
+
module.exports.UI = UI;`);
|
|
1884
|
+
}
|
|
1885
|
+
const functionNames = [];
|
|
1886
|
+
if (ast.functions && ast.functions.length) {
|
|
1887
|
+
for (const fn of ast.functions) {
|
|
1888
|
+
const args = (fn.args || []).join(", ");
|
|
1889
|
+
const bodyLines = (fn.steps || []).map((s) => ` // ${s.raw}`);
|
|
1890
|
+
functionNames.push(fn.name);
|
|
1891
|
+
if (isESM) {
|
|
1892
|
+
const fnCode = `export function ${fn.name}(${args}) {
|
|
1893
|
+
${bodyLines.join("\n")}
|
|
1894
|
+
}`;
|
|
1895
|
+
parts.push(fnCode);
|
|
1896
|
+
} else {
|
|
1897
|
+
const fnCode = `function ${fn.name}(${args}) {
|
|
1898
|
+
${bodyLines.join("\n")}
|
|
1899
|
+
}
|
|
1900
|
+
module.exports.${fn.name} = ${fn.name};`;
|
|
1901
|
+
parts.push(fnCode);
|
|
1902
|
+
}
|
|
1903
|
+
}
|
|
1904
|
+
}
|
|
1905
|
+
const iaNames = [];
|
|
1906
|
+
if (ast.ias && ast.ias.length) {
|
|
1907
|
+
for (const ia of ast.ias) {
|
|
1908
|
+
const body = ia.body.map((b) => ` // ${b}`).join("\n");
|
|
1909
|
+
const name = ia.name.replace(/[^a-zA-Z0-9_]/g, "_");
|
|
1910
|
+
const constName = `IA_${name}`;
|
|
1911
|
+
iaNames.push(constName);
|
|
1912
|
+
if (isESM) {
|
|
1913
|
+
const code = `export const ${constName} = { name: ${JSON.stringify(ia.name)}, run: () => {
|
|
1914
|
+
${body}
|
|
1915
|
+
} };`;
|
|
1916
|
+
parts.push(code);
|
|
1917
|
+
} else {
|
|
1918
|
+
const code = `const ${constName} = { name: ${JSON.stringify(ia.name)}, run: () => {
|
|
1919
|
+
${body}
|
|
1920
|
+
} };
|
|
1921
|
+
module.exports.${constName} = ${constName};`;
|
|
1922
|
+
parts.push(code);
|
|
1923
|
+
}
|
|
1924
|
+
}
|
|
1925
|
+
}
|
|
1926
|
+
const objectNames = [];
|
|
1927
|
+
if (ast.objects && ast.objects.length) {
|
|
1928
|
+
for (const o of ast.objects) {
|
|
1929
|
+
objectNames.push(o.name);
|
|
1930
|
+
parts.push(isESM ? `export const ${o.name} = ${JSON.stringify(o.props, null, 2)};` : `const ${o.name} = ${JSON.stringify(o.props, null, 2)};
|
|
1931
|
+
module.exports.${o.name} = ${o.name};`);
|
|
1932
|
+
}
|
|
1933
|
+
}
|
|
1934
|
+
const formNames = [];
|
|
1935
|
+
if (ast.forms && ast.forms.length) {
|
|
1936
|
+
for (const f of ast.forms) {
|
|
1937
|
+
const constName = `FORM_${f.name}`;
|
|
1938
|
+
formNames.push(constName);
|
|
1939
|
+
parts.push(isESM ? `export const ${constName} = ${JSON.stringify(f.props, null, 2)};` : `const ${constName} = ${JSON.stringify(f.props, null, 2)};
|
|
1940
|
+
module.exports.${constName} = ${constName};`);
|
|
1941
|
+
}
|
|
1942
|
+
}
|
|
1943
|
+
const animNames = [];
|
|
1944
|
+
if (ast.animations && ast.animations.length) {
|
|
1945
|
+
for (const a of ast.animations) {
|
|
1946
|
+
const constName = `ANIMATION_${a.name.replace(/[^a-zA-Z0-9_]/g, "_")}`;
|
|
1947
|
+
animNames.push(constName);
|
|
1948
|
+
parts.push(isESM ? `export const ${constName} = ${JSON.stringify(a.props, null, 2)};` : `const ${constName} = ${JSON.stringify(a.props, null, 2)};
|
|
1949
|
+
module.exports.${constName} = ${constName};`);
|
|
1950
|
+
}
|
|
1951
|
+
}
|
|
1952
|
+
if (ast.build) {
|
|
1953
|
+
parts.push(isESM ? `export const BUILD_TARGETS = ${JSON.stringify(ast.build.targets || [])};` : `const BUILD_TARGETS = ${JSON.stringify(ast.build.targets || [])};
|
|
1954
|
+
module.exports.BUILD_TARGETS = BUILD_TARGETS;`);
|
|
1955
|
+
}
|
|
1956
|
+
if (ast.evolve) {
|
|
1957
|
+
parts.push(isESM ? `export const EVOLVE_STEPS = ${JSON.stringify(ast.evolve.steps || [])};` : `const EVOLVE_STEPS = ${JSON.stringify(ast.evolve.steps || [])};
|
|
1958
|
+
module.exports.EVOLVE_STEPS = EVOLVE_STEPS;`);
|
|
1959
|
+
}
|
|
1960
|
+
if (ast.database) {
|
|
1961
|
+
parts.push(isESM ? `export const DATABASE = ${JSON.stringify(ast.database)};` : `const DATABASE = ${JSON.stringify(ast.database)};
|
|
1962
|
+
module.exports.DATABASE = DATABASE;`);
|
|
1963
|
+
}
|
|
1964
|
+
if (ast.kernel) {
|
|
1965
|
+
parts.push(isESM ? `export const KERNEL = ${JSON.stringify(ast.kernel)};` : `const KERNEL = ${JSON.stringify(ast.kernel)};
|
|
1966
|
+
module.exports.KERNEL = KERNEL;`);
|
|
1967
|
+
}
|
|
1968
|
+
if (ast.training) {
|
|
1969
|
+
parts.push(isESM ? `export const TRAINING = ${JSON.stringify(ast.training)};` : `const TRAINING = ${JSON.stringify(ast.training)};
|
|
1970
|
+
module.exports.TRAINING = TRAINING;`);
|
|
1971
|
+
}
|
|
1972
|
+
if (ast.substates && ast.substates.length) {
|
|
1973
|
+
parts.push(isESM ? `export const SUBSTATES = ${JSON.stringify(ast.substates, null, 2)};` : `const SUBSTATES = ${JSON.stringify(ast.substates, null, 2)};
|
|
1974
|
+
module.exports.SUBSTATES = SUBSTATES;`);
|
|
1975
|
+
}
|
|
1976
|
+
if (ast.classes && ast.classes.length) {
|
|
1977
|
+
for (const c of ast.classes) {
|
|
1978
|
+
const className = c.name.replace(/[^a-zA-Z0-9_]/g, "_");
|
|
1979
|
+
parts.push(isESM ? `export class ${className} {
|
|
1980
|
+
constructor() {
|
|
1981
|
+
Object.assign(this, ${JSON.stringify(c.props)});
|
|
1982
|
+
}
|
|
1983
|
+
${(c.methods || []).map((m) => ` ${m}() {}`).join("\n")}
|
|
1984
|
+
}` : `class ${className} {
|
|
1985
|
+
constructor() {
|
|
1986
|
+
Object.assign(this, ${JSON.stringify(c.props)});
|
|
1987
|
+
}
|
|
1988
|
+
${(c.methods || []).map((m) => ` ${m}() {}`).join("\n")}
|
|
1989
|
+
}
|
|
1990
|
+
module.exports.${className} = ${className};`);
|
|
1991
|
+
}
|
|
1992
|
+
}
|
|
1993
|
+
if (ast.loops && ast.loops.length) {
|
|
1994
|
+
parts.push(isESM ? `export const LOOPS = ${JSON.stringify(ast.loops, null, 2)};` : `const LOOPS = ${JSON.stringify(ast.loops, null, 2)};
|
|
1995
|
+
module.exports.LOOPS = LOOPS;`);
|
|
1996
|
+
}
|
|
1997
|
+
if (ast.events && ast.events.length) {
|
|
1998
|
+
for (const e of ast.events) {
|
|
1999
|
+
const eventName = `EVENT_${e.name.replace(/[^a-zA-Z0-9_]/g, "_")}`;
|
|
2000
|
+
parts.push(isESM ? `export const ${eventName} = { name: ${JSON.stringify(e.name)}, handler: ${JSON.stringify(e.handler || [])} };` : `const ${eventName} = { name: ${JSON.stringify(e.name)}, handler: ${JSON.stringify(e.handler || [])} };
|
|
2001
|
+
module.exports.${eventName} = ${eventName};`);
|
|
2002
|
+
}
|
|
2003
|
+
}
|
|
2004
|
+
if (ast.syncs && ast.syncs.length) {
|
|
2005
|
+
parts.push(isESM ? `export const SYNCS = ${JSON.stringify(ast.syncs, null, 2)};` : `const SYNCS = ${JSON.stringify(ast.syncs, null, 2)};
|
|
2006
|
+
module.exports.SYNCS = SYNCS;`);
|
|
2007
|
+
}
|
|
2008
|
+
if (ast.timeouts && ast.timeouts.length) {
|
|
2009
|
+
parts.push(isESM ? `export const TIMEOUTS = ${JSON.stringify(ast.timeouts, null, 2)};` : `const TIMEOUTS = ${JSON.stringify(ast.timeouts, null, 2)};
|
|
2010
|
+
module.exports.TIMEOUTS = TIMEOUTS;`);
|
|
2011
|
+
}
|
|
2012
|
+
if (ast.delays && ast.delays.length) {
|
|
2013
|
+
parts.push(isESM ? `export const DELAYS = ${JSON.stringify(ast.delays, null, 2)};` : `const DELAYS = ${JSON.stringify(ast.delays, null, 2)};
|
|
2014
|
+
module.exports.DELAYS = DELAYS;`);
|
|
2015
|
+
}
|
|
2016
|
+
if (ast.securities && ast.securities.length) {
|
|
2017
|
+
parts.push(isESM ? `export const SECURITY_RULES = ${JSON.stringify(ast.securities, null, 2)};` : `const SECURITY_RULES = ${JSON.stringify(ast.securities, null, 2)};
|
|
2018
|
+
module.exports.SECURITY_RULES = SECURITY_RULES;`);
|
|
2019
|
+
}
|
|
2020
|
+
if (ast.keys && ast.keys.length) {
|
|
2021
|
+
parts.push(isESM ? `export const KEYS = ${JSON.stringify(ast.keys, null, 2)};` : `const KEYS = ${JSON.stringify(ast.keys, null, 2)};
|
|
2022
|
+
module.exports.KEYS = KEYS;`);
|
|
2023
|
+
}
|
|
2024
|
+
if (ast.sandboxes && ast.sandboxes.length) {
|
|
2025
|
+
parts.push(isESM ? `export const SANDBOXES = ${JSON.stringify(ast.sandboxes, null, 2)};` : `const SANDBOXES = ${JSON.stringify(ast.sandboxes, null, 2)};
|
|
2026
|
+
module.exports.SANDBOXES = SANDBOXES;`);
|
|
2027
|
+
}
|
|
2028
|
+
if (ast.causes && ast.causes.length) {
|
|
2029
|
+
parts.push(isESM ? `export const CAUSES = ${JSON.stringify(ast.causes, null, 2)};` : `const CAUSES = ${JSON.stringify(ast.causes, null, 2)};
|
|
2030
|
+
module.exports.CAUSES = CAUSES;`);
|
|
2031
|
+
}
|
|
2032
|
+
if (ast.consequences && ast.consequences.length) {
|
|
2033
|
+
parts.push(isESM ? `export const CONSEQUENCES = ${JSON.stringify(ast.consequences, null, 2)};` : `const CONSEQUENCES = ${JSON.stringify(ast.consequences, null, 2)};
|
|
2034
|
+
module.exports.CONSEQUENCES = CONSEQUENCES;`);
|
|
2035
|
+
}
|
|
2036
|
+
if (ast.memories && ast.memories.length) {
|
|
2037
|
+
parts.push(isESM ? `export const MEMORIES = ${JSON.stringify(ast.memories, null, 2)};` : `const MEMORIES = ${JSON.stringify(ast.memories, null, 2)};
|
|
2038
|
+
module.exports.MEMORIES = MEMORIES;`);
|
|
2039
|
+
}
|
|
2040
|
+
if (ast.persists && ast.persists.length) {
|
|
2041
|
+
parts.push(isESM ? `export const PERSISTS = ${JSON.stringify(ast.persists, null, 2)};` : `const PERSISTS = ${JSON.stringify(ast.persists, null, 2)};
|
|
2042
|
+
module.exports.PERSISTS = PERSISTS;`);
|
|
2043
|
+
}
|
|
2044
|
+
if (ast.interfaces && ast.interfaces.length) {
|
|
2045
|
+
parts.push(isESM ? `export const INTERFACES = ${JSON.stringify(ast.interfaces, null, 2)};` : `const INTERFACES = ${JSON.stringify(ast.interfaces, null, 2)};
|
|
2046
|
+
module.exports.INTERFACES = INTERFACES;`);
|
|
2047
|
+
}
|
|
2048
|
+
if (ast.visuals && ast.visuals.length) {
|
|
2049
|
+
parts.push(isESM ? `export const VISUALS = ${JSON.stringify(ast.visuals, null, 2)};` : `const VISUALS = ${JSON.stringify(ast.visuals, null, 2)};
|
|
2050
|
+
module.exports.VISUALS = VISUALS;`);
|
|
2051
|
+
}
|
|
2052
|
+
if (ast.inputs && ast.inputs.length) {
|
|
2053
|
+
parts.push(isESM ? `export const INPUTS = ${JSON.stringify(ast.inputs, null, 2)};` : `const INPUTS = ${JSON.stringify(ast.inputs, null, 2)};
|
|
2054
|
+
module.exports.INPUTS = INPUTS;`);
|
|
2055
|
+
}
|
|
2056
|
+
if (ast.throttles && ast.throttles.length) {
|
|
2057
|
+
parts.push(isESM ? `export const THROTTLES = ${JSON.stringify(ast.throttles, null, 2)};` : `const THROTTLES = ${JSON.stringify(ast.throttles, null, 2)};
|
|
2058
|
+
module.exports.THROTTLES = THROTTLES;`);
|
|
2059
|
+
}
|
|
2060
|
+
if (ast.boosts && ast.boosts.length) {
|
|
2061
|
+
parts.push(isESM ? `export const BOOSTS = ${JSON.stringify(ast.boosts, null, 2)};` : `const BOOSTS = ${JSON.stringify(ast.boosts, null, 2)};
|
|
2062
|
+
module.exports.BOOSTS = BOOSTS;`);
|
|
2063
|
+
}
|
|
2064
|
+
if (ast.costs && ast.costs.length) {
|
|
2065
|
+
parts.push(isESM ? `export const COSTS = ${JSON.stringify(ast.costs, null, 2)};` : `const COSTS = ${JSON.stringify(ast.costs, null, 2)};
|
|
2066
|
+
module.exports.COSTS = COSTS;`);
|
|
2067
|
+
}
|
|
2068
|
+
if (ast.locks && ast.locks.length) {
|
|
2069
|
+
parts.push(isESM ? `export const LOCKS = ${JSON.stringify(ast.locks, null, 2)};` : `const LOCKS = ${JSON.stringify(ast.locks, null, 2)};
|
|
2070
|
+
module.exports.LOCKS = LOCKS;`);
|
|
2071
|
+
}
|
|
2072
|
+
if (ast.unlocks && ast.unlocks.length) {
|
|
2073
|
+
parts.push(isESM ? `export const UNLOCKS = ${JSON.stringify(ast.unlocks, null, 2)};` : `const UNLOCKS = ${JSON.stringify(ast.unlocks, null, 2)};
|
|
2074
|
+
module.exports.UNLOCKS = UNLOCKS;`);
|
|
2075
|
+
}
|
|
2076
|
+
if (ast.voids && ast.voids.length) {
|
|
2077
|
+
parts.push(isESM ? `export const VOIDS = ${JSON.stringify(ast.voids, null, 2)};` : `const VOIDS = ${JSON.stringify(ast.voids, null, 2)};
|
|
2078
|
+
module.exports.VOIDS = VOIDS;`);
|
|
2079
|
+
}
|
|
2080
|
+
if (ast.inherits && ast.inherits.length) {
|
|
2081
|
+
parts.push(isESM ? `export const INHERITS = ${JSON.stringify(ast.inherits, null, 2)};` : `const INHERITS = ${JSON.stringify(ast.inherits, null, 2)};
|
|
2082
|
+
module.exports.INHERITS = INHERITS;`);
|
|
2083
|
+
}
|
|
2084
|
+
if (ast.contains && ast.contains.length) {
|
|
2085
|
+
parts.push(isESM ? `export const CONTAINS = ${JSON.stringify(ast.contains, null, 2)};` : `const CONTAINS = ${JSON.stringify(ast.contains, null, 2)};
|
|
2086
|
+
module.exports.CONTAINS = CONTAINS;`);
|
|
2087
|
+
}
|
|
2088
|
+
if (ast.verifies && ast.verifies.length) {
|
|
2089
|
+
parts.push(isESM ? `export const VERIFIES = ${JSON.stringify(ast.verifies, null, 2)};` : `const VERIFIES = ${JSON.stringify(ast.verifies, null, 2)};
|
|
2090
|
+
module.exports.VERIFIES = VERIFIES;`);
|
|
2091
|
+
}
|
|
2092
|
+
if (ast.logNodes && ast.logNodes.length) {
|
|
2093
|
+
parts.push(isESM ? `export const LOG_NODES = ${JSON.stringify(ast.logNodes, null, 2)};` : `const LOG_NODES = ${JSON.stringify(ast.logNodes, null, 2)};
|
|
2094
|
+
module.exports.LOG_NODES = LOG_NODES;`);
|
|
2095
|
+
}
|
|
2096
|
+
if (isESM) {
|
|
2097
|
+
parts.push("\nexport default { SYSTEM, MODE, UI };");
|
|
2098
|
+
} else {
|
|
2099
|
+
parts.push("\nmodule.exports.default = { SYSTEM, MODE, UI };");
|
|
2100
|
+
}
|
|
2101
|
+
return parts.join("\n\n");
|
|
2102
|
+
}
|
|
2103
|
+
function transpileToDTS(ast) {
|
|
2104
|
+
const lines = [];
|
|
2105
|
+
lines.push("// Type declarations generated by enyosx-ai");
|
|
2106
|
+
lines.push("");
|
|
2107
|
+
if (ast.system) {
|
|
2108
|
+
lines.push(`export declare const SYSTEM: string;`);
|
|
2109
|
+
}
|
|
2110
|
+
if (ast.mode) {
|
|
2111
|
+
lines.push(`export declare const MODE: string;`);
|
|
2112
|
+
}
|
|
2113
|
+
if (ast.ui) {
|
|
2114
|
+
lines.push(`export declare const UI: string;`);
|
|
2115
|
+
}
|
|
2116
|
+
if (ast.functions && ast.functions.length) {
|
|
2117
|
+
for (const fn of ast.functions) {
|
|
2118
|
+
const args = (fn.args || []).map((a) => `${a}: any`).join(", ");
|
|
2119
|
+
lines.push(`export declare function ${fn.name}(${args}): void;`);
|
|
2120
|
+
}
|
|
2121
|
+
}
|
|
2122
|
+
if (ast.ias && ast.ias.length) {
|
|
2123
|
+
for (const ia of ast.ias) {
|
|
2124
|
+
const name = ia.name.replace(/[^a-zA-Z0-9_]/g, "_");
|
|
2125
|
+
lines.push(`export declare const IA_${name}: { name: string; run: () => void };`);
|
|
2126
|
+
}
|
|
2127
|
+
}
|
|
2128
|
+
if (ast.objects && ast.objects.length) {
|
|
2129
|
+
for (const o of ast.objects) {
|
|
2130
|
+
const propTypes = Object.keys(o.props).map((k) => `${k}: string | null`).join("; ");
|
|
2131
|
+
lines.push(`export declare const ${o.name}: { ${propTypes} };`);
|
|
2132
|
+
}
|
|
2133
|
+
}
|
|
2134
|
+
if (ast.forms && ast.forms.length) {
|
|
2135
|
+
for (const f of ast.forms) {
|
|
2136
|
+
lines.push(`export declare const FORM_${f.name}: Record<string, any>;`);
|
|
2137
|
+
}
|
|
2138
|
+
}
|
|
2139
|
+
if (ast.animations && ast.animations.length) {
|
|
2140
|
+
for (const a of ast.animations) {
|
|
2141
|
+
const constName = `ANIMATION_${a.name.replace(/[^a-zA-Z0-9_]/g, "_")}`;
|
|
2142
|
+
lines.push(`export declare const ${constName}: Record<string, any>;`);
|
|
2143
|
+
}
|
|
2144
|
+
}
|
|
2145
|
+
if (ast.build) {
|
|
2146
|
+
lines.push(`export declare const BUILD_TARGETS: string[];`);
|
|
2147
|
+
}
|
|
2148
|
+
if (ast.evolve) {
|
|
2149
|
+
lines.push(`export declare const EVOLVE_STEPS: string[];`);
|
|
2150
|
+
}
|
|
2151
|
+
lines.push("");
|
|
2152
|
+
lines.push("declare const _default: { SYSTEM: string; MODE: string; UI: string };");
|
|
2153
|
+
lines.push("export default _default;");
|
|
2154
|
+
return lines.join("\n");
|
|
2155
|
+
}
|
|
2156
|
+
function transpileToWAT(ast) {
|
|
2157
|
+
const lines = [];
|
|
2158
|
+
lines.push(";; WebAssembly Text Format generated by enyosx-ai");
|
|
2159
|
+
lines.push(";; This is a stub for future WASM compilation");
|
|
2160
|
+
lines.push("");
|
|
2161
|
+
lines.push("(module");
|
|
2162
|
+
lines.push(` ;; System: ${ast.system || "unnamed"}`);
|
|
2163
|
+
lines.push(` ;; Mode: ${ast.mode || "default"}`);
|
|
2164
|
+
lines.push("");
|
|
2165
|
+
lines.push(" ;; Memory declaration");
|
|
2166
|
+
lines.push(' (memory (export "memory") 1)');
|
|
2167
|
+
lines.push("");
|
|
2168
|
+
if (ast.system) {
|
|
2169
|
+
const bytes = Array.from(new TextEncoder().encode(ast.system)).join(" ");
|
|
2170
|
+
lines.push(` ;; System name data`);
|
|
2171
|
+
lines.push(` (data (i32.const 0) "${ast.system}")`);
|
|
2172
|
+
lines.push("");
|
|
2173
|
+
}
|
|
2174
|
+
if (ast.functions && ast.functions.length) {
|
|
2175
|
+
lines.push(" ;; Function stubs");
|
|
2176
|
+
for (const fn of ast.functions) {
|
|
2177
|
+
const params = (fn.args || []).map((_, i) => `(param $arg${i} i32)`).join(" ");
|
|
2178
|
+
lines.push(` (func (export "${fn.name}") ${params} (result i32)`);
|
|
2179
|
+
lines.push(` ;; Steps: ${(fn.steps || []).map((s) => s.raw).join(" -> ")}`);
|
|
2180
|
+
lines.push(` i32.const 0 ;; placeholder return`);
|
|
2181
|
+
lines.push(` )`);
|
|
2182
|
+
lines.push("");
|
|
2183
|
+
}
|
|
2184
|
+
}
|
|
2185
|
+
if (ast.ias && ast.ias.length) {
|
|
2186
|
+
lines.push(" ;; IA stubs (table references for future indirect calls)");
|
|
2187
|
+
for (const ia of ast.ias) {
|
|
2188
|
+
const name = ia.name.replace(/[^a-zA-Z0-9_]/g, "_");
|
|
2189
|
+
lines.push(` ;; IA: ${ia.name}`);
|
|
2190
|
+
lines.push(` (func (export "ia_${name}") (result i32)`);
|
|
2191
|
+
lines.push(` ;; Capabilities: ${ia.body.join(", ")}`);
|
|
2192
|
+
lines.push(` i32.const 1 ;; stub: IA ready`);
|
|
2193
|
+
lines.push(` )`);
|
|
2194
|
+
lines.push("");
|
|
2195
|
+
}
|
|
2196
|
+
}
|
|
2197
|
+
lines.push(" ;; Main entry point");
|
|
2198
|
+
lines.push(' (func (export "_start")');
|
|
2199
|
+
lines.push(" ;; Initialize system");
|
|
2200
|
+
lines.push(" nop");
|
|
2201
|
+
lines.push(" )");
|
|
2202
|
+
lines.push("");
|
|
2203
|
+
if (ast.build && ast.build.targets) {
|
|
2204
|
+
lines.push(` ;; Build targets: ${ast.build.targets.join(", ")}`);
|
|
2205
|
+
}
|
|
2206
|
+
lines.push(")");
|
|
2207
|
+
lines.push("");
|
|
2208
|
+
lines.push(";; To compile this WAT to WASM:");
|
|
2209
|
+
lines.push(";; wat2wasm output.wat -o output.wasm");
|
|
2210
|
+
lines.push(";; Or use wasm-pack for Rust-based compilation");
|
|
2211
|
+
return lines.join("\n");
|
|
2212
|
+
}
|
|
2213
|
+
function hasWASMTarget(ast) {
|
|
2214
|
+
if (!ast.build || !ast.build.targets)
|
|
2215
|
+
return false;
|
|
2216
|
+
return ast.build.targets.some(
|
|
2217
|
+
(t) => t.toLowerCase() === "wasm" || t.toLowerCase() === "webassembly" || t.toLowerCase() === "wat"
|
|
2218
|
+
);
|
|
2219
|
+
}
|
|
2220
|
+
|
|
2221
|
+
export {
|
|
2222
|
+
TokenType,
|
|
2223
|
+
SYMBOL_NAMES,
|
|
2224
|
+
tokenize,
|
|
2225
|
+
validateSemantic,
|
|
2226
|
+
applyEvolve,
|
|
2227
|
+
runENY,
|
|
2228
|
+
transpileToJS,
|
|
2229
|
+
transpileToDTS,
|
|
2230
|
+
transpileToWAT,
|
|
2231
|
+
hasWASMTarget
|
|
2232
|
+
};
|