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.
@@ -460,7 +460,7 @@ class Lexer {
460
460
  if (this._currentChar === Chars.pipe && this._pick() === Chars.pipe) {
461
461
  this._advance();
462
462
  this._advance();
463
- return new Token(TokenType.and, '||', lastL, lastC);
463
+ return new Token(TokenType.or, '||', lastL, lastC);
464
464
  }
465
465
  if (this._currentChar === Chars.quote || this._currentChar === Chars.squote) {
466
466
  const startChar = this._currentChar;
@@ -792,7 +792,7 @@ class Parser {
792
792
  case TokenType.minus:
793
793
  case TokenType.not:
794
794
  this._eat(this.currentToken.type);
795
- return new UnaryExpressionAST(token, this._factor());
795
+ return new UnaryExpressionAST(token, this._expression());
796
796
  case TokenType.numberConst:
797
797
  this._eat(TokenType.numberConst);
798
798
  return new LiteralAST(token, token.value.toString());
@@ -888,6 +888,9 @@ class Parser {
888
888
  while (this.currentToken?.type === TokenType.comma) {
889
889
  this._eat(TokenType.comma);
890
890
  this._eatEOL();
891
+ if (this._expect(TokenType.rbrace)) {
892
+ break;
893
+ }
891
894
  properties.push(this._property());
892
895
  this._eatEOL();
893
896
  }
@@ -945,6 +948,10 @@ class Parser {
945
948
  const result = [expr];
946
949
  while (this.currentToken?.type === TokenType.comma) {
947
950
  this._eat(TokenType.comma);
951
+ this._eatEOL();
952
+ if (this._expect(TokenType.rbracket)) {
953
+ break;
954
+ }
948
955
  expr = this._expression();
949
956
  result.push(expr);
950
957
  }
@@ -974,7 +981,6 @@ class Parser {
974
981
  const node = this._expression();
975
982
  if (![TokenType.semi, TokenType.eol, TokenType.eof]
976
983
  .includes(this.currentToken.type)) {
977
- console.log('DDDMMMS', this.currentToken);
978
984
  error(this.currentToken);
979
985
  }
980
986
  return node;
@@ -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
  }
@@ -1249,7 +1254,7 @@ class NodeVisitor extends ANodeVisitor {
1249
1254
  const methodName = `visit${node.constructor.name}`;
1250
1255
  // const fn = Object.getPrototypeOf(this)[methodName];
1251
1256
  const fn = this._nodesVisitors[methodName];
1252
- return fn?.call(this, node);
1257
+ return fn?.call(this, node) ?? null;
1253
1258
  }
1254
1259
  catch (error) {
1255
1260
  return null;
@@ -1375,7 +1380,7 @@ class MEvento extends NodeVisitor {
1375
1380
  const callee = node.callee;
1376
1381
  const args = node.arguments;
1377
1382
  const calleeName = callee.value;
1378
- const fn = this._functionsRegistry[calleeName];
1383
+ const fn = this.resolveFunction(calleeName);
1379
1384
  const argValues = args.map((e) => this.visit(e));
1380
1385
  // print("argValues::", argValues)
1381
1386
  return fn?.(argValues, this);
@@ -1481,13 +1486,20 @@ class MEvento extends NodeVisitor {
1481
1486
  }
1482
1487
  visitLogicalExpressionAST(node) {
1483
1488
  const leftNode = node.left;
1484
- const test = this.visit(leftNode);
1489
+ let test = this.visit(leftNode);
1485
1490
  const testBoolValue = _boolValue(test);
1486
1491
  if (node.operator.type === TokenType.and) {
1487
- return testBoolValue && _boolValue(this.visit(node.right));
1492
+ if (!testBoolValue) {
1493
+ return false;
1494
+ }
1495
+ return _boolValue(this.visit(node.right));
1488
1496
  }
1489
1497
  if (node.operator.type === TokenType.or) {
1490
- return testBoolValue || _boolValue(this.visit(node.right));
1498
+ if (testBoolValue) {
1499
+ return test;
1500
+ }
1501
+ test = this.visit(node.right);
1502
+ return test;
1491
1503
  }
1492
1504
  return false;
1493
1505
  }
@@ -1568,7 +1580,6 @@ class MEvento extends NodeVisitor {
1568
1580
  if (!isNum(tmp))
1569
1581
  throw Error("Cant update value");
1570
1582
  this.changeVariable(loopIdentifier.value, node.direction.type === TokenType.up ? tmp + updateValue : tmp - updateValue);
1571
- // console.log('Update loop from ' + tmp + ' to ' + this.resolve(loopIdentifier.value))
1572
1583
  }
1573
1584
  else {
1574
1585
  throw Error("Update value cant be non number");
@@ -1629,6 +1640,12 @@ class MEvento extends NodeVisitor {
1629
1640
  return this.visit(it);
1630
1641
  });
1631
1642
  }
1643
+ setFunctionResolver(resolver) {
1644
+ this._functionResolver = resolver;
1645
+ }
1646
+ resolveFunction(name) {
1647
+ return this._functionsRegistry[name] ?? this._functionResolver?.(name);
1648
+ }
1632
1649
  registerFunction(id, fn) {
1633
1650
  this._functionsRegistry[id] = fn;
1634
1651
  }
@@ -1848,13 +1865,20 @@ class MEventoAsync extends MEvento {
1848
1865
  }
1849
1866
  async visitLogicalExpressionAST(node) {
1850
1867
  const leftNode = node.left;
1851
- const test = await this.visit(leftNode);
1868
+ let test = await this.visit(leftNode);
1852
1869
  const testBoolValue = _boolValue(test);
1853
1870
  if (node.operator.type === TokenType.and) {
1854
- return testBoolValue && _boolValue(await this.visit(node.right));
1871
+ if (!testBoolValue) {
1872
+ return false;
1873
+ }
1874
+ return _boolValue(await this.visit(node.right));
1855
1875
  }
1856
1876
  if (node.operator.type === TokenType.or) {
1857
- return testBoolValue || _boolValue(await this.visit(node.right));
1877
+ if (testBoolValue) {
1878
+ return test;
1879
+ }
1880
+ test = await this.visit(node.right);
1881
+ return test;
1858
1882
  }
1859
1883
  return false;
1860
1884
  }