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,318 @@
|
|
|
1
|
+
// src/runENY.ts
|
|
2
|
+
import fs2 from "fs";
|
|
3
|
+
|
|
4
|
+
// src/parser.ts
|
|
5
|
+
import fs from "fs";
|
|
6
|
+
function parse(code, options) {
|
|
7
|
+
const logs = [];
|
|
8
|
+
const log = (entry) => {
|
|
9
|
+
const e = { timestamp: (/* @__PURE__ */ new Date()).toISOString(), ...entry };
|
|
10
|
+
logs.push(e);
|
|
11
|
+
if (options?.onLog)
|
|
12
|
+
options.onLog(e);
|
|
13
|
+
if (options?.logFile) {
|
|
14
|
+
try {
|
|
15
|
+
fs.appendFileSync(options.logFile, JSON.stringify(e) + "\n", { encoding: "utf8" });
|
|
16
|
+
} catch (err) {
|
|
17
|
+
const errEntry = { timestamp: (/* @__PURE__ */ new Date()).toISOString(), level: "error", event: "logfile.write.error", detail: String(err) };
|
|
18
|
+
logs.push(errEntry);
|
|
19
|
+
if (options?.onLog)
|
|
20
|
+
options.onLog(errEntry);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
log({ level: "info", event: "parse.start", detail: { length: code.length } });
|
|
25
|
+
const ast = {
|
|
26
|
+
raw: code,
|
|
27
|
+
functions: [],
|
|
28
|
+
ias: [],
|
|
29
|
+
nodes: [],
|
|
30
|
+
modules: [],
|
|
31
|
+
objects: [],
|
|
32
|
+
forms: [],
|
|
33
|
+
animations: [],
|
|
34
|
+
logic: [],
|
|
35
|
+
parallels: [],
|
|
36
|
+
build: null,
|
|
37
|
+
evolve: null,
|
|
38
|
+
targets: [],
|
|
39
|
+
version: null,
|
|
40
|
+
logs
|
|
41
|
+
};
|
|
42
|
+
const lines = code.split(/\r?\n/);
|
|
43
|
+
let i = 0;
|
|
44
|
+
while (i < lines.length) {
|
|
45
|
+
const raw = lines[i];
|
|
46
|
+
const line = raw.trim();
|
|
47
|
+
if (!line) {
|
|
48
|
+
i++;
|
|
49
|
+
continue;
|
|
50
|
+
}
|
|
51
|
+
if (/^Σ\s+SYSTEM/i.test(line)) {
|
|
52
|
+
const m = line.match(/^Σ\s+SYSTEM\s+"([^"]+)"/i);
|
|
53
|
+
ast.system = m ? m[1] : line.replace(/^Σ\s+SYSTEM\s*/i, "");
|
|
54
|
+
log({ level: "info", event: "parse.system", i, line: ast.system });
|
|
55
|
+
i++;
|
|
56
|
+
continue;
|
|
57
|
+
}
|
|
58
|
+
if (/^Σ\s+VERSION/i.test(line)) {
|
|
59
|
+
const m = line.match(/^Σ\s+VERSION\s+([\d\.]+)/i);
|
|
60
|
+
ast.version = m ? m[1] : null;
|
|
61
|
+
i++;
|
|
62
|
+
continue;
|
|
63
|
+
}
|
|
64
|
+
if (/^Σ\s+TARGET/i.test(line)) {
|
|
65
|
+
const m = line.match(/^Σ\s+TARGET\s+(.+)/i);
|
|
66
|
+
if (m) {
|
|
67
|
+
const parts = m[1].split(/[+,\s]+/).map((s) => s.trim()).filter(Boolean);
|
|
68
|
+
ast.targets = [...ast.targets || [], ...parts];
|
|
69
|
+
}
|
|
70
|
+
i++;
|
|
71
|
+
continue;
|
|
72
|
+
}
|
|
73
|
+
if (/^Σ\s+MODE/i.test(line)) {
|
|
74
|
+
const m = line.match(/^Σ\s+MODE\s+([\w-]+)/i);
|
|
75
|
+
ast.mode = m ? m[1] : null;
|
|
76
|
+
i++;
|
|
77
|
+
continue;
|
|
78
|
+
}
|
|
79
|
+
if (/^Σ\s+UI/i.test(line)) {
|
|
80
|
+
const m = line.match(/^Σ\s+UI\s+([\w-]+)/i);
|
|
81
|
+
ast.ui = m ? m[1] : null;
|
|
82
|
+
i++;
|
|
83
|
+
continue;
|
|
84
|
+
}
|
|
85
|
+
if (/^Δ\s+([\w_]+)\s*\(([^)]*)\)/.test(line)) {
|
|
86
|
+
const m = line.match(/^Δ\s+([\w_]+)\s*\(([^)]*)\)/);
|
|
87
|
+
const name = m ? m[1] : "anonymous";
|
|
88
|
+
const argsRaw = m ? m[2] : "";
|
|
89
|
+
const args = argsRaw ? argsRaw.split(",").map((s) => s.trim()).filter(Boolean) : [];
|
|
90
|
+
const steps = [];
|
|
91
|
+
log({ level: "info", event: "parse.function.start", i, detail: { name, args } });
|
|
92
|
+
i++;
|
|
93
|
+
while (i < lines.length) {
|
|
94
|
+
const l = lines[i];
|
|
95
|
+
if (!l.trim()) {
|
|
96
|
+
i++;
|
|
97
|
+
continue;
|
|
98
|
+
}
|
|
99
|
+
if (/^→/.test(l.trim()) || /^\s+→/.test(l) || /^\s+/.test(l)) {
|
|
100
|
+
const step = l.trim().replace(/^→\s?/, "");
|
|
101
|
+
steps.push({ raw: step });
|
|
102
|
+
log({ level: "debug", event: "parse.function.step", i, line: step });
|
|
103
|
+
i++;
|
|
104
|
+
} else {
|
|
105
|
+
break;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
const fn = { type: "function", name, args, steps };
|
|
109
|
+
log({ level: "info", event: "parse.function.end", detail: fn });
|
|
110
|
+
ast.functions.push(fn);
|
|
111
|
+
ast.nodes.push(fn);
|
|
112
|
+
continue;
|
|
113
|
+
}
|
|
114
|
+
if (/^Ψ\s+IA\s+([\w-]+)\s*\{?/.test(line)) {
|
|
115
|
+
const m = line.match(/^Ψ\s+IA\s+([\w-]+)\s*\{?/);
|
|
116
|
+
const name = m ? m[1] : "ia";
|
|
117
|
+
const body = [];
|
|
118
|
+
if (/\{$/.test(line)) {
|
|
119
|
+
i++;
|
|
120
|
+
while (i < lines.length && !/\}/.test(lines[i])) {
|
|
121
|
+
body.push(lines[i].trim());
|
|
122
|
+
i++;
|
|
123
|
+
}
|
|
124
|
+
if (i < lines.length && /\}/.test(lines[i]))
|
|
125
|
+
i++;
|
|
126
|
+
} else {
|
|
127
|
+
i++;
|
|
128
|
+
while (i < lines.length) {
|
|
129
|
+
const l = lines[i];
|
|
130
|
+
if (!l.trim()) {
|
|
131
|
+
i++;
|
|
132
|
+
break;
|
|
133
|
+
}
|
|
134
|
+
if (/^Σ|^Δ|^Ψ/.test(l.trim()))
|
|
135
|
+
break;
|
|
136
|
+
body.push(l.trim());
|
|
137
|
+
i++;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
const ia = { type: "ia", name, body };
|
|
141
|
+
log({ level: "info", event: "parse.ia", i, detail: ia });
|
|
142
|
+
ast.ias.push(ia);
|
|
143
|
+
ast.nodes.push(ia);
|
|
144
|
+
continue;
|
|
145
|
+
}
|
|
146
|
+
if (/^Σ\s+EVOLVE/i.test(line)) {
|
|
147
|
+
const steps = [];
|
|
148
|
+
i++;
|
|
149
|
+
while (i < lines.length && !!lines[i].trim() && !/^Σ|^Δ|^Ψ|Ω|Φ|Θ|Λ|⊗/.test(lines[i].trim())) {
|
|
150
|
+
steps.push(lines[i].trim());
|
|
151
|
+
i++;
|
|
152
|
+
}
|
|
153
|
+
const ev = { type: "evolve", steps };
|
|
154
|
+
ast.evolve = ev;
|
|
155
|
+
ast.nodes.push(ev);
|
|
156
|
+
continue;
|
|
157
|
+
}
|
|
158
|
+
if (/^Σ\s+BUILD/i.test(line)) {
|
|
159
|
+
const targets = [];
|
|
160
|
+
i++;
|
|
161
|
+
while (i < lines.length && !!lines[i].trim() && !/^Σ|^Δ|^Ψ|Ω|Φ|Θ|Λ|⊗/.test(lines[i].trim())) {
|
|
162
|
+
const m = lines[i].trim().match(/target:\s*([\w-]+)/);
|
|
163
|
+
if (m)
|
|
164
|
+
targets.push(m[1]);
|
|
165
|
+
i++;
|
|
166
|
+
}
|
|
167
|
+
const b = { type: "build", targets };
|
|
168
|
+
log({ level: "info", event: "parse.build", i, detail: b });
|
|
169
|
+
ast.build = b;
|
|
170
|
+
ast.nodes.push(b);
|
|
171
|
+
continue;
|
|
172
|
+
}
|
|
173
|
+
if (/^Σ\s+MODULE/i.test(line)) {
|
|
174
|
+
const m = line.match(/^Σ\s+MODULE\s+"([^"]+)"/i);
|
|
175
|
+
const name = m ? m[1] : line.replace(/^Σ\s+MODULE\s*/i, "");
|
|
176
|
+
const module = { type: "module", name };
|
|
177
|
+
ast.modules.push(module);
|
|
178
|
+
ast.nodes.push(module);
|
|
179
|
+
i++;
|
|
180
|
+
continue;
|
|
181
|
+
}
|
|
182
|
+
if (/^Ω\s+([\w_]+)\s*\{?/.test(line)) {
|
|
183
|
+
const m = line.match(/^Ω\s+([\w_]+)\s*\{?/);
|
|
184
|
+
const name = m ? m[1] : "object";
|
|
185
|
+
const props = {};
|
|
186
|
+
if (/\{$/.test(line)) {
|
|
187
|
+
i++;
|
|
188
|
+
while (i < lines.length && !/\}/.test(lines[i])) {
|
|
189
|
+
const p = lines[i].trim();
|
|
190
|
+
const ma = p.match(/^([\w_]+)\s*:\s*"?([^\"]+)"?/);
|
|
191
|
+
if (ma)
|
|
192
|
+
props[ma[1]] = ma[2];
|
|
193
|
+
else if (p)
|
|
194
|
+
props[p] = null;
|
|
195
|
+
i++;
|
|
196
|
+
}
|
|
197
|
+
if (i < lines.length && /\}/.test(lines[i]))
|
|
198
|
+
i++;
|
|
199
|
+
}
|
|
200
|
+
const obj = { type: "object", name, props };
|
|
201
|
+
ast.objects.push(obj);
|
|
202
|
+
ast.nodes.push(obj);
|
|
203
|
+
continue;
|
|
204
|
+
}
|
|
205
|
+
if (/^Φ\s+([\w_]+)\s*\{?/.test(line)) {
|
|
206
|
+
const m = line.match(/^Φ\s+([\w_]+)\s*\{?/);
|
|
207
|
+
const name = m ? m[1] : "form";
|
|
208
|
+
const props = {};
|
|
209
|
+
if (/\{$/.test(line)) {
|
|
210
|
+
i++;
|
|
211
|
+
while (i < lines.length && !/\}/.test(lines[i])) {
|
|
212
|
+
const p = lines[i].trim();
|
|
213
|
+
const ma = p.match(/^([\w_]+)\s*:\s*"?([^\"]+)"?/);
|
|
214
|
+
if (ma)
|
|
215
|
+
props[ma[1]] = ma[2];
|
|
216
|
+
else if (p)
|
|
217
|
+
props[p] = true;
|
|
218
|
+
i++;
|
|
219
|
+
}
|
|
220
|
+
if (i < lines.length && /\}/.test(lines[i]))
|
|
221
|
+
i++;
|
|
222
|
+
}
|
|
223
|
+
const form = { type: "form", name, props };
|
|
224
|
+
ast.forms.push(form);
|
|
225
|
+
ast.nodes.push(form);
|
|
226
|
+
continue;
|
|
227
|
+
}
|
|
228
|
+
if (/^Θ\s+animation\s+"([^"]+)"/.test(line)) {
|
|
229
|
+
const m = line.match(/^Θ\s+animation\s+"([^"]+)"/);
|
|
230
|
+
const name = m ? m[1] : "anim";
|
|
231
|
+
const props = {};
|
|
232
|
+
i++;
|
|
233
|
+
while (i < lines.length && !!lines[i].trim() && !/^Σ|^Δ|^Ψ|Ω|Φ|Λ|⊗/.test(lines[i].trim())) {
|
|
234
|
+
const p = lines[i].trim();
|
|
235
|
+
const ma = p.match(/^([\w_]+)\s*:\s*(.+)/);
|
|
236
|
+
if (ma)
|
|
237
|
+
props[ma[1]] = ma[2].trim();
|
|
238
|
+
i++;
|
|
239
|
+
}
|
|
240
|
+
const anim = { type: "animation", name, props };
|
|
241
|
+
ast.animations.push(anim);
|
|
242
|
+
ast.nodes.push(anim);
|
|
243
|
+
continue;
|
|
244
|
+
}
|
|
245
|
+
if (/^Λ\s+if\s+/.test(line)) {
|
|
246
|
+
const ruleLines = [];
|
|
247
|
+
let trueFlow = [];
|
|
248
|
+
let falseFlow = [];
|
|
249
|
+
let rule = line.replace(/^Λ\s+/, "");
|
|
250
|
+
i++;
|
|
251
|
+
while (i < lines.length && !!lines[i].trim() && !/^Σ|^Δ|^Ψ|Ω|Φ|Θ|⊗/.test(lines[i].trim())) {
|
|
252
|
+
const l = lines[i].trim();
|
|
253
|
+
if (/^else/i.test(l)) {
|
|
254
|
+
i++;
|
|
255
|
+
break;
|
|
256
|
+
}
|
|
257
|
+
if (/^→/.test(l))
|
|
258
|
+
trueFlow.push(l.replace(/^→\s?/, "").trim());
|
|
259
|
+
ruleLines.push(l);
|
|
260
|
+
i++;
|
|
261
|
+
}
|
|
262
|
+
while (i < lines.length && !!lines[i].trim() && !/^Σ|^Δ|^Ψ|Ω|Φ|Θ|⊗/.test(lines[i].trim())) {
|
|
263
|
+
const l = lines[i].trim();
|
|
264
|
+
if (/^→/.test(l))
|
|
265
|
+
falseFlow.push(l.replace(/^→\s?/, "").trim());
|
|
266
|
+
i++;
|
|
267
|
+
}
|
|
268
|
+
const logic = { type: "logic", rule, trueFlow, falseFlow };
|
|
269
|
+
ast.logic.push(logic);
|
|
270
|
+
ast.nodes.push(logic);
|
|
271
|
+
continue;
|
|
272
|
+
}
|
|
273
|
+
if (/^⊗\s*\{?/.test(line)) {
|
|
274
|
+
const items = [];
|
|
275
|
+
if (/\{$/.test(line)) {
|
|
276
|
+
i++;
|
|
277
|
+
while (i < lines.length && !/\}/.test(lines[i])) {
|
|
278
|
+
const l = lines[i].trim();
|
|
279
|
+
if (l)
|
|
280
|
+
items.push(l);
|
|
281
|
+
i++;
|
|
282
|
+
}
|
|
283
|
+
if (i < lines.length && /\}/.test(lines[i]))
|
|
284
|
+
i++;
|
|
285
|
+
}
|
|
286
|
+
const par = { type: "parallel", items };
|
|
287
|
+
ast.parallels.push(par);
|
|
288
|
+
ast.nodes.push(par);
|
|
289
|
+
continue;
|
|
290
|
+
}
|
|
291
|
+
i++;
|
|
292
|
+
}
|
|
293
|
+
return ast;
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
// src/runENY.ts
|
|
297
|
+
function runENY(code, options) {
|
|
298
|
+
const hasSystem = /Σ\s+SYSTEM/i.test(code);
|
|
299
|
+
if (!hasSystem) {
|
|
300
|
+
if (options?.onLog) {
|
|
301
|
+
options.onLog({ timestamp: (/* @__PURE__ */ new Date()).toISOString(), level: "warn", event: "runENY.no-system", detail: { length: code.length } });
|
|
302
|
+
}
|
|
303
|
+
if (options?.logFile) {
|
|
304
|
+
try {
|
|
305
|
+
fs2.appendFileSync(options.logFile, JSON.stringify({ timestamp: (/* @__PURE__ */ new Date()).toISOString(), level: "warn", event: "runENY.no-system", detail: { length: code.length } }) + "\n");
|
|
306
|
+
} catch (e) {
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
return { raw: code, isEny: false, logs: [] };
|
|
310
|
+
}
|
|
311
|
+
const ast = parse(code, options);
|
|
312
|
+
ast.isEny = true;
|
|
313
|
+
return ast;
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
export {
|
|
317
|
+
runENY
|
|
318
|
+
};
|
|
@@ -0,0 +1,273 @@
|
|
|
1
|
+
// src/parser.ts
|
|
2
|
+
function parse(code) {
|
|
3
|
+
const ast = {
|
|
4
|
+
raw: code,
|
|
5
|
+
functions: [],
|
|
6
|
+
ias: [],
|
|
7
|
+
nodes: [],
|
|
8
|
+
modules: [],
|
|
9
|
+
objects: [],
|
|
10
|
+
forms: [],
|
|
11
|
+
animations: [],
|
|
12
|
+
logic: [],
|
|
13
|
+
parallels: [],
|
|
14
|
+
build: null,
|
|
15
|
+
evolve: null,
|
|
16
|
+
targets: [],
|
|
17
|
+
version: null
|
|
18
|
+
};
|
|
19
|
+
const lines = code.split(/\r?\n/);
|
|
20
|
+
let i = 0;
|
|
21
|
+
while (i < lines.length) {
|
|
22
|
+
const raw = lines[i];
|
|
23
|
+
const line = raw.trim();
|
|
24
|
+
if (!line) {
|
|
25
|
+
i++;
|
|
26
|
+
continue;
|
|
27
|
+
}
|
|
28
|
+
if (/^Σ\s+SYSTEM/i.test(line)) {
|
|
29
|
+
const m = line.match(/^Σ\s+SYSTEM\s+"([^"]+)"/i);
|
|
30
|
+
ast.system = m ? m[1] : line.replace(/^Σ\s+SYSTEM\s*/i, "");
|
|
31
|
+
i++;
|
|
32
|
+
continue;
|
|
33
|
+
}
|
|
34
|
+
if (/^Σ\s+VERSION/i.test(line)) {
|
|
35
|
+
const m = line.match(/^Σ\s+VERSION\s+([\d\.]+)/i);
|
|
36
|
+
ast.version = m ? m[1] : null;
|
|
37
|
+
i++;
|
|
38
|
+
continue;
|
|
39
|
+
}
|
|
40
|
+
if (/^Σ\s+TARGET/i.test(line)) {
|
|
41
|
+
const m = line.match(/^Σ\s+TARGET\s+(.+)/i);
|
|
42
|
+
if (m) {
|
|
43
|
+
const parts = m[1].split(/[+,\s]+/).map((s) => s.trim()).filter(Boolean);
|
|
44
|
+
ast.targets = [...ast.targets || [], ...parts];
|
|
45
|
+
}
|
|
46
|
+
i++;
|
|
47
|
+
continue;
|
|
48
|
+
}
|
|
49
|
+
if (/^Σ\s+MODE/i.test(line)) {
|
|
50
|
+
const m = line.match(/^Σ\s+MODE\s+([\w-]+)/i);
|
|
51
|
+
ast.mode = m ? m[1] : null;
|
|
52
|
+
i++;
|
|
53
|
+
continue;
|
|
54
|
+
}
|
|
55
|
+
if (/^Σ\s+UI/i.test(line)) {
|
|
56
|
+
const m = line.match(/^Σ\s+UI\s+([\w-]+)/i);
|
|
57
|
+
ast.ui = m ? m[1] : null;
|
|
58
|
+
i++;
|
|
59
|
+
continue;
|
|
60
|
+
}
|
|
61
|
+
if (/^Δ\s+([\w_]+)\s*\(([^)]*)\)/.test(line)) {
|
|
62
|
+
const m = line.match(/^Δ\s+([\w_]+)\s*\(([^)]*)\)/);
|
|
63
|
+
const name = m ? m[1] : "anonymous";
|
|
64
|
+
const argsRaw = m ? m[2] : "";
|
|
65
|
+
const args = argsRaw ? argsRaw.split(",").map((s) => s.trim()).filter(Boolean) : [];
|
|
66
|
+
const steps = [];
|
|
67
|
+
i++;
|
|
68
|
+
while (i < lines.length) {
|
|
69
|
+
const l = lines[i];
|
|
70
|
+
if (!l.trim()) {
|
|
71
|
+
i++;
|
|
72
|
+
continue;
|
|
73
|
+
}
|
|
74
|
+
if (/^→/.test(l.trim()) || /^\s+→/.test(l) || /^\s+/.test(l)) {
|
|
75
|
+
steps.push({ raw: l.trim().replace(/^→\s?/, "") });
|
|
76
|
+
i++;
|
|
77
|
+
} else {
|
|
78
|
+
break;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
const fn = { type: "function", name, args, steps };
|
|
82
|
+
ast.functions.push(fn);
|
|
83
|
+
ast.nodes.push(fn);
|
|
84
|
+
continue;
|
|
85
|
+
}
|
|
86
|
+
if (/^Ψ\s+IA\s+([\w-]+)\s*\{?/.test(line)) {
|
|
87
|
+
const m = line.match(/^Ψ\s+IA\s+([\w-]+)\s*\{?/);
|
|
88
|
+
const name = m ? m[1] : "ia";
|
|
89
|
+
const body = [];
|
|
90
|
+
if (/\{$/.test(line)) {
|
|
91
|
+
i++;
|
|
92
|
+
while (i < lines.length && !/\}/.test(lines[i])) {
|
|
93
|
+
body.push(lines[i].trim());
|
|
94
|
+
i++;
|
|
95
|
+
}
|
|
96
|
+
if (i < lines.length && /\}/.test(lines[i]))
|
|
97
|
+
i++;
|
|
98
|
+
} else {
|
|
99
|
+
i++;
|
|
100
|
+
while (i < lines.length) {
|
|
101
|
+
const l = lines[i];
|
|
102
|
+
if (!l.trim()) {
|
|
103
|
+
i++;
|
|
104
|
+
break;
|
|
105
|
+
}
|
|
106
|
+
if (/^Σ|^Δ|^Ψ/.test(l.trim()))
|
|
107
|
+
break;
|
|
108
|
+
body.push(l.trim());
|
|
109
|
+
i++;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
const ia = { type: "ia", name, body };
|
|
113
|
+
ast.ias.push(ia);
|
|
114
|
+
ast.nodes.push(ia);
|
|
115
|
+
continue;
|
|
116
|
+
}
|
|
117
|
+
if (/^Σ\s+EVOLVE/i.test(line)) {
|
|
118
|
+
const steps = [];
|
|
119
|
+
i++;
|
|
120
|
+
while (i < lines.length && !!lines[i].trim() && !/^Σ|^Δ|^Ψ|Ω|Φ|Θ|Λ|⊗/.test(lines[i].trim())) {
|
|
121
|
+
steps.push(lines[i].trim());
|
|
122
|
+
i++;
|
|
123
|
+
}
|
|
124
|
+
const ev = { type: "evolve", steps };
|
|
125
|
+
ast.evolve = ev;
|
|
126
|
+
ast.nodes.push(ev);
|
|
127
|
+
continue;
|
|
128
|
+
}
|
|
129
|
+
if (/^Σ\s+BUILD/i.test(line)) {
|
|
130
|
+
const targets = [];
|
|
131
|
+
i++;
|
|
132
|
+
while (i < lines.length && !!lines[i].trim() && !/^Σ|^Δ|^Ψ|Ω|Φ|Θ|Λ|⊗/.test(lines[i].trim())) {
|
|
133
|
+
const m = lines[i].trim().match(/target:\s*([\w-]+)/);
|
|
134
|
+
if (m)
|
|
135
|
+
targets.push(m[1]);
|
|
136
|
+
i++;
|
|
137
|
+
}
|
|
138
|
+
const b = { type: "build", targets };
|
|
139
|
+
ast.build = b;
|
|
140
|
+
ast.nodes.push(b);
|
|
141
|
+
continue;
|
|
142
|
+
}
|
|
143
|
+
if (/^Σ\s+MODULE/i.test(line)) {
|
|
144
|
+
const m = line.match(/^Σ\s+MODULE\s+"([^"]+)"/i);
|
|
145
|
+
const name = m ? m[1] : line.replace(/^Σ\s+MODULE\s*/i, "");
|
|
146
|
+
const module = { type: "module", name };
|
|
147
|
+
ast.modules.push(module);
|
|
148
|
+
ast.nodes.push(module);
|
|
149
|
+
i++;
|
|
150
|
+
continue;
|
|
151
|
+
}
|
|
152
|
+
if (/^Ω\s+([\w_]+)\s*\{?/.test(line)) {
|
|
153
|
+
const m = line.match(/^Ω\s+([\w_]+)\s*\{?/);
|
|
154
|
+
const name = m ? m[1] : "object";
|
|
155
|
+
const props = {};
|
|
156
|
+
if (/\{$/.test(line)) {
|
|
157
|
+
i++;
|
|
158
|
+
while (i < lines.length && !/\}/.test(lines[i])) {
|
|
159
|
+
const p = lines[i].trim();
|
|
160
|
+
const ma = p.match(/^([\w_]+)\s*:\s*"?([^\"]+)"?/);
|
|
161
|
+
if (ma)
|
|
162
|
+
props[ma[1]] = ma[2];
|
|
163
|
+
else if (p)
|
|
164
|
+
props[p] = null;
|
|
165
|
+
i++;
|
|
166
|
+
}
|
|
167
|
+
if (i < lines.length && /\}/.test(lines[i]))
|
|
168
|
+
i++;
|
|
169
|
+
}
|
|
170
|
+
const obj = { type: "object", name, props };
|
|
171
|
+
ast.objects.push(obj);
|
|
172
|
+
ast.nodes.push(obj);
|
|
173
|
+
continue;
|
|
174
|
+
}
|
|
175
|
+
if (/^Φ\s+([\w_]+)\s*\{?/.test(line)) {
|
|
176
|
+
const m = line.match(/^Φ\s+([\w_]+)\s*\{?/);
|
|
177
|
+
const name = m ? m[1] : "form";
|
|
178
|
+
const props = {};
|
|
179
|
+
if (/\{$/.test(line)) {
|
|
180
|
+
i++;
|
|
181
|
+
while (i < lines.length && !/\}/.test(lines[i])) {
|
|
182
|
+
const p = lines[i].trim();
|
|
183
|
+
const ma = p.match(/^([\w_]+)\s*:\s*"?([^\"]+)"?/);
|
|
184
|
+
if (ma)
|
|
185
|
+
props[ma[1]] = ma[2];
|
|
186
|
+
else if (p)
|
|
187
|
+
props[p] = true;
|
|
188
|
+
i++;
|
|
189
|
+
}
|
|
190
|
+
if (i < lines.length && /\}/.test(lines[i]))
|
|
191
|
+
i++;
|
|
192
|
+
}
|
|
193
|
+
const form = { type: "form", name, props };
|
|
194
|
+
ast.forms.push(form);
|
|
195
|
+
ast.nodes.push(form);
|
|
196
|
+
continue;
|
|
197
|
+
}
|
|
198
|
+
if (/^Θ\s+animation\s+"([^"]+)"/.test(line)) {
|
|
199
|
+
const m = line.match(/^Θ\s+animation\s+"([^"]+)"/);
|
|
200
|
+
const name = m ? m[1] : "anim";
|
|
201
|
+
const props = {};
|
|
202
|
+
i++;
|
|
203
|
+
while (i < lines.length && !!lines[i].trim() && !/^Σ|^Δ|^Ψ|Ω|Φ|Λ|⊗/.test(lines[i].trim())) {
|
|
204
|
+
const p = lines[i].trim();
|
|
205
|
+
const ma = p.match(/^([\w_]+)\s*:\s*(.+)/);
|
|
206
|
+
if (ma)
|
|
207
|
+
props[ma[1]] = ma[2].trim();
|
|
208
|
+
i++;
|
|
209
|
+
}
|
|
210
|
+
const anim = { type: "animation", name, props };
|
|
211
|
+
ast.animations.push(anim);
|
|
212
|
+
ast.nodes.push(anim);
|
|
213
|
+
continue;
|
|
214
|
+
}
|
|
215
|
+
if (/^Λ\s+if\s+/.test(line)) {
|
|
216
|
+
const ruleLines = [];
|
|
217
|
+
let trueFlow = [];
|
|
218
|
+
let falseFlow = [];
|
|
219
|
+
let rule = line.replace(/^Λ\s+/, "");
|
|
220
|
+
i++;
|
|
221
|
+
while (i < lines.length && !!lines[i].trim() && !/^Σ|^Δ|^Ψ|Ω|Φ|Θ|⊗/.test(lines[i].trim())) {
|
|
222
|
+
const l = lines[i].trim();
|
|
223
|
+
if (/^else/i.test(l)) {
|
|
224
|
+
i++;
|
|
225
|
+
break;
|
|
226
|
+
}
|
|
227
|
+
if (/^→/.test(l))
|
|
228
|
+
trueFlow.push(l.replace(/^→\s?/, "").trim());
|
|
229
|
+
ruleLines.push(l);
|
|
230
|
+
i++;
|
|
231
|
+
}
|
|
232
|
+
while (i < lines.length && !!lines[i].trim() && !/^Σ|^Δ|^Ψ|Ω|Φ|Θ|⊗/.test(lines[i].trim())) {
|
|
233
|
+
const l = lines[i].trim();
|
|
234
|
+
if (/^→/.test(l))
|
|
235
|
+
falseFlow.push(l.replace(/^→\s?/, "").trim());
|
|
236
|
+
i++;
|
|
237
|
+
}
|
|
238
|
+
const logic = { type: "logic", rule, trueFlow, falseFlow };
|
|
239
|
+
ast.logic.push(logic);
|
|
240
|
+
ast.nodes.push(logic);
|
|
241
|
+
continue;
|
|
242
|
+
}
|
|
243
|
+
if (/^⊗\s*\{?/.test(line)) {
|
|
244
|
+
const items = [];
|
|
245
|
+
if (/\{$/.test(line)) {
|
|
246
|
+
i++;
|
|
247
|
+
while (i < lines.length && !/\}/.test(lines[i])) {
|
|
248
|
+
const l = lines[i].trim();
|
|
249
|
+
if (l)
|
|
250
|
+
items.push(l);
|
|
251
|
+
i++;
|
|
252
|
+
}
|
|
253
|
+
if (i < lines.length && /\}/.test(lines[i]))
|
|
254
|
+
i++;
|
|
255
|
+
}
|
|
256
|
+
const par = { type: "parallel", items };
|
|
257
|
+
ast.parallels.push(par);
|
|
258
|
+
ast.nodes.push(par);
|
|
259
|
+
continue;
|
|
260
|
+
}
|
|
261
|
+
i++;
|
|
262
|
+
}
|
|
263
|
+
return ast;
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
// src/runENY.ts
|
|
267
|
+
function runENY(code) {
|
|
268
|
+
return parse(code);
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
export {
|
|
272
|
+
runENY
|
|
273
|
+
};
|