starlight-cli 1.0.25 → 1.0.27
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 +456 -341
- package/package.json +1 -1
- package/src/evaluator.js +434 -340
- package/src/lexer.js +7 -4
- package/src/parser.js +28 -1
- package/src/starlight.js +1 -1
package/src/lexer.js
CHANGED
|
@@ -79,10 +79,13 @@ class Lexer {
|
|
|
79
79
|
}
|
|
80
80
|
|
|
81
81
|
const keywords = [
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
82
|
+
'let', 'sldeploy', 'if', 'else', 'while', 'for',
|
|
83
|
+
'break', 'continue', 'func', 'return',
|
|
84
|
+
'true', 'false', 'null',
|
|
85
|
+
'ask', 'define', 'import', 'from', 'as',
|
|
86
|
+
'async', 'await'
|
|
87
|
+
];
|
|
88
|
+
|
|
86
89
|
|
|
87
90
|
if (keywords.includes(result)) {
|
|
88
91
|
return { type: result.toUpperCase(), value: result, line: startLine, column: startCol };
|
package/src/parser.js
CHANGED
|
@@ -31,6 +31,11 @@ class Parser {
|
|
|
31
31
|
}
|
|
32
32
|
|
|
33
33
|
statement() {
|
|
34
|
+
if (this.current.type === 'ASYNC' && this.peekType() === 'FUNC') {
|
|
35
|
+
this.eat('ASYNC');
|
|
36
|
+
this.eat('FUNC');
|
|
37
|
+
return this.asyncFuncDeclaration();
|
|
38
|
+
}
|
|
34
39
|
switch (this.current.type) {
|
|
35
40
|
case 'LET': return this.varDeclaration();
|
|
36
41
|
case 'SLDEPLOY': return this.sldeployStatement();
|
|
@@ -78,6 +83,24 @@ class Parser {
|
|
|
78
83
|
if (this.current.type === 'SEMICOLON') this.eat('SEMICOLON');
|
|
79
84
|
return { type: 'DefineStatement', id, expr };
|
|
80
85
|
}
|
|
86
|
+
asyncFuncDeclaration() {
|
|
87
|
+
const name = this.current.value;
|
|
88
|
+
this.eat('IDENTIFIER');
|
|
89
|
+
this.eat('LPAREN');
|
|
90
|
+
const params = [];
|
|
91
|
+
if (this.current.type !== 'RPAREN') {
|
|
92
|
+
params.push(this.current.value);
|
|
93
|
+
this.eat('IDENTIFIER');
|
|
94
|
+
while (this.current.type === 'COMMA') {
|
|
95
|
+
this.eat('COMMA');
|
|
96
|
+
params.push(this.current.value);
|
|
97
|
+
this.eat('IDENTIFIER');
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
this.eat('RPAREN');
|
|
101
|
+
const body = this.block();
|
|
102
|
+
return { type: 'FunctionDeclaration', name, params, body, async: true };
|
|
103
|
+
}
|
|
81
104
|
|
|
82
105
|
ifStatement() {
|
|
83
106
|
this.eat('IF');
|
|
@@ -386,7 +409,11 @@ arrowFunction(params) {
|
|
|
386
409
|
if (t.type === 'TRUE') { this.eat('TRUE'); return { type: 'Literal', value: true }; }
|
|
387
410
|
if (t.type === 'FALSE') { this.eat('FALSE'); return { type: 'Literal', value: false }; }
|
|
388
411
|
if (t.type === 'NULL') { this.eat('NULL'); return { type: 'Literal', value: null }; }
|
|
389
|
-
|
|
412
|
+
if (t.type === 'AWAIT') {
|
|
413
|
+
this.eat('AWAIT');
|
|
414
|
+
const argument = this.expression();
|
|
415
|
+
return { type: 'AwaitExpression', argument };
|
|
416
|
+
}
|
|
390
417
|
if (t.type === 'ASK') {
|
|
391
418
|
this.eat('ASK');
|
|
392
419
|
this.eat('LPAREN');
|