starlight-cli 1.0.50 → 1.0.51

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
@@ -2386,7 +2386,7 @@ class ParseError extends Error {
2386
2386
  const line = token?.line ?? '?';
2387
2387
  const column = token?.column ?? '?';
2388
2388
 
2389
- let output = `SyntaxError: ${message}\n`;
2389
+ let output = `${message}\n`;
2390
2390
 
2391
2391
  if (source && token?.line != null) {
2392
2392
  const lines = source.split('\n');
@@ -3319,7 +3319,7 @@ const Lexer = __nccwpck_require__(211);
3319
3319
  const Parser = __nccwpck_require__(222);
3320
3320
  const Evaluator = __nccwpck_require__(112);
3321
3321
 
3322
- const VERSION = '1.0.50';
3322
+ const VERSION = '1.0.51';
3323
3323
 
3324
3324
  const COLOR = {
3325
3325
  reset: '\x1b[0m',
@@ -3484,12 +3484,26 @@ function savePrompt(lines) {
3484
3484
  }
3485
3485
 
3486
3486
  async function runFile(filePath, isTemp = false, callback) {
3487
- const code = fs.readFileSync(filePath, 'utf8');
3487
+ let code;
3488
+ try {
3489
+ code = fs.readFileSync(filePath, 'utf8');
3490
+ } catch (e) {
3491
+ console.error(COLOR.white + `Failed to read file: ${e.message}` + COLOR.reset);
3492
+ return waitAndExit(1);
3493
+ }
3494
+
3495
+ let tokens, ast;
3496
+ try {
3497
+ const lexer = new Lexer(code);
3498
+ tokens = lexer.getTokens();
3499
+
3500
+ const parser = new Parser(tokens, code);
3501
+ ast = parser.parse(); // <-- parser errors caught here
3502
+ } catch (e) {
3503
+ console.error(COLOR.white + ` ${e.message}` + COLOR.reset);
3504
+ return waitAndExit(1); // stop execution without Node.js stack trace
3505
+ }
3488
3506
 
3489
- const lexer = new Lexer(code);
3490
- const tokens = lexer.getTokens();
3491
- const parser = new Parser(tokens, code);
3492
- const ast = parser.parse();
3493
3507
  const evaluator = new Evaluator(code);
3494
3508
 
3495
3509
  try {
@@ -3511,7 +3525,6 @@ async function runFile(filePath, isTemp = false, callback) {
3511
3525
  }
3512
3526
 
3513
3527
 
3514
-
3515
3528
  if (!args[0].startsWith('--')) {
3516
3529
  runFile(path.resolve(args[0]));
3517
3530
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "starlight-cli",
3
- "version": "1.0.50",
3
+ "version": "1.0.51",
4
4
  "description": "Starlight Programming Language CLI",
5
5
  "bin": {
6
6
  "starlight": "index.js"
package/src/parser.js CHANGED
@@ -3,7 +3,7 @@ class ParseError extends Error {
3
3
  const line = token?.line ?? '?';
4
4
  const column = token?.column ?? '?';
5
5
 
6
- let output = `SyntaxError: ${message}\n`;
6
+ let output = `${message}\n`;
7
7
 
8
8
  if (source && token?.line != null) {
9
9
  const lines = source.split('\n');
package/src/starlight.js CHANGED
@@ -9,7 +9,7 @@ const Lexer = require('./lexer');
9
9
  const Parser = require('./parser');
10
10
  const Evaluator = require('./evaluator');
11
11
 
12
- const VERSION = '1.0.50';
12
+ const VERSION = '1.0.51';
13
13
 
14
14
  const COLOR = {
15
15
  reset: '\x1b[0m',
@@ -174,12 +174,26 @@ function savePrompt(lines) {
174
174
  }
175
175
 
176
176
  async function runFile(filePath, isTemp = false, callback) {
177
- const code = fs.readFileSync(filePath, 'utf8');
177
+ let code;
178
+ try {
179
+ code = fs.readFileSync(filePath, 'utf8');
180
+ } catch (e) {
181
+ console.error(COLOR.white + `Failed to read file: ${e.message}` + COLOR.reset);
182
+ return waitAndExit(1);
183
+ }
184
+
185
+ let tokens, ast;
186
+ try {
187
+ const lexer = new Lexer(code);
188
+ tokens = lexer.getTokens();
189
+
190
+ const parser = new Parser(tokens, code);
191
+ ast = parser.parse(); // <-- parser errors caught here
192
+ } catch (e) {
193
+ console.error(COLOR.white + ` ${e.message}` + COLOR.reset);
194
+ return waitAndExit(1); // stop execution without Node.js stack trace
195
+ }
178
196
 
179
- const lexer = new Lexer(code);
180
- const tokens = lexer.getTokens();
181
- const parser = new Parser(tokens, code);
182
- const ast = parser.parse();
183
197
  const evaluator = new Evaluator(code);
184
198
 
185
199
  try {
@@ -201,7 +215,6 @@ async function runFile(filePath, isTemp = false, callback) {
201
215
  }
202
216
 
203
217
 
204
-
205
218
  if (!args[0].startsWith('--')) {
206
219
  runFile(path.resolve(args[0]));
207
220
  }