starlight-cli 1.0.46 → 1.0.48
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 +530 -173
- package/package.json +1 -1
- package/src/evaluator.js +185 -62
- package/src/lexer.js +33 -8
- package/src/parser.js +289 -92
- package/src/starlight.js +23 -11
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.48';
|
|
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,24 +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 parser = new Parser(lexer.getTokens());
|
|
181
|
-
const ast = parser.parse();
|
|
182
|
-
new Evaluator().evaluate(ast);
|
|
186
|
+
await evaluator.evaluate(ast);
|
|
183
187
|
} catch (e) {
|
|
184
|
-
|
|
188
|
+
if (e.name === 'RuntimeError' || e.name === 'SyntaxError') {
|
|
189
|
+
console.error(COLOR.white + e.message + COLOR.reset);
|
|
190
|
+
} else {
|
|
191
|
+
console.error(COLOR.white + `Unexpected Error: ${e.message || e}` + COLOR.reset);
|
|
192
|
+
}
|
|
185
193
|
return waitAndExit(1);
|
|
186
194
|
}
|
|
187
195
|
|
|
188
|
-
|
|
189
196
|
if (callback) callback();
|
|
190
|
-
|
|
197
|
+
|
|
198
|
+
if (isTemp) {
|
|
199
|
+
try { fs.unlinkSync(filePath); } catch {}
|
|
200
|
+
}
|
|
191
201
|
}
|
|
192
202
|
|
|
203
|
+
|
|
204
|
+
|
|
193
205
|
if (!args[0].startsWith('--')) {
|
|
194
206
|
runFile(path.resolve(args[0]));
|
|
195
207
|
}
|