starlight-cli 1.0.39 → 1.0.41

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
@@ -1404,6 +1404,41 @@ class Evaluator {
1404
1404
  });
1405
1405
  this.global.define('keys', arg => arg && typeof arg === 'object' ? Object.keys(arg) : []);
1406
1406
  this.global.define('values', arg => arg && typeof arg === 'object' ? Object.values(arg) : []);
1407
+ this.global.define('range', (...args) => {
1408
+ let start = 0;
1409
+ let end = 0;
1410
+ let step = 1;
1411
+
1412
+ if (args.length === 1) {
1413
+ end = Number(args[0]);
1414
+ } else if (args.length === 2) {
1415
+ start = Number(args[0]);
1416
+ end = Number(args[1]);
1417
+ } else if (args.length === 3) {
1418
+ start = Number(args[0]);
1419
+ end = Number(args[1]);
1420
+ step = Number(args[2]);
1421
+ } else {
1422
+ throw new Error('range() expects 1 to 3 arguments');
1423
+ }
1424
+
1425
+ if (step === 0) {
1426
+ throw new Error('range() step cannot be 0');
1427
+ }
1428
+
1429
+ const result = [];
1430
+ if (step > 0) {
1431
+ for (let i = start; i < end; i += step) {
1432
+ result.push(i);
1433
+ }
1434
+ } else {
1435
+ for (let i = start; i > end; i += step) {
1436
+ result.push(i);
1437
+ }
1438
+ }
1439
+
1440
+ return result;
1441
+ });
1407
1442
 
1408
1443
  this.global.define('ask', prompt => {
1409
1444
  const readlineSync = __nccwpck_require__(552);
@@ -1471,6 +1506,8 @@ async evaluate(node, env = this.global) {
1471
1506
  case 'ForStatement':
1472
1507
  case 'ForInStatement':
1473
1508
  return await this.evalFor(node, env);
1509
+ case 'DoTrackStatement':
1510
+ return await this.evalDoTrack(node, env);
1474
1511
 
1475
1512
  case 'BreakStatement': throw new BreakSignal();
1476
1513
  case 'ContinueStatement': throw new ContinueSignal();
@@ -1542,6 +1579,18 @@ async evalProgram(node, env) {
1542
1579
  return result;
1543
1580
  }
1544
1581
 
1582
+ async evalDoTrack(node, env) {
1583
+ try {
1584
+ return await this.evaluate(node.body, env);
1585
+ } catch (err) {
1586
+ if (!node.handler) throw err;
1587
+
1588
+ const trackEnv = new Environment(env);
1589
+ trackEnv.define('error', err);
1590
+
1591
+ return await this.evaluate(node.handler, trackEnv);
1592
+ }
1593
+ }
1545
1594
 
1546
1595
  async evalImport(node, env) {
1547
1596
  const spec = node.path;
@@ -2007,7 +2056,7 @@ class Lexer {
2007
2056
  'break', 'continue', 'func', 'return',
2008
2057
  'true', 'false', 'null',
2009
2058
  'ask', 'define', 'import', 'from', 'as',
2010
- 'async', 'await', 'new', 'in'
2059
+ 'async', 'await', 'new', 'in', 'do', 'track'
2011
2060
  ];
2012
2061
 
2013
2062
 
@@ -2161,6 +2210,7 @@ class Parser {
2161
2210
  case 'IF': return this.ifStatement();
2162
2211
  case 'WHILE': return this.whileStatement();
2163
2212
  case 'FOR': return this.forStatement();
2213
+ case 'DO': return this.doTrackStatement();
2164
2214
  case 'BREAK': return this.breakStatement();
2165
2215
  case 'CONTINUE': return this.continueStatement();
2166
2216
  case 'FUNC': return this.funcDeclaration();
@@ -2195,6 +2245,23 @@ sldeployStatement() {
2195
2245
  if (this.current.type === 'SEMICOLON') this.eat('SEMICOLON');
2196
2246
  return { type: 'SldeployStatement', expr };
2197
2247
  }
2248
+ doTrackStatement() {
2249
+ this.eat('DO');
2250
+
2251
+ const body = this.block();
2252
+
2253
+ let handler = null;
2254
+ if (this.current.type === 'TRACK') {
2255
+ this.eat('TRACK');
2256
+ handler = this.block();
2257
+ }
2258
+
2259
+ return {
2260
+ type: 'DoTrackStatement',
2261
+ body,
2262
+ handler
2263
+ };
2264
+ }
2198
2265
 
2199
2266
  defineStatement() {
2200
2267
  this.eat('DEFINE');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "starlight-cli",
3
- "version": "1.0.39",
3
+ "version": "1.0.41",
4
4
  "description": "Starlight Programming Language CLI",
5
5
  "bin": {
6
6
  "starlight": "index.js"
package/src/evaluator.js CHANGED
@@ -61,6 +61,41 @@ class Evaluator {
61
61
  });
62
62
  this.global.define('keys', arg => arg && typeof arg === 'object' ? Object.keys(arg) : []);
63
63
  this.global.define('values', arg => arg && typeof arg === 'object' ? Object.values(arg) : []);
64
+ this.global.define('range', (...args) => {
65
+ let start = 0;
66
+ let end = 0;
67
+ let step = 1;
68
+
69
+ if (args.length === 1) {
70
+ end = Number(args[0]);
71
+ } else if (args.length === 2) {
72
+ start = Number(args[0]);
73
+ end = Number(args[1]);
74
+ } else if (args.length === 3) {
75
+ start = Number(args[0]);
76
+ end = Number(args[1]);
77
+ step = Number(args[2]);
78
+ } else {
79
+ throw new Error('range() expects 1 to 3 arguments');
80
+ }
81
+
82
+ if (step === 0) {
83
+ throw new Error('range() step cannot be 0');
84
+ }
85
+
86
+ const result = [];
87
+ if (step > 0) {
88
+ for (let i = start; i < end; i += step) {
89
+ result.push(i);
90
+ }
91
+ } else {
92
+ for (let i = start; i > end; i += step) {
93
+ result.push(i);
94
+ }
95
+ }
96
+
97
+ return result;
98
+ });
64
99
 
65
100
  this.global.define('ask', prompt => {
66
101
  const readlineSync = require('readline-sync');
@@ -128,6 +163,8 @@ async evaluate(node, env = this.global) {
128
163
  case 'ForStatement':
129
164
  case 'ForInStatement':
130
165
  return await this.evalFor(node, env);
166
+ case 'DoTrackStatement':
167
+ return await this.evalDoTrack(node, env);
131
168
 
132
169
  case 'BreakStatement': throw new BreakSignal();
133
170
  case 'ContinueStatement': throw new ContinueSignal();
@@ -199,6 +236,18 @@ async evalProgram(node, env) {
199
236
  return result;
200
237
  }
201
238
 
239
+ async evalDoTrack(node, env) {
240
+ try {
241
+ return await this.evaluate(node.body, env);
242
+ } catch (err) {
243
+ if (!node.handler) throw err;
244
+
245
+ const trackEnv = new Environment(env);
246
+ trackEnv.define('error', err);
247
+
248
+ return await this.evaluate(node.handler, trackEnv);
249
+ }
250
+ }
202
251
 
203
252
  async evalImport(node, env) {
204
253
  const spec = node.path;
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', 'new', 'in'
86
+ 'async', 'await', 'new', 'in', 'do', 'track'
87
87
  ];
88
88
 
89
89
 
package/src/parser.js CHANGED
@@ -43,6 +43,7 @@ class Parser {
43
43
  case 'IF': return this.ifStatement();
44
44
  case 'WHILE': return this.whileStatement();
45
45
  case 'FOR': return this.forStatement();
46
+ case 'DO': return this.doTrackStatement();
46
47
  case 'BREAK': return this.breakStatement();
47
48
  case 'CONTINUE': return this.continueStatement();
48
49
  case 'FUNC': return this.funcDeclaration();
@@ -77,6 +78,23 @@ sldeployStatement() {
77
78
  if (this.current.type === 'SEMICOLON') this.eat('SEMICOLON');
78
79
  return { type: 'SldeployStatement', expr };
79
80
  }
81
+ doTrackStatement() {
82
+ this.eat('DO');
83
+
84
+ const body = this.block();
85
+
86
+ let handler = null;
87
+ if (this.current.type === 'TRACK') {
88
+ this.eat('TRACK');
89
+ handler = this.block();
90
+ }
91
+
92
+ return {
93
+ type: 'DoTrackStatement',
94
+ body,
95
+ handler
96
+ };
97
+ }
80
98
 
81
99
  defineStatement() {
82
100
  this.eat('DEFINE');