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