starlight-cli 1.0.47 → 1.0.49
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 +421 -169
- package/package.json +1 -1
- package/src/evaluator.js +156 -70
- package/src/parser.js +248 -85
- package/src/starlight.js +17 -14
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.
|
|
12
|
+
const VERSION = '1.0.49';
|
|
13
13
|
|
|
14
14
|
const COLOR = {
|
|
15
15
|
reset: '\x1b[0m',
|
|
@@ -20,7 +20,8 @@ const COLOR = {
|
|
|
20
20
|
cyan: '\x1b[36m',
|
|
21
21
|
gray: '\x1b[90m',
|
|
22
22
|
green: '\x1b[32m',
|
|
23
|
-
magenta: '\x1b[35m'
|
|
23
|
+
magenta: '\x1b[35m',
|
|
24
|
+
white: '\x1b[37m'
|
|
24
25
|
};
|
|
25
26
|
|
|
26
27
|
function waitAndExit(code = 0) {
|
|
@@ -31,7 +32,7 @@ function waitAndExit(code = 0) {
|
|
|
31
32
|
}
|
|
32
33
|
|
|
33
34
|
function fatal(msg) {
|
|
34
|
-
console.error(COLOR.
|
|
35
|
+
console.error(COLOR.white + msg + COLOR.reset);
|
|
35
36
|
waitAndExit(1);
|
|
36
37
|
}
|
|
37
38
|
|
|
@@ -172,33 +173,35 @@ function savePrompt(lines) {
|
|
|
172
173
|
waitAndExit(0);
|
|
173
174
|
}
|
|
174
175
|
|
|
175
|
-
function runFile(filePath, isTemp = false, callback) {
|
|
176
|
+
async function runFile(filePath, isTemp = false, callback) {
|
|
176
177
|
const code = fs.readFileSync(filePath, 'utf8');
|
|
177
178
|
|
|
179
|
+
const lexer = new Lexer(code);
|
|
180
|
+
const tokens = lexer.getTokens();
|
|
181
|
+
const parser = new Parser(tokens, code);
|
|
182
|
+
const ast = parser.parse();
|
|
183
|
+
const evaluator = new Evaluator(code);
|
|
184
|
+
|
|
178
185
|
try {
|
|
179
|
-
|
|
180
|
-
const tokens = lexer.getTokens();
|
|
181
|
-
const parser = new Parser(tokens);
|
|
182
|
-
const ast = parser.parse();
|
|
183
|
-
new Evaluator().evaluate(ast);
|
|
186
|
+
await evaluator.evaluate(ast);
|
|
184
187
|
} catch (e) {
|
|
185
|
-
if (e.name === 'RuntimeError') {
|
|
186
|
-
console.error(COLOR.
|
|
187
|
-
} else if (e instanceof SyntaxError) {
|
|
188
|
-
console.error(COLOR.red + `SyntaxError: ${e.message}` + COLOR.reset);
|
|
188
|
+
if (e.name === 'RuntimeError' || e.name === 'SyntaxError') {
|
|
189
|
+
console.error(COLOR.white + e.message + COLOR.reset);
|
|
189
190
|
} else {
|
|
190
|
-
console.error(COLOR.
|
|
191
|
+
console.error(COLOR.white + `Unexpected Error: ${e.message || e}` + COLOR.reset);
|
|
191
192
|
}
|
|
192
193
|
return waitAndExit(1);
|
|
193
194
|
}
|
|
194
195
|
|
|
195
196
|
if (callback) callback();
|
|
197
|
+
|
|
196
198
|
if (isTemp) {
|
|
197
199
|
try { fs.unlinkSync(filePath); } catch {}
|
|
198
200
|
}
|
|
199
201
|
}
|
|
200
202
|
|
|
201
203
|
|
|
204
|
+
|
|
202
205
|
if (!args[0].startsWith('--')) {
|
|
203
206
|
runFile(path.resolve(args[0]));
|
|
204
207
|
}
|