mevento 1.9.1 → 1.9.5
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/esm2020/lib/mevento.mjs +49 -20
- package/fesm2015/mevento.mjs +49 -19
- package/fesm2015/mevento.mjs.map +1 -1
- package/fesm2020/mevento.mjs +48 -19
- package/fesm2020/mevento.mjs.map +1 -1
- package/lib/mevento.d.ts +1 -1
- package/package.json +1 -1
package/fesm2020/mevento.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
function error(token) {
|
|
2
|
-
const text = `Invalid token ${token.type}[${token.value}] at ${token.line}, ${token.col}\n`;
|
|
1
|
+
function error(token, expected) {
|
|
2
|
+
const text = `Invalid token ${token.type}[${token.value}] at ${token.line}, ${token.col} ${expected ? `: expecting ${expected} token` : ''}\n`;
|
|
3
3
|
throw (text);
|
|
4
4
|
}
|
|
5
5
|
function isNum(value) {
|
|
@@ -236,8 +236,7 @@ class Lexer {
|
|
|
236
236
|
['\n', '\r', '\u2028', '\u2029'].includes(String.fromCharCode(c));
|
|
237
237
|
}
|
|
238
238
|
_isWhiteSpace(c) {
|
|
239
|
-
return String.fromCharCode(c)
|
|
240
|
-
String.fromCharCode(c).length > 0;
|
|
239
|
+
return [' ', '\t'].includes(String.fromCharCode(c));
|
|
241
240
|
}
|
|
242
241
|
_isDigit(c) {
|
|
243
242
|
// tslint:disable-next-line:no-bitwise
|
|
@@ -461,7 +460,7 @@ class Lexer {
|
|
|
461
460
|
if (this._currentChar === Chars.pipe && this._pick() === Chars.pipe) {
|
|
462
461
|
this._advance();
|
|
463
462
|
this._advance();
|
|
464
|
-
return new Token(TokenType.
|
|
463
|
+
return new Token(TokenType.or, '||', lastL, lastC);
|
|
465
464
|
}
|
|
466
465
|
if (this._currentChar === Chars.quote || this._currentChar === Chars.squote) {
|
|
467
466
|
const startChar = this._currentChar;
|
|
@@ -762,7 +761,7 @@ class Parser {
|
|
|
762
761
|
this.currentToken = this.lexer.nextToken();
|
|
763
762
|
}
|
|
764
763
|
else {
|
|
765
|
-
error(this.currentToken);
|
|
764
|
+
error(this.currentToken, type);
|
|
766
765
|
}
|
|
767
766
|
}
|
|
768
767
|
_eatEOL() {
|
|
@@ -793,7 +792,7 @@ class Parser {
|
|
|
793
792
|
case TokenType.minus:
|
|
794
793
|
case TokenType.not:
|
|
795
794
|
this._eat(this.currentToken.type);
|
|
796
|
-
return new UnaryExpressionAST(token, this.
|
|
795
|
+
return new UnaryExpressionAST(token, this._expression());
|
|
797
796
|
case TokenType.numberConst:
|
|
798
797
|
this._eat(TokenType.numberConst);
|
|
799
798
|
return new LiteralAST(token, token.value.toString());
|
|
@@ -889,6 +888,9 @@ class Parser {
|
|
|
889
888
|
while (this.currentToken?.type === TokenType.comma) {
|
|
890
889
|
this._eat(TokenType.comma);
|
|
891
890
|
this._eatEOL();
|
|
891
|
+
if (this._expect(TokenType.rbrace)) {
|
|
892
|
+
break;
|
|
893
|
+
}
|
|
892
894
|
properties.push(this._property());
|
|
893
895
|
this._eatEOL();
|
|
894
896
|
}
|
|
@@ -946,6 +948,10 @@ class Parser {
|
|
|
946
948
|
const result = [expr];
|
|
947
949
|
while (this.currentToken?.type === TokenType.comma) {
|
|
948
950
|
this._eat(TokenType.comma);
|
|
951
|
+
this._eatEOL();
|
|
952
|
+
if (this._expect(TokenType.rbracket)) {
|
|
953
|
+
break;
|
|
954
|
+
}
|
|
949
955
|
expr = this._expression();
|
|
950
956
|
result.push(expr);
|
|
951
957
|
}
|
|
@@ -1216,7 +1222,6 @@ class ANodeVisitor {
|
|
|
1216
1222
|
}
|
|
1217
1223
|
registerVisitor(type, visitor) {
|
|
1218
1224
|
const methodName = `visit${type.name}`;
|
|
1219
|
-
// console.log('Reg::::::', methodName, type);
|
|
1220
1225
|
this._nodesVisitors[methodName] = visitor;
|
|
1221
1226
|
}
|
|
1222
1227
|
}
|
|
@@ -1245,10 +1250,15 @@ class NodeVisitor extends ANodeVisitor {
|
|
|
1245
1250
|
this.registerVisitor(ContinueAST, this.visitContinueAST);
|
|
1246
1251
|
}
|
|
1247
1252
|
visit(node) {
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1253
|
+
try {
|
|
1254
|
+
const methodName = `visit${node.constructor.name}`;
|
|
1255
|
+
// const fn = Object.getPrototypeOf(this)[methodName];
|
|
1256
|
+
const fn = this._nodesVisitors[methodName];
|
|
1257
|
+
return fn?.call(this, node) ?? null;
|
|
1258
|
+
}
|
|
1259
|
+
catch (error) {
|
|
1260
|
+
return null;
|
|
1261
|
+
}
|
|
1252
1262
|
}
|
|
1253
1263
|
assignProperty(owner, property, value) {
|
|
1254
1264
|
if (Array.isArray(owner)) {
|
|
@@ -1476,19 +1486,29 @@ class MEvento extends NodeVisitor {
|
|
|
1476
1486
|
}
|
|
1477
1487
|
visitLogicalExpressionAST(node) {
|
|
1478
1488
|
const leftNode = node.left;
|
|
1479
|
-
|
|
1489
|
+
let test = this.visit(leftNode);
|
|
1480
1490
|
const testBoolValue = _boolValue(test);
|
|
1481
1491
|
if (node.operator.type === TokenType.and) {
|
|
1482
|
-
|
|
1492
|
+
if (!testBoolValue) {
|
|
1493
|
+
return false;
|
|
1494
|
+
}
|
|
1495
|
+
return _boolValue(this.visit(node.right));
|
|
1483
1496
|
}
|
|
1484
1497
|
if (node.operator.type === TokenType.or) {
|
|
1485
|
-
|
|
1498
|
+
if (testBoolValue) {
|
|
1499
|
+
return test;
|
|
1500
|
+
}
|
|
1501
|
+
test = this.visit(node.right);
|
|
1502
|
+
return test;
|
|
1486
1503
|
}
|
|
1487
1504
|
return false;
|
|
1488
1505
|
}
|
|
1489
1506
|
visitIndexAccessorAST(node) {
|
|
1490
1507
|
const ownerNode = node.owner;
|
|
1491
1508
|
const owner = this.visit(ownerNode);
|
|
1509
|
+
if (owner === null || owner === undefined) {
|
|
1510
|
+
return null;
|
|
1511
|
+
}
|
|
1492
1512
|
if (typeof owner === 'object') {
|
|
1493
1513
|
const key = this.visit(node.key);
|
|
1494
1514
|
return owner[key];
|
|
@@ -1560,7 +1580,6 @@ class MEvento extends NodeVisitor {
|
|
|
1560
1580
|
if (!isNum(tmp))
|
|
1561
1581
|
throw Error("Cant update value");
|
|
1562
1582
|
this.changeVariable(loopIdentifier.value, node.direction.type === TokenType.up ? tmp + updateValue : tmp - updateValue);
|
|
1563
|
-
// console.log('Update loop from ' + tmp + ' to ' + this.resolve(loopIdentifier.value))
|
|
1564
1583
|
}
|
|
1565
1584
|
else {
|
|
1566
1585
|
throw Error("Update value cant be non number");
|
|
@@ -1840,19 +1859,29 @@ class MEventoAsync extends MEvento {
|
|
|
1840
1859
|
}
|
|
1841
1860
|
async visitLogicalExpressionAST(node) {
|
|
1842
1861
|
const leftNode = node.left;
|
|
1843
|
-
|
|
1862
|
+
let test = await this.visit(leftNode);
|
|
1844
1863
|
const testBoolValue = _boolValue(test);
|
|
1845
1864
|
if (node.operator.type === TokenType.and) {
|
|
1846
|
-
|
|
1865
|
+
if (!testBoolValue) {
|
|
1866
|
+
return false;
|
|
1867
|
+
}
|
|
1868
|
+
return _boolValue(await this.visit(node.right));
|
|
1847
1869
|
}
|
|
1848
1870
|
if (node.operator.type === TokenType.or) {
|
|
1849
|
-
|
|
1871
|
+
if (testBoolValue) {
|
|
1872
|
+
return test;
|
|
1873
|
+
}
|
|
1874
|
+
test = await this.visit(node.right);
|
|
1875
|
+
return test;
|
|
1850
1876
|
}
|
|
1851
1877
|
return false;
|
|
1852
1878
|
}
|
|
1853
1879
|
async visitIndexAccessorAST(node) {
|
|
1854
1880
|
const ownerNode = node.owner;
|
|
1855
1881
|
const owner = await this.visit(ownerNode);
|
|
1882
|
+
if (owner === null || owner === undefined) {
|
|
1883
|
+
return null;
|
|
1884
|
+
}
|
|
1856
1885
|
if (typeof owner === 'object') {
|
|
1857
1886
|
const key = await this.visit(node.key);
|
|
1858
1887
|
return owner[key];
|