starlight-cli 1.0.39 → 1.0.40

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
@@ -1471,6 +1471,8 @@ async evaluate(node, env = this.global) {
1471
1471
  case 'ForStatement':
1472
1472
  case 'ForInStatement':
1473
1473
  return await this.evalFor(node, env);
1474
+ case 'DoTrackStatement':
1475
+ return await this.evalDoTrack(node, env);
1474
1476
 
1475
1477
  case 'BreakStatement': throw new BreakSignal();
1476
1478
  case 'ContinueStatement': throw new ContinueSignal();
@@ -1542,6 +1544,18 @@ async evalProgram(node, env) {
1542
1544
  return result;
1543
1545
  }
1544
1546
 
1547
+ async evalDoTrack(node, env) {
1548
+ try {
1549
+ return await this.evaluate(node.body, env);
1550
+ } catch (err) {
1551
+ if (!node.handler) throw err;
1552
+
1553
+ const trackEnv = new Environment(env);
1554
+ trackEnv.define('error', err);
1555
+
1556
+ return await this.evaluate(node.handler, trackEnv);
1557
+ }
1558
+ }
1545
1559
 
1546
1560
  async evalImport(node, env) {
1547
1561
  const spec = node.path;
@@ -2007,7 +2021,7 @@ class Lexer {
2007
2021
  'break', 'continue', 'func', 'return',
2008
2022
  'true', 'false', 'null',
2009
2023
  'ask', 'define', 'import', 'from', 'as',
2010
- 'async', 'await', 'new', 'in'
2024
+ 'async', 'await', 'new', 'in', 'do', 'track'
2011
2025
  ];
2012
2026
 
2013
2027
 
@@ -2161,6 +2175,7 @@ class Parser {
2161
2175
  case 'IF': return this.ifStatement();
2162
2176
  case 'WHILE': return this.whileStatement();
2163
2177
  case 'FOR': return this.forStatement();
2178
+ case 'DO': return this.doTrackStatement();
2164
2179
  case 'BREAK': return this.breakStatement();
2165
2180
  case 'CONTINUE': return this.continueStatement();
2166
2181
  case 'FUNC': return this.funcDeclaration();
@@ -2195,6 +2210,23 @@ sldeployStatement() {
2195
2210
  if (this.current.type === 'SEMICOLON') this.eat('SEMICOLON');
2196
2211
  return { type: 'SldeployStatement', expr };
2197
2212
  }
2213
+ doTrackStatement() {
2214
+ this.eat('DO');
2215
+
2216
+ const body = this.block();
2217
+
2218
+ let handler = null;
2219
+ if (this.current.type === 'TRACK') {
2220
+ this.eat('TRACK');
2221
+ handler = this.block();
2222
+ }
2223
+
2224
+ return {
2225
+ type: 'DoTrackStatement',
2226
+ body,
2227
+ handler
2228
+ };
2229
+ }
2198
2230
 
2199
2231
  defineStatement() {
2200
2232
  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.40",
4
4
  "description": "Starlight Programming Language CLI",
5
5
  "bin": {
6
6
  "starlight": "index.js"
package/src/evaluator.js CHANGED
@@ -128,6 +128,8 @@ async evaluate(node, env = this.global) {
128
128
  case 'ForStatement':
129
129
  case 'ForInStatement':
130
130
  return await this.evalFor(node, env);
131
+ case 'DoTrackStatement':
132
+ return await this.evalDoTrack(node, env);
131
133
 
132
134
  case 'BreakStatement': throw new BreakSignal();
133
135
  case 'ContinueStatement': throw new ContinueSignal();
@@ -199,6 +201,18 @@ async evalProgram(node, env) {
199
201
  return result;
200
202
  }
201
203
 
204
+ async evalDoTrack(node, env) {
205
+ try {
206
+ return await this.evaluate(node.body, env);
207
+ } catch (err) {
208
+ if (!node.handler) throw err;
209
+
210
+ const trackEnv = new Environment(env);
211
+ trackEnv.define('error', err);
212
+
213
+ return await this.evaluate(node.handler, trackEnv);
214
+ }
215
+ }
202
216
 
203
217
  async evalImport(node, env) {
204
218
  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');