@holoscript/core 1.0.0-alpha.2 → 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 (74) hide show
  1. package/package.json +2 -2
  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 +17 -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
@@ -0,0 +1,376 @@
1
+ /**
2
+ * @holoscript/core Developer Experience
3
+ *
4
+ * REPL, better error formatting, interactive mode
5
+ */
6
+ import * as readline from 'readline';
7
+ /**
8
+ * Enhanced error formatter
9
+ */
10
+ export class ErrorFormatter {
11
+ /**
12
+ * Format error with source context
13
+ */
14
+ static formatError(error, sourceCode) {
15
+ const { message, location, suggestion, token } = error;
16
+ let formatted = `\nāŒ Error: ${message}\n`;
17
+ if (location) {
18
+ formatted += ` at line ${location.line}, column ${location.column}\n`;
19
+ if (sourceCode) {
20
+ const lines = sourceCode.split('\n');
21
+ const errorLine = lines[location.line - 1];
22
+ if (errorLine) {
23
+ formatted += `\n ${location.line} | ${errorLine}\n`;
24
+ formatted += ` | ${' '.repeat(location.column - 1)}^\n`;
25
+ }
26
+ }
27
+ }
28
+ if (suggestion) {
29
+ formatted += `\nšŸ’” Suggestion: ${suggestion}\n`;
30
+ }
31
+ return formatted;
32
+ }
33
+ /**
34
+ * Format multiple errors
35
+ */
36
+ static formatErrors(errors) {
37
+ if (errors.length === 0)
38
+ return '';
39
+ let formatted = `\nāŒ Found ${errors.length} error${errors.length !== 1 ? 's' : ''}:\n`;
40
+ for (let i = 0; i < Math.min(errors.length, 5); i++) {
41
+ formatted += this.formatError(errors[i]);
42
+ }
43
+ if (errors.length > 5) {
44
+ formatted += `\n... and ${errors.length - 5} more error${errors.length - 5 !== 1 ? 's' : ''}\n`;
45
+ }
46
+ return formatted;
47
+ }
48
+ /**
49
+ * Format success message
50
+ */
51
+ static formatSuccess(message, details) {
52
+ let formatted = `\nāœ… ${message}\n`;
53
+ if (details) {
54
+ if (typeof details === 'object') {
55
+ formatted += JSON.stringify(details, null, 2) + '\n';
56
+ }
57
+ else {
58
+ formatted += `${details}\n`;
59
+ }
60
+ }
61
+ return formatted;
62
+ }
63
+ /**
64
+ * Format help text
65
+ */
66
+ static formatHelp() {
67
+ return `
68
+ HoloScript+ REPL v1.0.0
69
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
70
+
71
+ Commands:
72
+ help - Show this help message
73
+ clear - Clear the screen
74
+ vars - List all variables
75
+ types - List all types
76
+ profile - Show performance profile
77
+ exit - Exit REPL
78
+
79
+ Shortcuts:
80
+ .create orb#name - Create orb
81
+ .position x y z - Set position
82
+ .property key val - Set property
83
+
84
+ Examples:
85
+ > orb#myOrb { position: [0, 0, 0] }
86
+ > myOrb.position = [1, 1, 1]
87
+ > match state { "idle" => { ... } }
88
+
89
+ For more info, visit: https://github.com/brianonbased-dev/holoscript
90
+ `.trim();
91
+ }
92
+ }
93
+ /**
94
+ * Interactive REPL
95
+ */
96
+ export class HoloScriptREPL {
97
+ constructor(parser, runtime) {
98
+ this.variables = new Map();
99
+ this.types = new Map();
100
+ this.history = [];
101
+ this.parser = parser;
102
+ this.runtime = runtime;
103
+ this.rl = readline.createInterface({
104
+ input: process.stdin,
105
+ output: process.stdout,
106
+ history: this.history,
107
+ historySize: 100,
108
+ });
109
+ }
110
+ /**
111
+ * Start REPL
112
+ */
113
+ async start() {
114
+ console.log('\n🄽 HoloScript+ REPL v1.0.0');
115
+ console.log('Type "help" for commands, "exit" to quit\n');
116
+ await this.repl();
117
+ }
118
+ /**
119
+ * Main REPL loop
120
+ */
121
+ async repl() {
122
+ const prompt = () => {
123
+ this.rl.question('> ', async (input) => {
124
+ try {
125
+ const trimmed = input.trim();
126
+ if (!trimmed) {
127
+ prompt();
128
+ return;
129
+ }
130
+ // Handle commands
131
+ if (trimmed.startsWith('.')) {
132
+ this.handleCommand(trimmed);
133
+ prompt();
134
+ return;
135
+ }
136
+ // Handle built-in commands
137
+ switch (trimmed.toLowerCase()) {
138
+ case 'help':
139
+ console.log(ErrorFormatter.formatHelp());
140
+ prompt();
141
+ return;
142
+ case 'clear':
143
+ console.clear();
144
+ prompt();
145
+ return;
146
+ case 'vars':
147
+ this.showVariables();
148
+ prompt();
149
+ return;
150
+ case 'types':
151
+ this.showTypes();
152
+ prompt();
153
+ return;
154
+ case 'profile':
155
+ this.showProfile();
156
+ prompt();
157
+ return;
158
+ case 'exit':
159
+ this.rl.close();
160
+ console.log('\nšŸ‘‹ Goodbye!\n');
161
+ return;
162
+ }
163
+ // Parse and execute
164
+ const result = await this.evaluate(trimmed);
165
+ if (result !== undefined && result !== null) {
166
+ this.displayResult(result);
167
+ }
168
+ }
169
+ catch (error) {
170
+ console.error(ErrorFormatter.formatError(error));
171
+ }
172
+ prompt();
173
+ });
174
+ };
175
+ prompt();
176
+ }
177
+ /**
178
+ * Handle dot commands
179
+ */
180
+ handleCommand(command) {
181
+ const parts = command.slice(1).split(' ');
182
+ const cmd = parts[0];
183
+ switch (cmd) {
184
+ case 'create':
185
+ console.log(`Creating: ${parts.slice(1).join(' ')}`);
186
+ break;
187
+ case 'position':
188
+ console.log(`Position: x=${parts[1]}, y=${parts[2]}, z=${parts[3]}`);
189
+ break;
190
+ case 'property':
191
+ console.log(`Property: ${parts[1]} = ${parts[2]}`);
192
+ break;
193
+ default:
194
+ console.log(`Unknown command: .${cmd}`);
195
+ }
196
+ }
197
+ /**
198
+ * Evaluate HoloScript code
199
+ */
200
+ async evaluate(code) {
201
+ try {
202
+ const parseResult = this.parser.parse(code);
203
+ if (parseResult.errors && parseResult.errors.length > 0) {
204
+ throw {
205
+ message: 'Parse error',
206
+ errors: parseResult.errors,
207
+ };
208
+ }
209
+ const result = await this.runtime.execute(parseResult.ast);
210
+ return result;
211
+ }
212
+ catch (error) {
213
+ throw error;
214
+ }
215
+ }
216
+ /**
217
+ * Show variables
218
+ */
219
+ showVariables() {
220
+ if (this.variables.size === 0) {
221
+ console.log('No variables defined');
222
+ return;
223
+ }
224
+ console.log('\nšŸ“¦ Variables:');
225
+ for (const [name, value] of this.variables) {
226
+ console.log(` ${name}: ${this.formatValue(value)}`);
227
+ }
228
+ console.log();
229
+ }
230
+ /**
231
+ * Show types
232
+ */
233
+ showTypes() {
234
+ if (this.types.size === 0) {
235
+ console.log('No custom types defined');
236
+ return;
237
+ }
238
+ console.log('\nšŸ·ļø Types:');
239
+ for (const [name, type] of this.types) {
240
+ console.log(` ${name}: ${JSON.stringify(type)}`);
241
+ }
242
+ console.log();
243
+ }
244
+ /**
245
+ * Show performance profile
246
+ */
247
+ showProfile() {
248
+ console.log('\nā±ļø Performance Profile:');
249
+ console.log(' (Profiling data would be displayed here)');
250
+ console.log();
251
+ }
252
+ /**
253
+ * Display result
254
+ */
255
+ displayResult(result) {
256
+ const formatted = this.formatValue(result);
257
+ console.log(`=> ${formatted}`);
258
+ }
259
+ /**
260
+ * Format value for display
261
+ */
262
+ formatValue(value) {
263
+ if (value === null)
264
+ return 'null';
265
+ if (value === undefined)
266
+ return 'undefined';
267
+ if (typeof value === 'string')
268
+ return `"${value}"`;
269
+ if (typeof value === 'number')
270
+ return `${value}`;
271
+ if (typeof value === 'boolean')
272
+ return `${value}`;
273
+ if (Array.isArray(value)) {
274
+ return `[ ${value.map((v) => this.formatValue(v)).join(', ')} ]`;
275
+ }
276
+ if (typeof value === 'object') {
277
+ const pairs = Object.entries(value)
278
+ .map(([k, v]) => `${k}: ${this.formatValue(v)}`)
279
+ .join(', ');
280
+ return `{ ${pairs} }`;
281
+ }
282
+ return String(value);
283
+ }
284
+ }
285
+ /**
286
+ * Create and start REPL
287
+ */
288
+ export async function startREPL(parser, runtime) {
289
+ const repl = new HoloScriptREPL(parser, runtime);
290
+ await repl.start();
291
+ }
292
+ /**
293
+ * Hot reload watcher for development
294
+ */
295
+ export class HotReloadWatcher {
296
+ constructor() {
297
+ this.watchers = new Map();
298
+ }
299
+ /**
300
+ * Watch file for changes
301
+ */
302
+ watch(filePath, callback) {
303
+ // Using basic fs.watch (production would use chokidar)
304
+ const fs = require('fs');
305
+ fs.watchFile(filePath, { interval: 1000 }, async () => {
306
+ try {
307
+ console.log(`\nšŸ”„ Reloading: ${filePath}`);
308
+ await callback();
309
+ console.log('āœ… Reload complete\n');
310
+ }
311
+ catch (error) {
312
+ console.error(ErrorFormatter.formatError(error));
313
+ }
314
+ });
315
+ this.watchers.set(filePath, true);
316
+ }
317
+ /**
318
+ * Stop watching
319
+ */
320
+ unwatch(filePath) {
321
+ const fs = require('fs');
322
+ fs.unwatchFile(filePath);
323
+ this.watchers.delete(filePath);
324
+ }
325
+ /**
326
+ * Stop all watchers
327
+ */
328
+ clear() {
329
+ const fs = require('fs');
330
+ for (const filePath of this.watchers.keys()) {
331
+ fs.unwatchFile(filePath);
332
+ }
333
+ this.watchers.clear();
334
+ }
335
+ }
336
+ /**
337
+ * Source map generator
338
+ */
339
+ export class SourceMapGenerator {
340
+ constructor() {
341
+ this.mappings = [];
342
+ }
343
+ /**
344
+ * Add mapping
345
+ */
346
+ addMapping(generatedLine, generatedColumn, sourceLine, sourceColumn, name) {
347
+ this.mappings.push({
348
+ generatedLine,
349
+ generatedColumn,
350
+ sourceLine,
351
+ sourceColumn,
352
+ name,
353
+ });
354
+ }
355
+ /**
356
+ * Generate source map
357
+ */
358
+ generate(sourceFile, generatedFile) {
359
+ return {
360
+ version: 3,
361
+ file: generatedFile,
362
+ sourceRoot: '',
363
+ sources: [sourceFile],
364
+ sourcesContent: [],
365
+ mappings: this.encodeMappings(),
366
+ names: [],
367
+ };
368
+ }
369
+ /**
370
+ * Encode mappings in VLQ format
371
+ */
372
+ encodeMappings() {
373
+ // Simplified VLQ encoding
374
+ return this.mappings.map((m) => `${m.generatedLine}:${m.generatedColumn}->${m.sourceLine}:${m.sourceColumn}`).join(';');
375
+ }
376
+ }