@holoscript/core 1.0.0-alpha.1 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (127) hide show
  1. package/package.json +10 -9
  2. package/src/HoloScript2DParser.js +227 -0
  3. package/src/HoloScript2DParser.ts +5 -0
  4. package/src/HoloScriptCodeParser.js +1102 -0
  5. package/src/HoloScriptCodeParser.ts +145 -20
  6. package/src/HoloScriptDebugger.js +458 -0
  7. package/src/HoloScriptParser.js +338 -0
  8. package/src/HoloScriptPlusParser.js +371 -0
  9. package/src/HoloScriptPlusParser.ts +543 -0
  10. package/src/HoloScriptRuntime.js +1399 -0
  11. package/src/HoloScriptRuntime.test.js +351 -0
  12. package/src/HoloScriptRuntime.ts +257 -3
  13. package/src/HoloScriptTypeChecker.js +356 -0
  14. package/src/__tests__/GraphicsServices.test.js +357 -0
  15. package/src/__tests__/GraphicsServices.test.ts +427 -0
  16. package/src/__tests__/HoloScriptPlusParser.test.js +317 -0
  17. package/src/__tests__/HoloScriptPlusParser.test.ts +392 -0
  18. package/src/__tests__/integration.test.js +336 -0
  19. package/src/__tests__/performance.bench.js +218 -0
  20. package/src/__tests__/type-checker.test.js +60 -0
  21. package/src/__tests__/type-checker.test.ts +73 -0
  22. package/src/index.js +217 -0
  23. package/src/index.ts +158 -18
  24. package/src/interop/Interoperability.js +413 -0
  25. package/src/interop/Interoperability.ts +494 -0
  26. package/src/logger.js +42 -0
  27. package/src/parser/EnhancedParser.js +205 -0
  28. package/src/parser/EnhancedParser.ts +251 -0
  29. package/src/parser/HoloScriptPlusParser.js +928 -0
  30. package/src/parser/HoloScriptPlusParser.ts +1089 -0
  31. package/src/runtime/HoloScriptPlusRuntime.js +674 -0
  32. package/src/runtime/HoloScriptPlusRuntime.ts +861 -0
  33. package/src/runtime/PerformanceTelemetry.js +323 -0
  34. package/src/runtime/PerformanceTelemetry.ts +467 -0
  35. package/src/runtime/RuntimeOptimization.js +361 -0
  36. package/src/runtime/RuntimeOptimization.ts +416 -0
  37. package/src/services/HololandGraphicsPipelineService.js +506 -0
  38. package/src/services/HololandGraphicsPipelineService.ts +662 -0
  39. package/src/services/PlatformPerformanceOptimizer.js +356 -0
  40. package/src/services/PlatformPerformanceOptimizer.ts +503 -0
  41. package/src/state/ReactiveState.js +427 -0
  42. package/src/state/ReactiveState.ts +572 -0
  43. package/src/tools/DeveloperExperience.js +376 -0
  44. package/src/tools/DeveloperExperience.ts +438 -0
  45. package/src/traits/AIDriverTrait.js +322 -0
  46. package/src/traits/AIDriverTrait.test.js +329 -0
  47. package/src/traits/AIDriverTrait.test.ts +357 -0
  48. package/src/traits/AIDriverTrait.ts +474 -0
  49. package/src/traits/LightingTrait.js +313 -0
  50. package/src/traits/LightingTrait.test.js +410 -0
  51. package/src/traits/LightingTrait.test.ts +462 -0
  52. package/src/traits/LightingTrait.ts +505 -0
  53. package/src/traits/MaterialTrait.js +194 -0
  54. package/src/traits/MaterialTrait.test.js +286 -0
  55. package/src/traits/MaterialTrait.test.ts +329 -0
  56. package/src/traits/MaterialTrait.ts +324 -0
  57. package/src/traits/RenderingTrait.js +356 -0
  58. package/src/traits/RenderingTrait.test.js +363 -0
  59. package/src/traits/RenderingTrait.test.ts +427 -0
  60. package/src/traits/RenderingTrait.ts +555 -0
  61. package/src/traits/VRTraitSystem.js +740 -0
  62. package/src/traits/VRTraitSystem.ts +1040 -0
  63. package/src/traits/VoiceInputTrait.js +284 -0
  64. package/src/traits/VoiceInputTrait.test.js +226 -0
  65. package/src/traits/VoiceInputTrait.test.ts +252 -0
  66. package/src/traits/VoiceInputTrait.ts +401 -0
  67. package/src/types/AdvancedTypeSystem.js +226 -0
  68. package/src/types/AdvancedTypeSystem.ts +494 -0
  69. package/src/types/HoloScriptPlus.d.ts +853 -0
  70. package/src/types.js +6 -0
  71. package/src/types.ts +96 -1
  72. package/tsconfig.json +1 -1
  73. package/tsup.config.d.ts +2 -0
  74. package/tsup.config.js +18 -0
  75. package/LICENSE +0 -21
  76. package/dist/chunk-3X2EGU7Z.cjs +0 -52
  77. package/dist/chunk-3X2EGU7Z.cjs.map +0 -1
  78. package/dist/chunk-723TPVHD.js +0 -1074
  79. package/dist/chunk-723TPVHD.js.map +0 -1
  80. package/dist/chunk-EOKNAVDO.cjs +0 -424
  81. package/dist/chunk-EOKNAVDO.cjs.map +0 -1
  82. package/dist/chunk-HQZ3HUMY.js +0 -1087
  83. package/dist/chunk-HQZ3HUMY.js.map +0 -1
  84. package/dist/chunk-KWYIVRIH.js +0 -344
  85. package/dist/chunk-KWYIVRIH.js.map +0 -1
  86. package/dist/chunk-LKH4ZAN6.js +0 -421
  87. package/dist/chunk-LKH4ZAN6.js.map +0 -1
  88. package/dist/chunk-SATNCODL.js +0 -45
  89. package/dist/chunk-SATNCODL.js.map +0 -1
  90. package/dist/chunk-VMZN4EVR.cjs +0 -347
  91. package/dist/chunk-VMZN4EVR.cjs.map +0 -1
  92. package/dist/chunk-VV3UUUYP.cjs +0 -1089
  93. package/dist/chunk-VV3UUUYP.cjs.map +0 -1
  94. package/dist/chunk-XRYTSQHZ.cjs +0 -1076
  95. package/dist/chunk-XRYTSQHZ.cjs.map +0 -1
  96. package/dist/debugger.cjs +0 -19
  97. package/dist/debugger.cjs.map +0 -1
  98. package/dist/debugger.d.cts +0 -171
  99. package/dist/debugger.d.ts +0 -171
  100. package/dist/debugger.js +0 -6
  101. package/dist/debugger.js.map +0 -1
  102. package/dist/index.cjs +0 -755
  103. package/dist/index.cjs.map +0 -1
  104. package/dist/index.d.cts +0 -169
  105. package/dist/index.d.ts +0 -169
  106. package/dist/index.js +0 -699
  107. package/dist/index.js.map +0 -1
  108. package/dist/parser.cjs +0 -13
  109. package/dist/parser.cjs.map +0 -1
  110. package/dist/parser.d.cts +0 -154
  111. package/dist/parser.d.ts +0 -154
  112. package/dist/parser.js +0 -4
  113. package/dist/parser.js.map +0 -1
  114. package/dist/runtime.cjs +0 -13
  115. package/dist/runtime.cjs.map +0 -1
  116. package/dist/runtime.d.cts +0 -147
  117. package/dist/runtime.d.ts +0 -147
  118. package/dist/runtime.js +0 -4
  119. package/dist/runtime.js.map +0 -1
  120. package/dist/type-checker.cjs +0 -16
  121. package/dist/type-checker.cjs.map +0 -1
  122. package/dist/type-checker.d.cts +0 -105
  123. package/dist/type-checker.d.ts +0 -105
  124. package/dist/type-checker.js +0 -3
  125. package/dist/type-checker.js.map +0 -1
  126. package/dist/types-WQSk1Qs2.d.cts +0 -238
  127. package/dist/types-WQSk1Qs2.d.ts +0 -238
@@ -1,1076 +0,0 @@
1
- 'use strict';
2
-
3
- var chunk3X2EGU7Z_cjs = require('./chunk-3X2EGU7Z.cjs');
4
-
5
- // src/HoloScriptCodeParser.ts
6
- var CODE_SECURITY_CONFIG = {
7
- maxCodeLength: 5e4,
8
- maxBlocks: 100,
9
- suspiciousKeywords: [
10
- "process",
11
- "require",
12
- "eval",
13
- "import",
14
- "constructor",
15
- "prototype",
16
- "__proto__",
17
- "fs",
18
- "child_process",
19
- "exec",
20
- "spawn"
21
- ]
22
- };
23
- var HoloScriptCodeParser = class {
24
- constructor() {
25
- this.errors = [];
26
- this.warnings = [];
27
- this.tokens = [];
28
- this.position = 0;
29
- }
30
- /**
31
- * Parse HoloScript code string into AST
32
- */
33
- parse(code) {
34
- this.errors = [];
35
- this.warnings = [];
36
- this.tokens = [];
37
- this.position = 0;
38
- if (code.length > CODE_SECURITY_CONFIG.maxCodeLength) {
39
- return {
40
- success: false,
41
- ast: [],
42
- errors: [{ line: 0, column: 0, message: `Code exceeds max length (${CODE_SECURITY_CONFIG.maxCodeLength})` }],
43
- warnings: []
44
- };
45
- }
46
- for (const keyword of CODE_SECURITY_CONFIG.suspiciousKeywords) {
47
- if (code.toLowerCase().includes(keyword)) {
48
- chunk3X2EGU7Z_cjs.logger.warn("Suspicious keyword detected", { keyword });
49
- return {
50
- success: false,
51
- ast: [],
52
- errors: [{ line: 0, column: 0, message: `Suspicious keyword detected: ${keyword}` }],
53
- warnings: []
54
- };
55
- }
56
- }
57
- try {
58
- this.tokens = this.tokenize(code);
59
- const ast = this.parseProgram();
60
- return {
61
- success: this.errors.length === 0,
62
- ast,
63
- errors: this.errors,
64
- warnings: this.warnings
65
- };
66
- } catch (error) {
67
- return {
68
- success: false,
69
- ast: [],
70
- errors: [{ line: 0, column: 0, message: String(error) }],
71
- warnings: this.warnings
72
- };
73
- }
74
- }
75
- /**
76
- * Tokenize code into tokens
77
- */
78
- tokenize(code) {
79
- const tokens = [];
80
- let line = 1;
81
- let column = 1;
82
- let i = 0;
83
- const keywords = [
84
- "orb",
85
- "function",
86
- "connect",
87
- "to",
88
- "as",
89
- "gate",
90
- "stream",
91
- "from",
92
- "through",
93
- "return",
94
- "if",
95
- "else",
96
- "nexus",
97
- "building",
98
- "pillar",
99
- "foundation",
100
- // Phase 2: Loop constructs
101
- "for",
102
- "while",
103
- "forEach",
104
- "in",
105
- "of",
106
- "break",
107
- "continue",
108
- // Phase 2: Module system
109
- "import",
110
- "export",
111
- "module",
112
- "use",
113
- // Phase 2: Type system
114
- "type",
115
- "interface",
116
- "extends",
117
- "implements",
118
- // Phase 2: Async
119
- "async",
120
- "await",
121
- "spawn",
122
- "parallel",
123
- // Phase 2: Object-oriented
124
- "class",
125
- "new",
126
- "this",
127
- "super",
128
- "static",
129
- "private",
130
- "public",
131
- // Phase 2: Error handling
132
- "try",
133
- "catch",
134
- "finally",
135
- "throw",
136
- // Phase 2: Constants
137
- "const",
138
- "let",
139
- "var",
140
- // Phase B: Data cells
141
- "data_cell",
142
- "data_zone",
143
- "data_source",
144
- "refresh",
145
- "position_offset",
146
- "props"
147
- ];
148
- while (i < code.length) {
149
- const char = code[i];
150
- if (char === " " || char === " " || char === "\r") {
151
- i++;
152
- column++;
153
- continue;
154
- }
155
- if (char === "\n") {
156
- tokens.push({ type: "newline", value: "\n", line, column });
157
- line++;
158
- column = 1;
159
- i++;
160
- continue;
161
- }
162
- if (char === "/" && code[i + 1] === "/") {
163
- while (i < code.length && code[i] !== "\n") {
164
- i++;
165
- }
166
- continue;
167
- }
168
- if (char === '"' || char === "'") {
169
- const quote = char;
170
- let str = "";
171
- const startCol = column;
172
- i++;
173
- column++;
174
- while (i < code.length && code[i] !== quote) {
175
- if (code[i] === "\\" && i + 1 < code.length) {
176
- str += code[i + 1];
177
- i += 2;
178
- column += 2;
179
- } else {
180
- str += code[i];
181
- i++;
182
- column++;
183
- }
184
- }
185
- i++;
186
- column++;
187
- tokens.push({ type: "string", value: str, line, column: startCol });
188
- continue;
189
- }
190
- if (/[0-9]/.test(char) || char === "-" && /[0-9]/.test(code[i + 1])) {
191
- let num = "";
192
- const startCol = column;
193
- while (i < code.length && /[0-9.\-]/.test(code[i])) {
194
- num += code[i];
195
- i++;
196
- column++;
197
- }
198
- tokens.push({ type: "number", value: num, line, column: startCol });
199
- continue;
200
- }
201
- if (/[a-zA-Z_]/.test(char)) {
202
- let ident = "";
203
- const startCol = column;
204
- while (i < code.length && /[a-zA-Z0-9_]/.test(code[i])) {
205
- ident += code[i];
206
- i++;
207
- column++;
208
- }
209
- const isKeyword = keywords.includes(ident.toLowerCase());
210
- tokens.push({
211
- type: isKeyword ? "keyword" : "identifier",
212
- value: ident,
213
- line,
214
- column: startCol
215
- });
216
- continue;
217
- }
218
- const multiCharOps = ["===", "!==", "==", "!=", ">=", "<=", "&&", "||", "++", "--", "+=", "-=", "*=", "/=", "%=", "=>", "->"];
219
- let foundMultiOp = false;
220
- for (const op of multiCharOps) {
221
- if (code.substring(i, i + op.length) === op) {
222
- tokens.push({ type: "operator", value: op, line, column });
223
- i += op.length;
224
- column += op.length;
225
- foundMultiOp = true;
226
- break;
227
- }
228
- }
229
- if (foundMultiOp) continue;
230
- const punctuation = ["{", "}", "(", ")", "[", "]", ":", ",", ".", ";", "=", "<", ">", "+", "-", "*", "/", "%", "!", "&", "|", "?"];
231
- if (punctuation.includes(char)) {
232
- tokens.push({ type: "punctuation", value: char, line, column });
233
- i++;
234
- column++;
235
- continue;
236
- }
237
- i++;
238
- column++;
239
- }
240
- return tokens;
241
- }
242
- /**
243
- * Parse program (list of declarations)
244
- */
245
- parseProgram() {
246
- const nodes = [];
247
- let blockCount = 0;
248
- while (this.position < this.tokens.length) {
249
- while (this.currentToken()?.type === "newline") {
250
- this.advance();
251
- }
252
- if (this.position >= this.tokens.length) break;
253
- blockCount++;
254
- if (blockCount > CODE_SECURITY_CONFIG.maxBlocks) {
255
- this.errors.push({ line: 0, column: 0, message: "Too many blocks in program" });
256
- break;
257
- }
258
- const node = this.parseDeclaration();
259
- if (node) {
260
- nodes.push(node);
261
- }
262
- }
263
- return nodes;
264
- }
265
- /**
266
- * Parse a single declaration
267
- */
268
- parseDeclaration() {
269
- const token = this.currentToken();
270
- if (!token) return null;
271
- if (token.type === "keyword") {
272
- switch (token.value.toLowerCase()) {
273
- case "orb":
274
- return this.parseOrb();
275
- case "function":
276
- return this.parseFunction();
277
- case "connect":
278
- return this.parseConnection();
279
- case "gate":
280
- case "if":
281
- return this.parseGate();
282
- case "stream":
283
- return this.parseStream();
284
- case "nexus":
285
- return this.parseNexus();
286
- case "building":
287
- case "class":
288
- return this.parseBuilding();
289
- // Phase 2: Loop constructs
290
- case "for":
291
- return this.parseForLoop();
292
- case "while":
293
- return this.parseWhileLoop();
294
- case "foreach":
295
- return this.parseForEachLoop();
296
- // Phase 2: Module system
297
- case "import":
298
- return this.parseImport();
299
- case "export":
300
- return this.parseExport();
301
- // Phase 2: Variable declarations
302
- case "const":
303
- case "let":
304
- case "var":
305
- return this.parseVariableDeclaration();
306
- // Phase B: Data cells
307
- case "data_cell":
308
- return this.parseDataCell();
309
- case "data_zone":
310
- return this.parseDataZone();
311
- default:
312
- this.advance();
313
- return null;
314
- }
315
- }
316
- this.advance();
317
- return null;
318
- }
319
- /**
320
- * Parse for loop: for (init; condition; update) { body }
321
- */
322
- parseForLoop() {
323
- this.expect("keyword", "for");
324
- if (!this.check("punctuation", "(")) {
325
- this.errors.push({ line: 0, column: 0, message: "Expected ( after for" });
326
- return null;
327
- }
328
- this.advance();
329
- let init = "", condition = "", update = "";
330
- let depth = 0;
331
- while (this.position < this.tokens.length) {
332
- const t = this.currentToken();
333
- if (!t) break;
334
- if (t.value === ";" && depth === 0) {
335
- this.advance();
336
- break;
337
- }
338
- if (t.value === "(") depth++;
339
- if (t.value === ")") depth--;
340
- init += t.value + " ";
341
- this.advance();
342
- }
343
- depth = 0;
344
- while (this.position < this.tokens.length) {
345
- const t = this.currentToken();
346
- if (!t) break;
347
- if (t.value === ";" && depth === 0) {
348
- this.advance();
349
- break;
350
- }
351
- if (t.value === "(") depth++;
352
- if (t.value === ")") depth--;
353
- condition += t.value + " ";
354
- this.advance();
355
- }
356
- depth = 0;
357
- while (this.position < this.tokens.length) {
358
- const t = this.currentToken();
359
- if (!t) break;
360
- if (t.value === ")" && depth === 0) {
361
- this.advance();
362
- break;
363
- }
364
- if (t.value === "(") depth++;
365
- if (t.value === ")") depth--;
366
- update += t.value + " ";
367
- this.advance();
368
- }
369
- const body = [];
370
- if (this.check("punctuation", "{")) {
371
- this.advance();
372
- let braceDepth = 1;
373
- while (braceDepth > 0 && this.position < this.tokens.length) {
374
- if (this.check("punctuation", "{")) braceDepth++;
375
- if (this.check("punctuation", "}")) braceDepth--;
376
- this.advance();
377
- }
378
- }
379
- return {
380
- type: "for-loop",
381
- init: init.trim(),
382
- condition: condition.trim(),
383
- update: update.trim(),
384
- body,
385
- position: { x: 0, y: 0, z: 0 }
386
- };
387
- }
388
- /**
389
- * Parse while loop: while (condition) { body }
390
- */
391
- parseWhileLoop() {
392
- this.expect("keyword", "while");
393
- let condition = "";
394
- if (this.check("punctuation", "(")) {
395
- this.advance();
396
- let depth = 1;
397
- while (depth > 0 && this.position < this.tokens.length) {
398
- const t = this.currentToken();
399
- if (!t) break;
400
- if (t.value === "(") depth++;
401
- if (t.value === ")") {
402
- depth--;
403
- if (depth === 0) {
404
- this.advance();
405
- break;
406
- }
407
- }
408
- condition += t.value + " ";
409
- this.advance();
410
- }
411
- }
412
- if (this.check("punctuation", "{")) {
413
- this.advance();
414
- let braceDepth = 1;
415
- while (braceDepth > 0 && this.position < this.tokens.length) {
416
- if (this.check("punctuation", "{")) braceDepth++;
417
- if (this.check("punctuation", "}")) braceDepth--;
418
- this.advance();
419
- }
420
- }
421
- return {
422
- type: "while-loop",
423
- condition: condition.trim(),
424
- body: [],
425
- position: { x: 0, y: 0, z: 0 }
426
- };
427
- }
428
- /**
429
- * Parse forEach loop: forEach item in collection { body }
430
- */
431
- parseForEachLoop() {
432
- this.expect("keyword", "forEach");
433
- const variable = this.expectIdentifier();
434
- this.expect("keyword", "in");
435
- const collection = this.expectIdentifier();
436
- if (this.check("punctuation", "{")) {
437
- this.advance();
438
- let braceDepth = 1;
439
- while (braceDepth > 0 && this.position < this.tokens.length) {
440
- if (this.check("punctuation", "{")) braceDepth++;
441
- if (this.check("punctuation", "}")) braceDepth--;
442
- this.advance();
443
- }
444
- }
445
- return {
446
- type: "foreach-loop",
447
- variable: variable || "item",
448
- collection: collection || "items",
449
- body: [],
450
- position: { x: 0, y: 0, z: 0 }
451
- };
452
- }
453
- /**
454
- * Parse import: import { x, y } from "module"
455
- */
456
- parseImport() {
457
- this.expect("keyword", "import");
458
- const imports = [];
459
- let modulePath = "";
460
- let defaultImport;
461
- if (this.check("punctuation", "{")) {
462
- this.advance();
463
- while (!this.check("punctuation", "}") && this.position < this.tokens.length) {
464
- const name = this.expectIdentifier();
465
- if (name) imports.push(name);
466
- if (this.check("punctuation", ",")) this.advance();
467
- }
468
- this.expect("punctuation", "}");
469
- } else {
470
- defaultImport = this.expectIdentifier() || void 0;
471
- }
472
- if (this.check("keyword", "from")) {
473
- this.advance();
474
- const pathToken = this.currentToken();
475
- if (pathToken?.type === "string") {
476
- modulePath = pathToken.value;
477
- this.advance();
478
- }
479
- }
480
- return {
481
- type: "import",
482
- imports,
483
- defaultImport,
484
- modulePath,
485
- position: { x: 0, y: 0, z: 0 }
486
- };
487
- }
488
- /**
489
- * Parse export: export { x, y } or export function/orb
490
- */
491
- parseExport() {
492
- this.expect("keyword", "export");
493
- const next = this.currentToken();
494
- if (next?.type === "keyword") {
495
- const declaration = this.parseDeclaration();
496
- return {
497
- type: "export",
498
- declaration: declaration || void 0,
499
- position: { x: 0, y: 0, z: 0 }
500
- };
501
- }
502
- const exports$1 = [];
503
- if (this.check("punctuation", "{")) {
504
- this.advance();
505
- while (!this.check("punctuation", "}") && this.position < this.tokens.length) {
506
- const name = this.expectIdentifier();
507
- if (name) exports$1.push(name);
508
- if (this.check("punctuation", ",")) this.advance();
509
- }
510
- this.expect("punctuation", "}");
511
- }
512
- return {
513
- type: "export",
514
- exports: exports$1,
515
- position: { x: 0, y: 0, z: 0 }
516
- };
517
- }
518
- /**
519
- * Parse variable declaration: const/let/var name = value
520
- */
521
- parseVariableDeclaration() {
522
- const kindToken = this.currentToken()?.value.toLowerCase();
523
- const kind = kindToken === "let" ? "let" : kindToken === "var" ? "var" : "const";
524
- this.advance();
525
- const name = this.expectIdentifier();
526
- if (!name) return null;
527
- let dataType;
528
- if (this.check("punctuation", ":")) {
529
- this.advance();
530
- dataType = this.expectIdentifier() || void 0;
531
- }
532
- let value;
533
- if (this.check("punctuation", "=")) {
534
- this.advance();
535
- const valueToken = this.currentToken();
536
- if (valueToken?.type === "string") {
537
- value = valueToken.value;
538
- this.advance();
539
- } else if (valueToken?.type === "number") {
540
- value = parseFloat(valueToken.value);
541
- this.advance();
542
- } else if (valueToken?.type === "identifier") {
543
- if (valueToken.value === "true") value = true;
544
- else if (valueToken.value === "false") value = false;
545
- else value = valueToken.value;
546
- this.advance();
547
- } else if (this.check("punctuation", "[")) {
548
- value = this.parseArray();
549
- } else if (this.check("punctuation", "{")) {
550
- value = this.parseObject();
551
- }
552
- }
553
- return {
554
- type: "variable-declaration",
555
- kind,
556
- name,
557
- dataType,
558
- value,
559
- position: { x: 0, y: 0, z: 0 }
560
- };
561
- }
562
- /**
563
- * Parse data_cell declaration
564
- *
565
- * Syntax:
566
- * data_cell {
567
- * type: "metric"
568
- * data_source: "/api/cpu"
569
- * refresh: 5s
570
- * position_offset: [0, 1, 0]
571
- * props: {
572
- * label: "CPU Usage"
573
- * style: { color: "#00ffff", glow: 0.5 }
574
- * }
575
- * }
576
- */
577
- parseDataCell() {
578
- const startToken = this.currentToken();
579
- this.expect("keyword", "data_cell");
580
- const node = {
581
- type: "data_cell",
582
- cellType: "text",
583
- props: {},
584
- position: { x: 0, y: 0, z: 0 },
585
- line: startToken?.line,
586
- column: startToken?.column
587
- };
588
- if (this.check("punctuation", "{")) {
589
- this.advance();
590
- while (!this.check("punctuation", "}") && this.position < this.tokens.length) {
591
- this.skipNewlines();
592
- if (this.check("punctuation", "}")) break;
593
- const prop = this.parseProperty();
594
- if (prop) {
595
- switch (prop.key) {
596
- case "type":
597
- node.cellType = prop.value;
598
- break;
599
- case "data_source":
600
- node.dataSource = String(prop.value);
601
- break;
602
- case "refresh":
603
- const refreshStr = String(prop.value);
604
- if (refreshStr.endsWith("ms")) {
605
- node.refresh = parseInt(refreshStr.replace("ms", ""), 10) / 1e3;
606
- } else if (refreshStr.endsWith("s")) {
607
- node.refresh = parseInt(refreshStr.replace("s", ""), 10);
608
- } else {
609
- node.refresh = parseFloat(refreshStr);
610
- }
611
- break;
612
- case "position_offset":
613
- if (Array.isArray(prop.value) && prop.value.length === 3) {
614
- node.positionOffset = prop.value.map(Number);
615
- }
616
- break;
617
- case "position":
618
- if (Array.isArray(prop.value) && prop.value.length === 3) {
619
- node.position = {
620
- x: Number(prop.value[0]),
621
- y: Number(prop.value[1]),
622
- z: Number(prop.value[2])
623
- };
624
- } else if (typeof prop.value === "object") {
625
- node.position = this.parsePosition(prop.value);
626
- }
627
- break;
628
- case "props":
629
- if (typeof prop.value === "object" && prop.value !== null) {
630
- node.props = { ...node.props, ...prop.value };
631
- }
632
- break;
633
- default:
634
- node.props[prop.key] = prop.value;
635
- }
636
- }
637
- this.skipNewlines();
638
- }
639
- this.expect("punctuation", "}");
640
- }
641
- return node;
642
- }
643
- /**
644
- * Parse data_zone declaration containing multiple data_cells
645
- *
646
- * Syntax:
647
- * data_zone bridge_metrics {
648
- * position: [0, 2, 0]
649
- * orientation: face_captain
650
- *
651
- * data_cell { ... }
652
- * data_cell { ... }
653
- * }
654
- */
655
- parseDataZone() {
656
- const startToken = this.currentToken();
657
- this.expect("keyword", "data_zone");
658
- const name = this.expectIdentifier();
659
- if (!name) return null;
660
- const node = {
661
- type: "data_zone",
662
- name,
663
- cells: [],
664
- position: { x: 0, y: 0, z: 0 },
665
- line: startToken?.line,
666
- column: startToken?.column
667
- };
668
- if (this.check("punctuation", "{")) {
669
- this.advance();
670
- while (!this.check("punctuation", "}") && this.position < this.tokens.length) {
671
- this.skipNewlines();
672
- if (this.check("punctuation", "}")) break;
673
- if (this.check("keyword", "data_cell")) {
674
- const cell = this.parseDataCell();
675
- if (cell) {
676
- node.cells.push(cell);
677
- }
678
- } else {
679
- const prop = this.parseProperty();
680
- if (prop) {
681
- switch (prop.key) {
682
- case "position":
683
- if (Array.isArray(prop.value) && prop.value.length === 3) {
684
- node.position = {
685
- x: Number(prop.value[0]),
686
- y: Number(prop.value[1]),
687
- z: Number(prop.value[2])
688
- };
689
- } else if (typeof prop.value === "object") {
690
- node.position = this.parsePosition(prop.value);
691
- }
692
- break;
693
- case "orientation":
694
- node.orientation = String(prop.value);
695
- break;
696
- }
697
- }
698
- }
699
- this.skipNewlines();
700
- }
701
- this.expect("punctuation", "}");
702
- }
703
- return node;
704
- }
705
- /**
706
- * Parse orb declaration
707
- */
708
- parseOrb() {
709
- this.expect("keyword", "orb");
710
- const name = this.expectIdentifier();
711
- if (!name) return null;
712
- const properties = {};
713
- let position;
714
- let hologram;
715
- if (this.check("punctuation", "{")) {
716
- this.advance();
717
- while (!this.check("punctuation", "}") && this.position < this.tokens.length) {
718
- this.skipNewlines();
719
- if (this.check("punctuation", "}")) break;
720
- const prop = this.parseProperty();
721
- if (prop) {
722
- if (prop.key === "position" || prop.key === "at") {
723
- position = this.parsePosition(prop.value);
724
- } else if (prop.key === "color" || prop.key === "glow" || prop.key === "size") {
725
- hologram = hologram || { shape: "orb", color: "#00ffff", size: 1, glow: true, interactive: true };
726
- if (prop.key === "color") hologram.color = String(prop.value);
727
- if (prop.key === "glow") hologram.glow = Boolean(prop.value);
728
- if (prop.key === "size") hologram.size = Number(prop.value);
729
- } else {
730
- properties[prop.key] = prop.value;
731
- }
732
- }
733
- this.skipNewlines();
734
- }
735
- this.expect("punctuation", "}");
736
- }
737
- return {
738
- type: "orb",
739
- name,
740
- position: position || { x: 0, y: 0, z: 0 },
741
- hologram: hologram || { shape: "orb", color: "#00ffff", size: 1, glow: true, interactive: true },
742
- properties,
743
- methods: []
744
- };
745
- }
746
- /**
747
- * Parse function declaration
748
- */
749
- parseFunction() {
750
- this.expect("keyword", "function");
751
- const name = this.expectIdentifier();
752
- if (!name) return null;
753
- const parameters = [];
754
- let returnType;
755
- if (this.check("punctuation", "(")) {
756
- this.advance();
757
- while (!this.check("punctuation", ")") && this.position < this.tokens.length) {
758
- const paramName = this.expectIdentifier();
759
- if (!paramName) break;
760
- let paramType = "any";
761
- if (this.check("punctuation", ":")) {
762
- this.advance();
763
- paramType = this.expectIdentifier() || "any";
764
- }
765
- parameters.push({
766
- type: "parameter",
767
- name: paramName,
768
- dataType: paramType
769
- });
770
- if (this.check("punctuation", ",")) {
771
- this.advance();
772
- }
773
- }
774
- this.expect("punctuation", ")");
775
- }
776
- if (this.check("punctuation", ":")) {
777
- this.advance();
778
- returnType = this.expectIdentifier() || void 0;
779
- }
780
- const body = [];
781
- if (this.check("punctuation", "{")) {
782
- this.advance();
783
- let depth = 1;
784
- while (depth > 0 && this.position < this.tokens.length) {
785
- if (this.check("punctuation", "{")) depth++;
786
- if (this.check("punctuation", "}")) depth--;
787
- this.advance();
788
- }
789
- }
790
- return {
791
- type: "method",
792
- name,
793
- parameters,
794
- body,
795
- returnType,
796
- position: { x: 0, y: 0, z: 0 },
797
- hologram: { shape: "cube", color: "#ff6b35", size: 1.5, glow: true, interactive: true }
798
- };
799
- }
800
- /**
801
- * Parse connection
802
- */
803
- parseConnection() {
804
- this.expect("keyword", "connect");
805
- const from = this.expectIdentifier();
806
- if (!from) return null;
807
- this.expect("keyword", "to");
808
- const to = this.expectIdentifier();
809
- if (!to) return null;
810
- let dataType = "any";
811
- if (this.check("keyword", "as")) {
812
- this.advance();
813
- const typeStr = this.currentToken();
814
- if (typeStr?.type === "string" || typeStr?.type === "identifier") {
815
- dataType = typeStr.value;
816
- this.advance();
817
- }
818
- }
819
- return {
820
- type: "connection",
821
- from,
822
- to,
823
- dataType,
824
- bidirectional: false
825
- };
826
- }
827
- /**
828
- * Parse gate (conditional)
829
- */
830
- parseGate() {
831
- this.expect("keyword", "gate");
832
- this.expectIdentifier();
833
- let condition = "";
834
- if (this.check("punctuation", "(")) {
835
- this.advance();
836
- while (!this.check("punctuation", ")") && this.position < this.tokens.length) {
837
- const token = this.currentToken();
838
- if (token) condition += token.value + " ";
839
- this.advance();
840
- }
841
- this.expect("punctuation", ")");
842
- }
843
- if (this.check("punctuation", "{")) {
844
- this.advance();
845
- let depth = 1;
846
- while (depth > 0 && this.position < this.tokens.length) {
847
- if (this.check("punctuation", "{")) depth++;
848
- if (this.check("punctuation", "}")) depth--;
849
- this.advance();
850
- }
851
- }
852
- return {
853
- type: "gate",
854
- condition: condition.trim(),
855
- truePath: [],
856
- falsePath: [],
857
- position: { x: 0, y: 0, z: 0 },
858
- hologram: { shape: "pyramid", color: "#4ecdc4", size: 1, glow: true, interactive: true }
859
- };
860
- }
861
- /**
862
- * Parse stream
863
- */
864
- parseStream() {
865
- this.expect("keyword", "stream");
866
- const name = this.expectIdentifier();
867
- if (!name) return null;
868
- let source = "unknown";
869
- if (this.check("keyword", "from")) {
870
- this.advance();
871
- source = this.expectIdentifier() || "unknown";
872
- }
873
- if (this.check("punctuation", "{")) {
874
- this.advance();
875
- let depth = 1;
876
- while (depth > 0 && this.position < this.tokens.length) {
877
- if (this.check("punctuation", "{")) depth++;
878
- if (this.check("punctuation", "}")) depth--;
879
- this.advance();
880
- }
881
- }
882
- return {
883
- type: "stream",
884
- name,
885
- source,
886
- transformations: [],
887
- position: { x: 0, y: 0, z: 0 },
888
- hologram: { shape: "cylinder", color: "#45b7d1", size: 2, glow: true, interactive: true }
889
- };
890
- }
891
- /**
892
- * Parse nexus (multi-agent hub)
893
- */
894
- parseNexus() {
895
- this.expect("keyword", "nexus");
896
- const name = this.expectIdentifier();
897
- if (!name) return null;
898
- if (this.check("punctuation", "{")) {
899
- this.advance();
900
- let depth = 1;
901
- while (depth > 0 && this.position < this.tokens.length) {
902
- if (this.check("punctuation", "{")) depth++;
903
- if (this.check("punctuation", "}")) depth--;
904
- this.advance();
905
- }
906
- }
907
- return {
908
- type: "nexus",
909
- position: { x: 0, y: 0, z: 0 },
910
- hologram: { shape: "sphere", color: "#9b59b6", size: 3, glow: true, interactive: true }
911
- };
912
- }
913
- /**
914
- * Parse building (class-like)
915
- */
916
- parseBuilding() {
917
- this.expect("keyword", "building");
918
- const name = this.expectIdentifier();
919
- if (!name) return null;
920
- if (this.check("punctuation", "{")) {
921
- this.advance();
922
- let depth = 1;
923
- while (depth > 0 && this.position < this.tokens.length) {
924
- if (this.check("punctuation", "{")) depth++;
925
- if (this.check("punctuation", "}")) depth--;
926
- this.advance();
927
- }
928
- }
929
- return {
930
- type: "building",
931
- position: { x: 0, y: 0, z: 0 },
932
- hologram: { shape: "cube", color: "#e74c3c", size: 4, glow: true, interactive: true }
933
- };
934
- }
935
- /**
936
- * Parse a property (key: value)
937
- */
938
- parseProperty() {
939
- const key = this.expectIdentifier();
940
- if (!key) return null;
941
- if (!this.check("punctuation", ":")) {
942
- return { key, value: true };
943
- }
944
- this.advance();
945
- const valueToken = this.currentToken();
946
- if (!valueToken) return null;
947
- let value;
948
- if (valueToken.type === "string") {
949
- value = valueToken.value;
950
- this.advance();
951
- } else if (valueToken.type === "number") {
952
- value = parseFloat(valueToken.value);
953
- this.advance();
954
- } else if (valueToken.type === "identifier") {
955
- if (valueToken.value === "true") value = true;
956
- else if (valueToken.value === "false") value = false;
957
- else value = valueToken.value;
958
- this.advance();
959
- } else if (this.check("punctuation", "[")) {
960
- value = this.parseArray();
961
- } else if (this.check("punctuation", "{")) {
962
- value = this.parseObject();
963
- } else {
964
- value = valueToken.value;
965
- this.advance();
966
- }
967
- return { key, value };
968
- }
969
- /**
970
- * Parse array [...]
971
- */
972
- parseArray() {
973
- const arr = [];
974
- this.expect("punctuation", "[");
975
- while (!this.check("punctuation", "]") && this.position < this.tokens.length) {
976
- const token = this.currentToken();
977
- if (token?.type === "string" || token?.type === "number" || token?.type === "identifier") {
978
- if (token.type === "number") {
979
- arr.push(parseFloat(token.value));
980
- } else {
981
- arr.push(token.value);
982
- }
983
- this.advance();
984
- }
985
- if (this.check("punctuation", ",")) {
986
- this.advance();
987
- }
988
- }
989
- this.expect("punctuation", "]");
990
- return arr;
991
- }
992
- /**
993
- * Parse object {...}
994
- */
995
- parseObject() {
996
- const obj = {};
997
- this.expect("punctuation", "{");
998
- while (!this.check("punctuation", "}") && this.position < this.tokens.length) {
999
- this.skipNewlines();
1000
- if (this.check("punctuation", "}")) break;
1001
- const prop = this.parseProperty();
1002
- if (prop) {
1003
- obj[prop.key] = prop.value;
1004
- }
1005
- this.skipNewlines();
1006
- if (this.check("punctuation", ",")) {
1007
- this.advance();
1008
- }
1009
- }
1010
- this.expect("punctuation", "}");
1011
- return obj;
1012
- }
1013
- /**
1014
- * Parse position from value
1015
- */
1016
- parsePosition(value) {
1017
- if (typeof value === "object" && value !== null) {
1018
- const v = value;
1019
- return {
1020
- x: Number(v.x) || 0,
1021
- y: Number(v.y) || 0,
1022
- z: Number(v.z) || 0
1023
- };
1024
- }
1025
- return { x: 0, y: 0, z: 0 };
1026
- }
1027
- // Helper methods
1028
- currentToken() {
1029
- return this.tokens[this.position];
1030
- }
1031
- advance() {
1032
- return this.tokens[this.position++];
1033
- }
1034
- check(type, value) {
1035
- const token = this.currentToken();
1036
- if (!token) return false;
1037
- if (token.type !== type) return false;
1038
- if (value !== void 0 && token.value.toLowerCase() !== value.toLowerCase()) return false;
1039
- return true;
1040
- }
1041
- expect(type, value) {
1042
- if (this.check(type, value)) {
1043
- this.advance();
1044
- return true;
1045
- }
1046
- const token = this.currentToken();
1047
- this.errors.push({
1048
- line: token?.line || 0,
1049
- column: token?.column || 0,
1050
- message: `Expected ${type}${value ? ` '${value}'` : ""}, got ${token?.type || "EOF"} '${token?.value || ""}'`
1051
- });
1052
- return false;
1053
- }
1054
- expectIdentifier() {
1055
- const token = this.currentToken();
1056
- if (token?.type === "identifier" || token?.type === "keyword") {
1057
- this.advance();
1058
- return token.value;
1059
- }
1060
- this.errors.push({
1061
- line: token?.line || 0,
1062
- column: token?.column || 0,
1063
- message: `Expected identifier, got ${token?.type || "EOF"}`
1064
- });
1065
- return null;
1066
- }
1067
- skipNewlines() {
1068
- while (this.currentToken()?.type === "newline") {
1069
- this.advance();
1070
- }
1071
- }
1072
- };
1073
-
1074
- exports.HoloScriptCodeParser = HoloScriptCodeParser;
1075
- //# sourceMappingURL=chunk-XRYTSQHZ.cjs.map
1076
- //# sourceMappingURL=chunk-XRYTSQHZ.cjs.map