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/fesm2015/mevento.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { __awaiter } from 'tslib';
|
|
2
2
|
|
|
3
|
-
function error(token) {
|
|
4
|
-
const text = `Invalid token ${token.type}[${token.value}] at ${token.line}, ${token.col}\n`;
|
|
3
|
+
function error(token, expected) {
|
|
4
|
+
const text = `Invalid token ${token.type}[${token.value}] at ${token.line}, ${token.col} ${expected ? `: expecting ${expected} token` : ''}\n`;
|
|
5
5
|
throw (text);
|
|
6
6
|
}
|
|
7
7
|
function isNum(value) {
|
|
@@ -240,8 +240,7 @@ class Lexer {
|
|
|
240
240
|
['\n', '\r', '\u2028', '\u2029'].includes(String.fromCharCode(c));
|
|
241
241
|
}
|
|
242
242
|
_isWhiteSpace(c) {
|
|
243
|
-
return String.fromCharCode(c)
|
|
244
|
-
String.fromCharCode(c).length > 0;
|
|
243
|
+
return [' ', '\t'].includes(String.fromCharCode(c));
|
|
245
244
|
}
|
|
246
245
|
_isDigit(c) {
|
|
247
246
|
// tslint:disable-next-line:no-bitwise
|
|
@@ -465,7 +464,7 @@ class Lexer {
|
|
|
465
464
|
if (this._currentChar === Chars.pipe && this._pick() === Chars.pipe) {
|
|
466
465
|
this._advance();
|
|
467
466
|
this._advance();
|
|
468
|
-
return new Token(TokenType.
|
|
467
|
+
return new Token(TokenType.or, '||', lastL, lastC);
|
|
469
468
|
}
|
|
470
469
|
if (this._currentChar === Chars.quote || this._currentChar === Chars.squote) {
|
|
471
470
|
const startChar = this._currentChar;
|
|
@@ -767,7 +766,7 @@ class Parser {
|
|
|
767
766
|
this.currentToken = this.lexer.nextToken();
|
|
768
767
|
}
|
|
769
768
|
else {
|
|
770
|
-
error(this.currentToken);
|
|
769
|
+
error(this.currentToken, type);
|
|
771
770
|
}
|
|
772
771
|
}
|
|
773
772
|
_eatEOL() {
|
|
@@ -801,7 +800,7 @@ class Parser {
|
|
|
801
800
|
case TokenType.minus:
|
|
802
801
|
case TokenType.not:
|
|
803
802
|
this._eat(this.currentToken.type);
|
|
804
|
-
return new UnaryExpressionAST(token, this.
|
|
803
|
+
return new UnaryExpressionAST(token, this._expression());
|
|
805
804
|
case TokenType.numberConst:
|
|
806
805
|
this._eat(TokenType.numberConst);
|
|
807
806
|
return new LiteralAST(token, token.value.toString());
|
|
@@ -899,6 +898,9 @@ class Parser {
|
|
|
899
898
|
while (((_b = this.currentToken) === null || _b === void 0 ? void 0 : _b.type) === TokenType.comma) {
|
|
900
899
|
this._eat(TokenType.comma);
|
|
901
900
|
this._eatEOL();
|
|
901
|
+
if (this._expect(TokenType.rbrace)) {
|
|
902
|
+
break;
|
|
903
|
+
}
|
|
902
904
|
properties.push(this._property());
|
|
903
905
|
this._eatEOL();
|
|
904
906
|
}
|
|
@@ -957,6 +959,10 @@ class Parser {
|
|
|
957
959
|
const result = [expr];
|
|
958
960
|
while (((_a = this.currentToken) === null || _a === void 0 ? void 0 : _a.type) === TokenType.comma) {
|
|
959
961
|
this._eat(TokenType.comma);
|
|
962
|
+
this._eatEOL();
|
|
963
|
+
if (this._expect(TokenType.rbracket)) {
|
|
964
|
+
break;
|
|
965
|
+
}
|
|
960
966
|
expr = this._expression();
|
|
961
967
|
result.push(expr);
|
|
962
968
|
}
|
|
@@ -1230,7 +1236,6 @@ class ANodeVisitor {
|
|
|
1230
1236
|
}
|
|
1231
1237
|
registerVisitor(type, visitor) {
|
|
1232
1238
|
const methodName = `visit${type.name}`;
|
|
1233
|
-
// console.log('Reg::::::', methodName, type);
|
|
1234
1239
|
this._nodesVisitors[methodName] = visitor;
|
|
1235
1240
|
}
|
|
1236
1241
|
}
|
|
@@ -1259,10 +1264,16 @@ class NodeVisitor extends ANodeVisitor {
|
|
|
1259
1264
|
this.registerVisitor(ContinueAST, this.visitContinueAST);
|
|
1260
1265
|
}
|
|
1261
1266
|
visit(node) {
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1267
|
+
var _a;
|
|
1268
|
+
try {
|
|
1269
|
+
const methodName = `visit${node.constructor.name}`;
|
|
1270
|
+
// const fn = Object.getPrototypeOf(this)[methodName];
|
|
1271
|
+
const fn = this._nodesVisitors[methodName];
|
|
1272
|
+
return (_a = fn === null || fn === void 0 ? void 0 : fn.call(this, node)) !== null && _a !== void 0 ? _a : null;
|
|
1273
|
+
}
|
|
1274
|
+
catch (error) {
|
|
1275
|
+
return null;
|
|
1276
|
+
}
|
|
1266
1277
|
}
|
|
1267
1278
|
assignProperty(owner, property, value) {
|
|
1268
1279
|
if (Array.isArray(owner)) {
|
|
@@ -1495,19 +1506,29 @@ class MEvento extends NodeVisitor {
|
|
|
1495
1506
|
}
|
|
1496
1507
|
visitLogicalExpressionAST(node) {
|
|
1497
1508
|
const leftNode = node.left;
|
|
1498
|
-
|
|
1509
|
+
let test = this.visit(leftNode);
|
|
1499
1510
|
const testBoolValue = _boolValue(test);
|
|
1500
1511
|
if (node.operator.type === TokenType.and) {
|
|
1501
|
-
|
|
1512
|
+
if (!testBoolValue) {
|
|
1513
|
+
return false;
|
|
1514
|
+
}
|
|
1515
|
+
return _boolValue(this.visit(node.right));
|
|
1502
1516
|
}
|
|
1503
1517
|
if (node.operator.type === TokenType.or) {
|
|
1504
|
-
|
|
1518
|
+
if (testBoolValue) {
|
|
1519
|
+
return test;
|
|
1520
|
+
}
|
|
1521
|
+
test = this.visit(node.right);
|
|
1522
|
+
return test;
|
|
1505
1523
|
}
|
|
1506
1524
|
return false;
|
|
1507
1525
|
}
|
|
1508
1526
|
visitIndexAccessorAST(node) {
|
|
1509
1527
|
const ownerNode = node.owner;
|
|
1510
1528
|
const owner = this.visit(ownerNode);
|
|
1529
|
+
if (owner === null || owner === undefined) {
|
|
1530
|
+
return null;
|
|
1531
|
+
}
|
|
1511
1532
|
if (typeof owner === 'object') {
|
|
1512
1533
|
const key = this.visit(node.key);
|
|
1513
1534
|
return owner[key];
|
|
@@ -1579,7 +1600,6 @@ class MEvento extends NodeVisitor {
|
|
|
1579
1600
|
if (!isNum(tmp))
|
|
1580
1601
|
throw Error("Cant update value");
|
|
1581
1602
|
this.changeVariable(loopIdentifier.value, node.direction.type === TokenType.up ? tmp + updateValue : tmp - updateValue);
|
|
1582
|
-
// console.log('Update loop from ' + tmp + ' to ' + this.resolve(loopIdentifier.value))
|
|
1583
1603
|
}
|
|
1584
1604
|
else {
|
|
1585
1605
|
throw Error("Update value cant be non number");
|
|
@@ -1880,13 +1900,20 @@ class MEventoAsync extends MEvento {
|
|
|
1880
1900
|
visitLogicalExpressionAST(node) {
|
|
1881
1901
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1882
1902
|
const leftNode = node.left;
|
|
1883
|
-
|
|
1903
|
+
let test = yield this.visit(leftNode);
|
|
1884
1904
|
const testBoolValue = _boolValue(test);
|
|
1885
1905
|
if (node.operator.type === TokenType.and) {
|
|
1886
|
-
|
|
1906
|
+
if (!testBoolValue) {
|
|
1907
|
+
return false;
|
|
1908
|
+
}
|
|
1909
|
+
return _boolValue(yield this.visit(node.right));
|
|
1887
1910
|
}
|
|
1888
1911
|
if (node.operator.type === TokenType.or) {
|
|
1889
|
-
|
|
1912
|
+
if (testBoolValue) {
|
|
1913
|
+
return test;
|
|
1914
|
+
}
|
|
1915
|
+
test = yield this.visit(node.right);
|
|
1916
|
+
return test;
|
|
1890
1917
|
}
|
|
1891
1918
|
return false;
|
|
1892
1919
|
});
|
|
@@ -1895,6 +1922,9 @@ class MEventoAsync extends MEvento {
|
|
|
1895
1922
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1896
1923
|
const ownerNode = node.owner;
|
|
1897
1924
|
const owner = yield this.visit(ownerNode);
|
|
1925
|
+
if (owner === null || owner === undefined) {
|
|
1926
|
+
return null;
|
|
1927
|
+
}
|
|
1898
1928
|
if (typeof owner === 'object') {
|
|
1899
1929
|
const key = yield this.visit(node.key);
|
|
1900
1930
|
return owner[key];
|