@holoscript/core 2.0.1 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chunk-2XXE34KS.js +344 -0
- package/dist/chunk-2XXE34KS.js.map +1 -0
- package/dist/chunk-3X2EGU7Z.cjs +52 -0
- package/dist/chunk-3X2EGU7Z.cjs.map +1 -0
- package/dist/chunk-AFFVFO4D.js +1689 -0
- package/dist/chunk-AFFVFO4D.js.map +1 -0
- package/dist/chunk-DGUM43GV.js +10 -0
- package/dist/chunk-DGUM43GV.js.map +1 -0
- package/{src/HoloScriptDebugger.ts → dist/chunk-DOY73HDH.js} +118 -257
- package/dist/chunk-DOY73HDH.js.map +1 -0
- package/dist/chunk-JEQ2X3Z6.cjs +12 -0
- package/dist/chunk-JEQ2X3Z6.cjs.map +1 -0
- package/dist/chunk-L6VLNVKP.cjs +1691 -0
- package/dist/chunk-L6VLNVKP.cjs.map +1 -0
- package/dist/chunk-MFNO57XL.cjs +347 -0
- package/dist/chunk-MFNO57XL.cjs.map +1 -0
- package/dist/chunk-R75MREOS.cjs +424 -0
- package/dist/chunk-R75MREOS.cjs.map +1 -0
- package/dist/chunk-SATNCODL.js +45 -0
- package/dist/chunk-SATNCODL.js.map +1 -0
- package/dist/chunk-T57ZL7KR.cjs +1281 -0
- package/dist/chunk-T57ZL7KR.cjs.map +1 -0
- package/dist/chunk-U72GEJZT.js +1279 -0
- package/dist/chunk-U72GEJZT.js.map +1 -0
- package/dist/debugger.cjs +20 -0
- package/dist/debugger.cjs.map +1 -0
- package/dist/debugger.d.cts +171 -0
- package/dist/debugger.d.ts +171 -0
- package/dist/debugger.js +7 -0
- package/dist/debugger.js.map +1 -0
- package/dist/index.cjs +6803 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +4093 -0
- package/dist/index.d.ts +4093 -0
- package/dist/index.js +6715 -0
- package/dist/index.js.map +1 -0
- package/dist/parser.cjs +14 -0
- package/dist/parser.cjs.map +1 -0
- package/dist/parser.d.cts +172 -0
- package/dist/parser.d.ts +172 -0
- package/dist/parser.js +5 -0
- package/dist/parser.js.map +1 -0
- package/dist/runtime.cjs +14 -0
- package/dist/runtime.cjs.map +1 -0
- package/dist/runtime.d.cts +200 -0
- package/dist/runtime.d.ts +200 -0
- package/dist/runtime.js +5 -0
- package/dist/runtime.js.map +1 -0
- package/dist/type-checker.cjs +17 -0
- package/dist/type-checker.cjs.map +1 -0
- package/dist/type-checker.d.cts +105 -0
- package/dist/type-checker.d.ts +105 -0
- package/dist/type-checker.js +4 -0
- package/dist/type-checker.js.map +1 -0
- package/dist/types-4h8cbtF_.d.cts +329 -0
- package/dist/types-4h8cbtF_.d.ts +329 -0
- package/package.json +17 -13
- package/src/HoloScript2DParser.js +0 -227
- package/src/HoloScript2DParser.ts +0 -261
- package/src/HoloScriptCodeParser.js +0 -1102
- package/src/HoloScriptCodeParser.ts +0 -1188
- package/src/HoloScriptDebugger.js +0 -458
- package/src/HoloScriptParser.js +0 -338
- package/src/HoloScriptParser.ts +0 -397
- package/src/HoloScriptPlusParser.js +0 -371
- package/src/HoloScriptPlusParser.ts +0 -543
- package/src/HoloScriptRuntime.js +0 -1399
- package/src/HoloScriptRuntime.test.js +0 -351
- package/src/HoloScriptRuntime.test.ts +0 -436
- package/src/HoloScriptRuntime.ts +0 -1653
- package/src/HoloScriptTypeChecker.js +0 -356
- package/src/HoloScriptTypeChecker.ts +0 -475
- package/src/__tests__/GraphicsServices.test.js +0 -357
- package/src/__tests__/GraphicsServices.test.ts +0 -427
- package/src/__tests__/HoloScriptPlusParser.test.js +0 -317
- package/src/__tests__/HoloScriptPlusParser.test.ts +0 -392
- package/src/__tests__/integration.test.js +0 -336
- package/src/__tests__/integration.test.ts +0 -416
- package/src/__tests__/performance.bench.js +0 -218
- package/src/__tests__/performance.bench.ts +0 -262
- package/src/__tests__/type-checker.test.js +0 -60
- package/src/__tests__/type-checker.test.ts +0 -73
- package/src/index.js +0 -217
- package/src/index.ts +0 -426
- package/src/interop/Interoperability.js +0 -413
- package/src/interop/Interoperability.ts +0 -494
- package/src/logger.js +0 -42
- package/src/logger.ts +0 -57
- package/src/parser/EnhancedParser.js +0 -205
- package/src/parser/EnhancedParser.ts +0 -251
- package/src/parser/HoloScriptPlusParser.js +0 -928
- package/src/parser/HoloScriptPlusParser.ts +0 -1089
- package/src/runtime/HoloScriptPlusRuntime.js +0 -674
- package/src/runtime/HoloScriptPlusRuntime.ts +0 -861
- package/src/runtime/PerformanceTelemetry.js +0 -323
- package/src/runtime/PerformanceTelemetry.ts +0 -467
- package/src/runtime/RuntimeOptimization.js +0 -361
- package/src/runtime/RuntimeOptimization.ts +0 -416
- package/src/services/HololandGraphicsPipelineService.js +0 -506
- package/src/services/HololandGraphicsPipelineService.ts +0 -662
- package/src/services/PlatformPerformanceOptimizer.js +0 -356
- package/src/services/PlatformPerformanceOptimizer.ts +0 -503
- package/src/state/ReactiveState.js +0 -427
- package/src/state/ReactiveState.ts +0 -572
- package/src/tools/DeveloperExperience.js +0 -376
- package/src/tools/DeveloperExperience.ts +0 -438
- package/src/traits/AIDriverTrait.js +0 -322
- package/src/traits/AIDriverTrait.test.js +0 -329
- package/src/traits/AIDriverTrait.test.ts +0 -357
- package/src/traits/AIDriverTrait.ts +0 -474
- package/src/traits/LightingTrait.js +0 -313
- package/src/traits/LightingTrait.test.js +0 -410
- package/src/traits/LightingTrait.test.ts +0 -462
- package/src/traits/LightingTrait.ts +0 -505
- package/src/traits/MaterialTrait.js +0 -194
- package/src/traits/MaterialTrait.test.js +0 -286
- package/src/traits/MaterialTrait.test.ts +0 -329
- package/src/traits/MaterialTrait.ts +0 -324
- package/src/traits/RenderingTrait.js +0 -356
- package/src/traits/RenderingTrait.test.js +0 -363
- package/src/traits/RenderingTrait.test.ts +0 -427
- package/src/traits/RenderingTrait.ts +0 -555
- package/src/traits/VRTraitSystem.js +0 -740
- package/src/traits/VRTraitSystem.ts +0 -1040
- package/src/traits/VoiceInputTrait.js +0 -284
- package/src/traits/VoiceInputTrait.test.js +0 -226
- package/src/traits/VoiceInputTrait.test.ts +0 -252
- package/src/traits/VoiceInputTrait.ts +0 -401
- package/src/types/AdvancedTypeSystem.js +0 -226
- package/src/types/AdvancedTypeSystem.ts +0 -494
- package/src/types/HoloScriptPlus.d.ts +0 -853
- package/src/types.js +0 -6
- package/src/types.ts +0 -369
- package/tsconfig.json +0 -23
- package/tsup.config.d.ts +0 -2
- package/tsup.config.js +0 -18
- package/tsup.config.ts +0 -19
|
@@ -1,205 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,251 +0,0 @@
|
|
|
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
|
-
}
|