mevento 1.9.4 → 1.9.6

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.
@@ -464,7 +464,7 @@ class Lexer {
464
464
  if (this._currentChar === Chars.pipe && this._pick() === Chars.pipe) {
465
465
  this._advance();
466
466
  this._advance();
467
- return new Token(TokenType.and, '||', lastL, lastC);
467
+ return new Token(TokenType.or, '||', lastL, lastC);
468
468
  }
469
469
  if (this._currentChar === Chars.quote || this._currentChar === Chars.squote) {
470
470
  const startChar = this._currentChar;
@@ -800,7 +800,7 @@ class Parser {
800
800
  case TokenType.minus:
801
801
  case TokenType.not:
802
802
  this._eat(this.currentToken.type);
803
- return new UnaryExpressionAST(token, this._factor());
803
+ return new UnaryExpressionAST(token, this._expression());
804
804
  case TokenType.numberConst:
805
805
  this._eat(TokenType.numberConst);
806
806
  return new LiteralAST(token, token.value.toString());
@@ -898,6 +898,9 @@ class Parser {
898
898
  while (((_b = this.currentToken) === null || _b === void 0 ? void 0 : _b.type) === TokenType.comma) {
899
899
  this._eat(TokenType.comma);
900
900
  this._eatEOL();
901
+ if (this._expect(TokenType.rbrace)) {
902
+ break;
903
+ }
901
904
  properties.push(this._property());
902
905
  this._eatEOL();
903
906
  }
@@ -956,6 +959,10 @@ class Parser {
956
959
  const result = [expr];
957
960
  while (((_a = this.currentToken) === null || _a === void 0 ? void 0 : _a.type) === TokenType.comma) {
958
961
  this._eat(TokenType.comma);
962
+ this._eatEOL();
963
+ if (this._expect(TokenType.rbracket)) {
964
+ break;
965
+ }
959
966
  expr = this._expression();
960
967
  result.push(expr);
961
968
  }
@@ -985,7 +992,6 @@ class Parser {
985
992
  const node = this._expression();
986
993
  if (![TokenType.semi, TokenType.eol, TokenType.eof]
987
994
  .includes(this.currentToken.type)) {
988
- console.log('DDDMMMS', this.currentToken);
989
995
  error(this.currentToken);
990
996
  }
991
997
  return node;
@@ -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,11 +1264,12 @@ class NodeVisitor extends ANodeVisitor {
1259
1264
  this.registerVisitor(ContinueAST, this.visitContinueAST);
1260
1265
  }
1261
1266
  visit(node) {
1267
+ var _a;
1262
1268
  try {
1263
1269
  const methodName = `visit${node.constructor.name}`;
1264
1270
  // const fn = Object.getPrototypeOf(this)[methodName];
1265
1271
  const fn = this._nodesVisitors[methodName];
1266
- return fn === null || fn === void 0 ? void 0 : fn.call(this, node);
1272
+ return (_a = fn === null || fn === void 0 ? void 0 : fn.call(this, node)) !== null && _a !== void 0 ? _a : null;
1267
1273
  }
1268
1274
  catch (error) {
1269
1275
  return null;
@@ -1394,7 +1400,7 @@ class MEvento extends NodeVisitor {
1394
1400
  const callee = node.callee;
1395
1401
  const args = node.arguments;
1396
1402
  const calleeName = callee.value;
1397
- const fn = this._functionsRegistry[calleeName];
1403
+ const fn = this.resolveFunction(calleeName);
1398
1404
  const argValues = args.map((e) => this.visit(e));
1399
1405
  // print("argValues::", argValues)
1400
1406
  return fn === null || fn === void 0 ? void 0 : fn(argValues, this);
@@ -1500,13 +1506,20 @@ class MEvento extends NodeVisitor {
1500
1506
  }
1501
1507
  visitLogicalExpressionAST(node) {
1502
1508
  const leftNode = node.left;
1503
- const test = this.visit(leftNode);
1509
+ let test = this.visit(leftNode);
1504
1510
  const testBoolValue = _boolValue(test);
1505
1511
  if (node.operator.type === TokenType.and) {
1506
- return testBoolValue && _boolValue(this.visit(node.right));
1512
+ if (!testBoolValue) {
1513
+ return false;
1514
+ }
1515
+ return _boolValue(this.visit(node.right));
1507
1516
  }
1508
1517
  if (node.operator.type === TokenType.or) {
1509
- return testBoolValue || _boolValue(this.visit(node.right));
1518
+ if (testBoolValue) {
1519
+ return test;
1520
+ }
1521
+ test = this.visit(node.right);
1522
+ return test;
1510
1523
  }
1511
1524
  return false;
1512
1525
  }
@@ -1587,7 +1600,6 @@ class MEvento extends NodeVisitor {
1587
1600
  if (!isNum(tmp))
1588
1601
  throw Error("Cant update value");
1589
1602
  this.changeVariable(loopIdentifier.value, node.direction.type === TokenType.up ? tmp + updateValue : tmp - updateValue);
1590
- // console.log('Update loop from ' + tmp + ' to ' + this.resolve(loopIdentifier.value))
1591
1603
  }
1592
1604
  else {
1593
1605
  throw Error("Update value cant be non number");
@@ -1648,6 +1660,13 @@ class MEvento extends NodeVisitor {
1648
1660
  return this.visit(it);
1649
1661
  });
1650
1662
  }
1663
+ setFunctionResolver(resolver) {
1664
+ this._functionResolver = resolver;
1665
+ }
1666
+ resolveFunction(name) {
1667
+ var _a, _b;
1668
+ return (_a = this._functionsRegistry[name]) !== null && _a !== void 0 ? _a : (_b = this._functionResolver) === null || _b === void 0 ? void 0 : _b.call(this, name);
1669
+ }
1651
1670
  registerFunction(id, fn) {
1652
1671
  this._functionsRegistry[id] = fn;
1653
1672
  }
@@ -1888,13 +1907,20 @@ class MEventoAsync extends MEvento {
1888
1907
  visitLogicalExpressionAST(node) {
1889
1908
  return __awaiter(this, void 0, void 0, function* () {
1890
1909
  const leftNode = node.left;
1891
- const test = yield this.visit(leftNode);
1910
+ let test = yield this.visit(leftNode);
1892
1911
  const testBoolValue = _boolValue(test);
1893
1912
  if (node.operator.type === TokenType.and) {
1894
- return testBoolValue && _boolValue(yield this.visit(node.right));
1913
+ if (!testBoolValue) {
1914
+ return false;
1915
+ }
1916
+ return _boolValue(yield this.visit(node.right));
1895
1917
  }
1896
1918
  if (node.operator.type === TokenType.or) {
1897
- return testBoolValue || _boolValue(yield this.visit(node.right));
1919
+ if (testBoolValue) {
1920
+ return test;
1921
+ }
1922
+ test = yield this.visit(node.right);
1923
+ return test;
1898
1924
  }
1899
1925
  return false;
1900
1926
  });