@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
@@ -0,0 +1,205 @@
1
+ /**
2
+ * @holoscript/core Enhanced Parser
3
+ *
4
+ * Improved error recovery, line/column tracking, better diagnostics
5
+ */
6
+ /**
7
+ * Enhanced parser with better error handling
8
+ */
9
+ export class EnhancedHoloScriptParser {
10
+ constructor(sourceCode) {
11
+ this.position = 0;
12
+ this.line = 1;
13
+ this.column = 0;
14
+ this.lineOffsets = [0];
15
+ this.errors = [];
16
+ this.tokens = this.tokenizeWithLocation(sourceCode);
17
+ }
18
+ /**
19
+ * Tokenize with line/column tracking
20
+ */
21
+ tokenizeWithLocation(source) {
22
+ const tokens = [];
23
+ let pos = 0;
24
+ let line = 1;
25
+ let column = 0;
26
+ for (let i = 0; i < source.length; i++) {
27
+ if (source[i] === '\n') {
28
+ line++;
29
+ column = 0;
30
+ this.lineOffsets.push(i + 1);
31
+ }
32
+ else {
33
+ column++;
34
+ }
35
+ // Simple tokenization (enhanced version would be more comprehensive)
36
+ if (/\s/.test(source[i]))
37
+ continue;
38
+ // Capture token with location
39
+ const token = {
40
+ type: this.getTokenType(source[i]),
41
+ value: source[i],
42
+ location: { line, column, offset: i },
43
+ };
44
+ tokens.push(token);
45
+ }
46
+ return tokens;
47
+ }
48
+ getTokenType(char) {
49
+ const typeMap = {
50
+ '{': 'lbrace',
51
+ '}': 'rbrace',
52
+ '[': 'lbracket',
53
+ ']': 'rbracket',
54
+ '(': 'lparen',
55
+ ')': 'rparen',
56
+ '@': 'at',
57
+ '#': 'hash',
58
+ ':': 'colon',
59
+ ',': 'comma',
60
+ '=': 'equals',
61
+ '.': 'dot',
62
+ };
63
+ return typeMap[char] || 'identifier';
64
+ }
65
+ /**
66
+ * Better error with suggestions
67
+ */
68
+ error(message, suggestion) {
69
+ const token = this.currentToken();
70
+ const location = token?.location || { line: this.line, column: this.column, offset: this.position };
71
+ const error = {
72
+ message,
73
+ location,
74
+ token,
75
+ suggestion: suggestion || this.suggestFix(message),
76
+ context: this.getErrorContext(location),
77
+ };
78
+ this.errors.push(error);
79
+ return error;
80
+ }
81
+ /**
82
+ * Suggest fixes based on error pattern
83
+ */
84
+ suggestFix(error) {
85
+ if (error.includes('Expected }')) {
86
+ return 'Check that all braces are balanced. Missing closing brace?';
87
+ }
88
+ if (error.includes('Expected identifier')) {
89
+ return 'Expected a name or identifier here (e.g., myOrb, myVariable)';
90
+ }
91
+ if (error.includes('Unexpected token')) {
92
+ const token = this.currentToken();
93
+ return `Remove or fix the '${token?.value}' token on this line`;
94
+ }
95
+ if (error.includes('Expected @')) {
96
+ return 'Traits must start with @ symbol (e.g., @grabbable, @voice_input)';
97
+ }
98
+ return 'Check syntax in this area';
99
+ }
100
+ /**
101
+ * Get error context from source
102
+ */
103
+ getErrorContext(location) {
104
+ const startLine = Math.max(0, location.line - 2);
105
+ const endLine = location.line + 1;
106
+ const lineNum = location.line;
107
+ let context = '';
108
+ for (let i = startLine; i < endLine; i++) {
109
+ const prefix = i === lineNum ? '→' : ' ';
110
+ context += `${prefix} ${i + 1} | <source line>\n`;
111
+ }
112
+ // Add pointer
113
+ context += ` | ${' '.repeat(location.column - 1)}^`;
114
+ return context;
115
+ }
116
+ /**
117
+ * Error recovery: skip to next statement
118
+ */
119
+ synchronize() {
120
+ this.advance();
121
+ while (!this.isAtEnd()) {
122
+ if (this.previous()?.type === 'newline')
123
+ return;
124
+ const current = this.currentToken();
125
+ if (current?.type === 'identifier' ||
126
+ current?.type === 'at' ||
127
+ current?.type === 'rbrace') {
128
+ return;
129
+ }
130
+ this.advance();
131
+ }
132
+ }
133
+ /**
134
+ * Get all collected errors
135
+ */
136
+ getErrors() {
137
+ return this.errors;
138
+ }
139
+ /**
140
+ * Check if any errors occurred
141
+ */
142
+ hasErrors() {
143
+ return this.errors.length > 0;
144
+ }
145
+ // Utility methods
146
+ currentToken() {
147
+ return this.tokens[this.position];
148
+ }
149
+ previous() {
150
+ return this.tokens[this.position - 1];
151
+ }
152
+ advance() {
153
+ if (!this.isAtEnd())
154
+ this.position++;
155
+ return this.previous();
156
+ }
157
+ isAtEnd() {
158
+ return this.position >= this.tokens.length;
159
+ }
160
+ match(...types) {
161
+ for (const type of types) {
162
+ if (this.check(type)) {
163
+ this.advance();
164
+ return true;
165
+ }
166
+ }
167
+ return false;
168
+ }
169
+ check(type) {
170
+ if (this.isAtEnd())
171
+ return false;
172
+ return this.currentToken()?.type === type;
173
+ }
174
+ expect(type, message) {
175
+ if (this.check(type))
176
+ return this.advance();
177
+ return this.error(message);
178
+ }
179
+ }
180
+ /**
181
+ * Format parser error for display
182
+ */
183
+ export function formatParseError(error) {
184
+ const { message, location, suggestion, context } = error;
185
+ return `
186
+ ❌ Parse Error: ${message}
187
+ at line ${location.line}, column ${location.column}
188
+
189
+ ${context}
190
+
191
+ 💡 Suggestion: ${suggestion || 'Check the syntax'}
192
+ `.trim();
193
+ }
194
+ /**
195
+ * Format all errors
196
+ */
197
+ export function formatParseErrors(errors) {
198
+ if (errors.length === 0)
199
+ return '';
200
+ let output = `\n❌ Found ${errors.length} parse error${errors.length !== 1 ? 's' : ''}:\n\n`;
201
+ for (let i = 0; i < errors.length; i++) {
202
+ output += `[${i + 1}/${errors.length}] ${formatParseError(errors[i])}\n\n`;
203
+ }
204
+ return output;
205
+ }
@@ -0,0 +1,251 @@
1
+ /**
2
+ * @holoscript/core Enhanced Parser
3
+ *
4
+ * Improved error recovery, line/column tracking, better diagnostics
5
+ */
6
+
7
+ export interface SourceLocation {
8
+ line: number;
9
+ column: number;
10
+ offset: number;
11
+ }
12
+
13
+ export interface ParseError {
14
+ message: string;
15
+ location: SourceLocation;
16
+ token: any;
17
+ suggestion?: string;
18
+ context?: string;
19
+ }
20
+
21
+ /**
22
+ * Enhanced parser with better error handling
23
+ */
24
+ export class EnhancedHoloScriptParser {
25
+ private tokens: any[];
26
+ private position: number = 0;
27
+ private line: number = 1;
28
+ private column: number = 0;
29
+ private lineOffsets: number[] = [0];
30
+ private errors: ParseError[] = [];
31
+
32
+ constructor(sourceCode: string) {
33
+ this.tokens = this.tokenizeWithLocation(sourceCode);
34
+ }
35
+
36
+ /**
37
+ * Tokenize with line/column tracking
38
+ */
39
+ private tokenizeWithLocation(source: string): any[] {
40
+ const tokens: any[] = [];
41
+ let pos = 0;
42
+ let line = 1;
43
+ let column = 0;
44
+
45
+ for (let i = 0; i < source.length; i++) {
46
+ if (source[i] === '\n') {
47
+ line++;
48
+ column = 0;
49
+ this.lineOffsets.push(i + 1);
50
+ } else {
51
+ column++;
52
+ }
53
+
54
+ // Simple tokenization (enhanced version would be more comprehensive)
55
+ if (/\s/.test(source[i])) continue;
56
+
57
+ // Capture token with location
58
+ const token = {
59
+ type: this.getTokenType(source[i]),
60
+ value: source[i],
61
+ location: { line, column, offset: i },
62
+ };
63
+
64
+ tokens.push(token);
65
+ }
66
+
67
+ return tokens;
68
+ }
69
+
70
+ private getTokenType(char: string): string {
71
+ const typeMap: Record<string, string> = {
72
+ '{': 'lbrace',
73
+ '}': 'rbrace',
74
+ '[': 'lbracket',
75
+ ']': 'rbracket',
76
+ '(': 'lparen',
77
+ ')': 'rparen',
78
+ '@': 'at',
79
+ '#': 'hash',
80
+ ':': 'colon',
81
+ ',': 'comma',
82
+ '=': 'equals',
83
+ '.': 'dot',
84
+ };
85
+ return typeMap[char] || 'identifier';
86
+ }
87
+
88
+ /**
89
+ * Better error with suggestions
90
+ */
91
+ error(message: string, suggestion?: string): ParseError {
92
+ const token = this.currentToken();
93
+ const location = token?.location || { line: this.line, column: this.column, offset: this.position };
94
+
95
+ const error: ParseError = {
96
+ message,
97
+ location,
98
+ token,
99
+ suggestion: suggestion || this.suggestFix(message),
100
+ context: this.getErrorContext(location),
101
+ };
102
+
103
+ this.errors.push(error);
104
+ return error;
105
+ }
106
+
107
+ /**
108
+ * Suggest fixes based on error pattern
109
+ */
110
+ private suggestFix(error: string): string {
111
+ if (error.includes('Expected }')) {
112
+ return 'Check that all braces are balanced. Missing closing brace?';
113
+ }
114
+ if (error.includes('Expected identifier')) {
115
+ return 'Expected a name or identifier here (e.g., myOrb, myVariable)';
116
+ }
117
+ if (error.includes('Unexpected token')) {
118
+ const token = this.currentToken();
119
+ return `Remove or fix the '${token?.value}' token on this line`;
120
+ }
121
+ if (error.includes('Expected @')) {
122
+ return 'Traits must start with @ symbol (e.g., @grabbable, @voice_input)';
123
+ }
124
+ return 'Check syntax in this area';
125
+ }
126
+
127
+ /**
128
+ * Get error context from source
129
+ */
130
+ private getErrorContext(location: SourceLocation): string {
131
+ const startLine = Math.max(0, location.line - 2);
132
+ const endLine = location.line + 1;
133
+ const lineNum = location.line;
134
+
135
+ let context = '';
136
+ for (let i = startLine; i < endLine; i++) {
137
+ const prefix = i === lineNum ? '→' : ' ';
138
+ context += `${prefix} ${i + 1} | <source line>\n`;
139
+ }
140
+
141
+ // Add pointer
142
+ context += ` | ${' '.repeat(location.column - 1)}^`;
143
+
144
+ return context;
145
+ }
146
+
147
+ /**
148
+ * Error recovery: skip to next statement
149
+ */
150
+ private synchronize(): void {
151
+ this.advance();
152
+
153
+ while (!this.isAtEnd()) {
154
+ if (this.previous()?.type === 'newline') return;
155
+
156
+ const current = this.currentToken();
157
+ if (
158
+ current?.type === 'identifier' ||
159
+ current?.type === 'at' ||
160
+ current?.type === 'rbrace'
161
+ ) {
162
+ return;
163
+ }
164
+
165
+ this.advance();
166
+ }
167
+ }
168
+
169
+ /**
170
+ * Get all collected errors
171
+ */
172
+ getErrors(): ParseError[] {
173
+ return this.errors;
174
+ }
175
+
176
+ /**
177
+ * Check if any errors occurred
178
+ */
179
+ hasErrors(): boolean {
180
+ return this.errors.length > 0;
181
+ }
182
+
183
+ // Utility methods
184
+ currentToken() {
185
+ return this.tokens[this.position];
186
+ }
187
+
188
+ private previous() {
189
+ return this.tokens[this.position - 1];
190
+ }
191
+
192
+ private advance() {
193
+ if (!this.isAtEnd()) this.position++;
194
+ return this.previous();
195
+ }
196
+
197
+ private isAtEnd(): boolean {
198
+ return this.position >= this.tokens.length;
199
+ }
200
+
201
+ private match(...types: string[]): boolean {
202
+ for (const type of types) {
203
+ if (this.check(type)) {
204
+ this.advance();
205
+ return true;
206
+ }
207
+ }
208
+ return false;
209
+ }
210
+
211
+ private check(type: string): boolean {
212
+ if (this.isAtEnd()) return false;
213
+ return this.currentToken()?.type === type;
214
+ }
215
+
216
+ private expect(type: string, message: string) {
217
+ if (this.check(type)) return this.advance();
218
+ return this.error(message);
219
+ }
220
+ }
221
+
222
+ /**
223
+ * Format parser error for display
224
+ */
225
+ export function formatParseError(error: ParseError): string {
226
+ const { message, location, suggestion, context } = error;
227
+
228
+ return `
229
+ ❌ Parse Error: ${message}
230
+ at line ${location.line}, column ${location.column}
231
+
232
+ ${context}
233
+
234
+ 💡 Suggestion: ${suggestion || 'Check the syntax'}
235
+ `.trim();
236
+ }
237
+
238
+ /**
239
+ * Format all errors
240
+ */
241
+ export function formatParseErrors(errors: ParseError[]): string {
242
+ if (errors.length === 0) return '';
243
+
244
+ let output = `\n❌ Found ${errors.length} parse error${errors.length !== 1 ? 's' : ''}:\n\n`;
245
+
246
+ for (let i = 0; i < errors.length; i++) {
247
+ output += `[${i + 1}/${errors.length}] ${formatParseError(errors[i])}\n\n`;
248
+ }
249
+
250
+ return output;
251
+ }