starlight-cli 1.0.23 → 1.0.25
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/index.js +389 -357
- package/package.json +1 -1
- package/src/evaluator.js +362 -390
- package/src/lexer.js +13 -1
- package/src/parser.js +47 -8
- package/src/starlight.js +1 -1
package/src/lexer.js
CHANGED
|
@@ -139,7 +139,19 @@ class Lexer {
|
|
|
139
139
|
const startCol = this.column;
|
|
140
140
|
|
|
141
141
|
if (char === '=' && next === '=') { tokens.push({ type: 'EQEQ', line: startLine, column: startCol }); this.advance(); this.advance(); continue; }
|
|
142
|
-
|
|
142
|
+
|
|
143
|
+
if (char === '=' && next === '>') {
|
|
144
|
+
tokens.push({ type: 'ARROW', line: startLine, column: startCol });
|
|
145
|
+
this.advance(); this.advance();
|
|
146
|
+
continue;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
if (char === '-' && next === '>') {
|
|
150
|
+
tokens.push({ type: 'ARROW', line: startLine, column: startCol });
|
|
151
|
+
this.advance(); this.advance();
|
|
152
|
+
continue;
|
|
153
|
+
}
|
|
154
|
+
|
|
143
155
|
if (char === '!' && next === '=') { tokens.push({ type: 'NOTEQ', line: startLine, column: startCol }); this.advance(); this.advance(); continue; }
|
|
144
156
|
if (char === '<' && next === '=') { tokens.push({ type: 'LTE', line: startLine, column: startCol }); this.advance(); this.advance(); continue; }
|
|
145
157
|
if (char === '>' && next === '=') { tokens.push({ type: 'GTE', line: startLine, column: startCol }); this.advance(); this.advance(); continue; }
|
package/src/parser.js
CHANGED
|
@@ -368,6 +368,15 @@ class Parser {
|
|
|
368
368
|
}
|
|
369
369
|
return node;
|
|
370
370
|
}
|
|
371
|
+
arrowFunction(params) {
|
|
372
|
+
this.eat('ARROW');
|
|
373
|
+
const body = this.expression();
|
|
374
|
+
return {
|
|
375
|
+
type: 'ArrowFunctionExpression',
|
|
376
|
+
params,
|
|
377
|
+
body
|
|
378
|
+
};
|
|
379
|
+
}
|
|
371
380
|
|
|
372
381
|
primary() {
|
|
373
382
|
const t = this.current;
|
|
@@ -394,17 +403,47 @@ class Parser {
|
|
|
394
403
|
}
|
|
395
404
|
|
|
396
405
|
if (t.type === 'IDENTIFIER') {
|
|
397
|
-
|
|
406
|
+
const name = t.value;
|
|
407
|
+
this.eat('IDENTIFIER');
|
|
408
|
+
|
|
409
|
+
if (this.current.type === 'ARROW') {
|
|
410
|
+
return this.arrowFunction([name]);
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
return { type: 'Identifier', name };
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
|
|
417
|
+
if (t.type === 'LPAREN') {
|
|
418
|
+
this.eat('LPAREN');
|
|
419
|
+
|
|
420
|
+
const params = [];
|
|
421
|
+
|
|
422
|
+
if (this.current.type !== 'RPAREN') {
|
|
423
|
+
params.push(this.current.value);
|
|
424
|
+
this.eat('IDENTIFIER');
|
|
425
|
+
while (this.current.type === 'COMMA') {
|
|
426
|
+
this.eat('COMMA');
|
|
427
|
+
params.push(this.current.value);
|
|
398
428
|
this.eat('IDENTIFIER');
|
|
399
|
-
return { type: 'Identifier', name };
|
|
400
429
|
}
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
this.eat('RPAREN');
|
|
433
|
+
|
|
434
|
+
if (this.current.type === 'ARROW') {
|
|
435
|
+
return this.arrowFunction(params);
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
if (params.length === 1) {
|
|
439
|
+
return { type: 'Identifier', name: params[0] };
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
throw new Error(
|
|
443
|
+
`Invalid grouped expression at line ${this.current.line}, column ${this.current.column}`
|
|
444
|
+
);
|
|
445
|
+
}
|
|
401
446
|
|
|
402
|
-
if (t.type === 'LPAREN') {
|
|
403
|
-
this.eat('LPAREN');
|
|
404
|
-
const expr = this.expression();
|
|
405
|
-
this.eat('RPAREN');
|
|
406
|
-
return expr;
|
|
407
|
-
}
|
|
408
447
|
|
|
409
448
|
if (t.type === 'LBRACKET') {
|
|
410
449
|
this.eat('LBRACKET');
|