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