starlight-cli 1.0.37 → 1.0.38

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
@@ -1467,9 +1467,6 @@ async evaluate(node, env = this.global) {
1467
1467
  case 'Literal': return node.value;
1468
1468
  case 'Identifier': return env.get(node.name);
1469
1469
  case 'IfStatement': return await this.evalIf(node, env);
1470
- case 'ForInStatement':
1471
- return await this.evalForIn(node, env);
1472
-
1473
1470
  case 'WhileStatement': return await this.evalWhile(node, env);
1474
1471
  case 'ForStatement': return await this.evalFor(node, env);
1475
1472
  case 'BreakStatement': throw new BreakSignal();
@@ -1539,30 +1536,7 @@ async evalProgram(node, env) {
1539
1536
  }
1540
1537
  return result;
1541
1538
  }
1542
- async evalForIn(node, env) {
1543
- const iterable = await this.evaluate(node.iterable, env);
1544
-
1545
- if (!Array.isArray(iterable)) {
1546
- throw new Error("for-in expects an array");
1547
- }
1548
-
1549
- for (const value of iterable) {
1550
- const local = new Environment(env);
1551
-
1552
- // loop variable
1553
- local.define(node.id.name, value);
1554
-
1555
- try {
1556
- await this.evaluate(node.body, local);
1557
- } catch (e) {
1558
- if (e instanceof BreakSignal) break;
1559
- if (e instanceof ContinueSignal) continue;
1560
- throw e;
1561
- }
1562
- }
1563
1539
 
1564
- return null;
1565
- }
1566
1540
 
1567
1541
  async evalImport(node, env) {
1568
1542
  const spec = node.path;
@@ -1772,9 +1746,11 @@ async evalWhile(node, env) {
1772
1746
  }
1773
1747
  return null;
1774
1748
  }
1775
-
1776
1749
  async evalFor(node, env) {
1777
- // --- Python-style for x in iterable ---
1750
+
1751
+ // -------------------------------
1752
+ // Python-style: for x in iterable
1753
+ // -------------------------------
1778
1754
  if (node.type === 'ForInStatement') {
1779
1755
  const iterable = await this.evaluate(node.iterable, env);
1780
1756
 
@@ -1782,11 +1758,13 @@ async evalFor(node, env) {
1782
1758
  throw new Error('Cannot iterate over non-iterable');
1783
1759
  }
1784
1760
 
1785
- // Handle arrays
1761
+ const loopVar = node.variable; // STRING from parser
1762
+
1763
+ // Arrays
1786
1764
  if (Array.isArray(iterable)) {
1787
- for (let i = 0; i < iterable.length; i++) {
1765
+ for (const value of iterable) {
1788
1766
  const loopEnv = new Environment(env);
1789
- loopEnv.define(node.variable, iterable[i]);
1767
+ loopEnv.define(loopVar, value);
1790
1768
 
1791
1769
  try {
1792
1770
  await this.evaluate(node.body, loopEnv);
@@ -1796,11 +1774,12 @@ async evalFor(node, env) {
1796
1774
  throw e;
1797
1775
  }
1798
1776
  }
1799
- } else {
1800
- // Handle objects: iterate over keys
1777
+ }
1778
+ // Objects (keys)
1779
+ else {
1801
1780
  for (const key of Object.keys(iterable)) {
1802
1781
  const loopEnv = new Environment(env);
1803
- loopEnv.define(node.variable, key);
1782
+ loopEnv.define(loopVar, key);
1804
1783
 
1805
1784
  try {
1806
1785
  await this.evaluate(node.body, loopEnv);
@@ -1815,7 +1794,11 @@ async evalFor(node, env) {
1815
1794
  return null;
1816
1795
  }
1817
1796
 
1797
+ // -------------------------------
1798
+ // C-style for loop
1799
+ // -------------------------------
1818
1800
  const local = new Environment(env);
1801
+
1819
1802
  if (node.init) await this.evaluate(node.init, local);
1820
1803
 
1821
1804
  while (!node.test || await this.evaluate(node.test, local)) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "starlight-cli",
3
- "version": "1.0.37",
3
+ "version": "1.0.38",
4
4
  "description": "Starlight Programming Language CLI",
5
5
  "bin": {
6
6
  "starlight": "index.js"
package/src/evaluator.js CHANGED
@@ -124,9 +124,6 @@ async evaluate(node, env = this.global) {
124
124
  case 'Literal': return node.value;
125
125
  case 'Identifier': return env.get(node.name);
126
126
  case 'IfStatement': return await this.evalIf(node, env);
127
- case 'ForInStatement':
128
- return await this.evalForIn(node, env);
129
-
130
127
  case 'WhileStatement': return await this.evalWhile(node, env);
131
128
  case 'ForStatement': return await this.evalFor(node, env);
132
129
  case 'BreakStatement': throw new BreakSignal();
@@ -196,30 +193,7 @@ async evalProgram(node, env) {
196
193
  }
197
194
  return result;
198
195
  }
199
- async evalForIn(node, env) {
200
- const iterable = await this.evaluate(node.iterable, env);
201
-
202
- if (!Array.isArray(iterable)) {
203
- throw new Error("for-in expects an array");
204
- }
205
196
 
206
- for (const value of iterable) {
207
- const local = new Environment(env);
208
-
209
- // loop variable
210
- local.define(node.id.name, value);
211
-
212
- try {
213
- await this.evaluate(node.body, local);
214
- } catch (e) {
215
- if (e instanceof BreakSignal) break;
216
- if (e instanceof ContinueSignal) continue;
217
- throw e;
218
- }
219
- }
220
-
221
- return null;
222
- }
223
197
 
224
198
  async evalImport(node, env) {
225
199
  const spec = node.path;
@@ -429,9 +403,11 @@ async evalWhile(node, env) {
429
403
  }
430
404
  return null;
431
405
  }
432
-
433
406
  async evalFor(node, env) {
434
- // --- Python-style for x in iterable ---
407
+
408
+ // -------------------------------
409
+ // Python-style: for x in iterable
410
+ // -------------------------------
435
411
  if (node.type === 'ForInStatement') {
436
412
  const iterable = await this.evaluate(node.iterable, env);
437
413
 
@@ -439,11 +415,13 @@ async evalFor(node, env) {
439
415
  throw new Error('Cannot iterate over non-iterable');
440
416
  }
441
417
 
442
- // Handle arrays
418
+ const loopVar = node.variable; // STRING from parser
419
+
420
+ // Arrays
443
421
  if (Array.isArray(iterable)) {
444
- for (let i = 0; i < iterable.length; i++) {
422
+ for (const value of iterable) {
445
423
  const loopEnv = new Environment(env);
446
- loopEnv.define(node.variable, iterable[i]);
424
+ loopEnv.define(loopVar, value);
447
425
 
448
426
  try {
449
427
  await this.evaluate(node.body, loopEnv);
@@ -453,11 +431,12 @@ async evalFor(node, env) {
453
431
  throw e;
454
432
  }
455
433
  }
456
- } else {
457
- // Handle objects: iterate over keys
434
+ }
435
+ // Objects (keys)
436
+ else {
458
437
  for (const key of Object.keys(iterable)) {
459
438
  const loopEnv = new Environment(env);
460
- loopEnv.define(node.variable, key);
439
+ loopEnv.define(loopVar, key);
461
440
 
462
441
  try {
463
442
  await this.evaluate(node.body, loopEnv);
@@ -472,7 +451,11 @@ async evalFor(node, env) {
472
451
  return null;
473
452
  }
474
453
 
454
+ // -------------------------------
455
+ // C-style for loop
456
+ // -------------------------------
475
457
  const local = new Environment(env);
458
+
476
459
  if (node.init) await this.evaluate(node.init, local);
477
460
 
478
461
  while (!node.test || await this.evaluate(node.test, local)) {