starlight-cli 1.0.30 → 1.0.31

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 CHANGED
@@ -1496,6 +1496,15 @@ async evaluate(node, env = this.global) {
1496
1496
  const val = await this.evaluate(node.argument, env);
1497
1497
  return val;
1498
1498
  }
1499
+ case 'NewExpression': {
1500
+ const fn = await this.evaluate(node.callee, env); // the class or constructor
1501
+ if (typeof fn !== 'function') {
1502
+ throw new Error('NewExpression callee is not a function');
1503
+ }
1504
+ const args = [];
1505
+ for (const a of node.arguments) args.push(await this.evaluate(a, env));
1506
+ return new fn(...args);
1507
+ }
1499
1508
  default:
1500
1509
  throw new Error(`Unknown node type in evaluator: ${node.type}`);
1501
1510
  }
@@ -1919,7 +1928,7 @@ class Lexer {
1919
1928
  'break', 'continue', 'func', 'return',
1920
1929
  'true', 'false', 'null',
1921
1930
  'ask', 'define', 'import', 'from', 'as',
1922
- 'async', 'await'
1931
+ 'async', 'await', 'new'
1923
1932
  ];
1924
1933
 
1925
1934
 
@@ -2444,6 +2453,22 @@ if (t.type === 'AWAIT') {
2444
2453
  const argument = this.expression();
2445
2454
  return { type: 'AwaitExpression', argument };
2446
2455
  }
2456
+ if (t.type === 'NEW') {
2457
+ this.eat('NEW');
2458
+ const callee = this.primary(); // the class or function being called
2459
+ this.eat('LPAREN');
2460
+ const args = [];
2461
+ if (this.current.type !== 'RPAREN') {
2462
+ args.push(this.expression());
2463
+ while (this.current.type === 'COMMA') {
2464
+ this.eat('COMMA');
2465
+ args.push(this.expression());
2466
+ }
2467
+ }
2468
+ this.eat('RPAREN');
2469
+ return { type: 'NewExpression', callee, arguments: args };
2470
+ }
2471
+
2447
2472
  if (t.type === 'ASK') {
2448
2473
  this.eat('ASK');
2449
2474
  this.eat('LPAREN');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "starlight-cli",
3
- "version": "1.0.30",
3
+ "version": "1.0.31",
4
4
  "description": "Starlight Programming Language CLI",
5
5
  "bin": {
6
6
  "starlight": "index.js"
package/src/evaluator.js CHANGED
@@ -153,6 +153,15 @@ async evaluate(node, env = this.global) {
153
153
  const val = await this.evaluate(node.argument, env);
154
154
  return val;
155
155
  }
156
+ case 'NewExpression': {
157
+ const fn = await this.evaluate(node.callee, env); // the class or constructor
158
+ if (typeof fn !== 'function') {
159
+ throw new Error('NewExpression callee is not a function');
160
+ }
161
+ const args = [];
162
+ for (const a of node.arguments) args.push(await this.evaluate(a, env));
163
+ return new fn(...args);
164
+ }
156
165
  default:
157
166
  throw new Error(`Unknown node type in evaluator: ${node.type}`);
158
167
  }
package/src/lexer.js CHANGED
@@ -83,7 +83,7 @@ class Lexer {
83
83
  'break', 'continue', 'func', 'return',
84
84
  'true', 'false', 'null',
85
85
  'ask', 'define', 'import', 'from', 'as',
86
- 'async', 'await'
86
+ 'async', 'await', 'new'
87
87
  ];
88
88
 
89
89
 
package/src/parser.js CHANGED
@@ -414,6 +414,22 @@ if (t.type === 'AWAIT') {
414
414
  const argument = this.expression();
415
415
  return { type: 'AwaitExpression', argument };
416
416
  }
417
+ if (t.type === 'NEW') {
418
+ this.eat('NEW');
419
+ const callee = this.primary(); // the class or function being called
420
+ this.eat('LPAREN');
421
+ const args = [];
422
+ if (this.current.type !== 'RPAREN') {
423
+ args.push(this.expression());
424
+ while (this.current.type === 'COMMA') {
425
+ this.eat('COMMA');
426
+ args.push(this.expression());
427
+ }
428
+ }
429
+ this.eat('RPAREN');
430
+ return { type: 'NewExpression', callee, arguments: args };
431
+ }
432
+
417
433
  if (t.type === 'ASK') {
418
434
  this.eat('ASK');
419
435
  this.eat('LPAREN');