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