mevento 1.2.2 → 1.8.0

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.
@@ -79,6 +79,7 @@ TokenType.with = 39;
79
79
  TokenType.in = 40;
80
80
  TokenType.TILL = 41;
81
81
  TokenType.BREAK = 42;
82
+ TokenType.CONTINUE = 43;
82
83
  class Token {
83
84
  constructor(type, value, line = 1, col = 1) {
84
85
  this.type = type;
@@ -490,6 +491,7 @@ Lexer._defaultLanguage = new LexerDictionary("en", {
490
491
  "till": "till",
491
492
  "in": "in",
492
493
  "break": "break",
494
+ "continue": "continue",
493
495
  });
494
496
  Lexer.languages = [
495
497
  Lexer._defaultLanguage,
@@ -502,11 +504,12 @@ Lexer.languages = [
502
504
  "tanque": "while",
503
505
  "pour": "for",
504
506
  "avec": "with",
505
- "mon": "up",
507
+ "mont": "up",
506
508
  "desc": "down",
507
509
  "jusqua": "till",
508
510
  "dans": "in",
509
511
  "couper": "break",
512
+ "continuer": "continue",
510
513
  }),
511
514
  new LexerDictionary("bm", {
512
515
  "nii": "if",
@@ -522,6 +525,7 @@ Lexer.languages = [
522
525
  "kata": "till",
523
526
  "kono": "in",
524
527
  "tike": "break",
528
+ "ipan": "continue",
525
529
  }),
526
530
  ];
527
531
  Lexer.RESERVED = {
@@ -538,6 +542,7 @@ Lexer.RESERVED = {
538
542
  "till": Token.from(TokenType.TILL, "till"),
539
543
  "in": Token.from(TokenType.in, "in"),
540
544
  "break": Token.from(TokenType.BREAK, "break"),
545
+ "continue": Token.from(TokenType.CONTINUE, "continue"),
541
546
  };
542
547
  /**
543
548
  * Parser
@@ -744,6 +749,11 @@ class BreakAST extends AST {
744
749
  super(line, col);
745
750
  }
746
751
  }
752
+ class ContinueAST extends AST {
753
+ constructor(line, col) {
754
+ super(line, col);
755
+ }
756
+ }
747
757
  class Parser {
748
758
  constructor(lexer) {
749
759
  this.currentToken = lexer.nextToken();
@@ -986,8 +996,7 @@ class Parser {
986
996
  }
987
997
  // const body = _statements();
988
998
  const body = [this._statement()];
989
- while (this.currentToken.type === TokenType.eol ||
990
- this.currentToken.type === TokenType.semi) {
999
+ while (true) {
991
1000
  this._eatSemiOrEOL();
992
1001
  if (this.currentToken.type === TokenType.rbrace || this.currentToken.type === TokenType.eof) {
993
1002
  // _eat(this.currentToken!.type);
@@ -1051,7 +1060,6 @@ class Parser {
1051
1060
  return new WhileLoopStatement(test, body, token, this.currentToken);
1052
1061
  }
1053
1062
  _forOfIdentifier() {
1054
- let node;
1055
1063
  switch (this.currentToken.type) {
1056
1064
  case TokenType.lparen: {
1057
1065
  // probable tuple
@@ -1127,11 +1135,14 @@ class Parser {
1127
1135
  return node;
1128
1136
  }
1129
1137
  _statement() {
1130
- var _a, _b;
1138
+ var _a, _b, _c, _d;
1131
1139
  switch (this.currentToken.type) {
1132
1140
  case TokenType.BREAK:
1133
1141
  this._eat(TokenType.BREAK);
1134
1142
  return new BreakAST((_a = this.currentToken) === null || _a === void 0 ? void 0 : _a.line, (_b = this.currentToken) === null || _b === void 0 ? void 0 : _b.col);
1143
+ case TokenType.CONTINUE:
1144
+ this._eat(TokenType.CONTINUE);
1145
+ return new ContinueAST((_c = this.currentToken) === null || _c === void 0 ? void 0 : _c.line, (_d = this.currentToken) === null || _d === void 0 ? void 0 : _d.col);
1135
1146
  case TokenType.semi:
1136
1147
  this._eatSemi();
1137
1148
  return this._statement();
@@ -1164,7 +1175,12 @@ class Parser {
1164
1175
  this._eat(TokenType.eof);
1165
1176
  break;
1166
1177
  }
1167
- results.push(this._statement());
1178
+ if (this.currentToken.type === TokenType.lbrace) {
1179
+ results.push(this._blockStatement());
1180
+ }
1181
+ else {
1182
+ results.push(this._statement());
1183
+ }
1168
1184
  // if (this.currentToken!.type !== TokenType.eol &&
1169
1185
  // this.currentToken!.type !== TokenType.semi &&
1170
1186
  // this.currentToken!.type !== TokenType.eof) {
@@ -1196,7 +1212,11 @@ Parser._binopPrecdences = {
1196
1212
  [TokenType.div]: 40,
1197
1213
  [TokenType.mod]: 40,
1198
1214
  };
1199
- class BreakBranch {
1215
+ class LoopControl {
1216
+ }
1217
+ class BreakBranch extends LoopControl {
1218
+ }
1219
+ class ContinueBranch extends LoopControl {
1200
1220
  }
1201
1221
  // AST Wallker
1202
1222
  class ANodeVisitor {
@@ -1210,19 +1230,8 @@ class ANodeVisitor {
1210
1230
  }
1211
1231
  }
1212
1232
  class NodeVisitor extends ANodeVisitor {
1213
- visit(node) {
1214
- const methodName = `visit${node.constructor.name}`;
1215
- // const fn = Object.getPrototypeOf(this)[methodName];
1216
- const fn = this._nodesVisitors[methodName];
1217
- return fn === null || fn === void 0 ? void 0 : fn.call(this, node);
1218
- }
1219
- }
1220
- class MEvento extends NodeVisitor {
1221
1233
  constructor() {
1222
1234
  super();
1223
- this._memory = {};
1224
- this.debug = false;
1225
- this._functionsRegistry = {};
1226
1235
  this.registerVisitor(RootAST, this.visitRootAST);
1227
1236
  this.registerVisitor(BlockStatementAST, this.visitBlockStatementAST);
1228
1237
  this.registerVisitor(IdentifierAST, this.visitIdentifierAST);
@@ -1242,6 +1251,30 @@ class MEvento extends NodeVisitor {
1242
1251
  this.registerVisitor(ForLoopStatement, this.visitForLoopStatement);
1243
1252
  this.registerVisitor(ForOfStatement, this.visitForOfStatement);
1244
1253
  this.registerVisitor(BreakAST, this.visitBreakAST);
1254
+ this.registerVisitor(ContinueAST, this.visitContinueAST);
1255
+ }
1256
+ visit(node) {
1257
+ const methodName = `visit${node.constructor.name}`;
1258
+ // const fn = Object.getPrototypeOf(this)[methodName];
1259
+ const fn = this._nodesVisitors[methodName];
1260
+ return fn === null || fn === void 0 ? void 0 : fn.call(this, node);
1261
+ }
1262
+ assignProperty(owner, property, value) {
1263
+ if (Array.isArray(owner)) {
1264
+ owner[property] = value;
1265
+ }
1266
+ else if (typeof owner === 'object') {
1267
+ owner[property] = value;
1268
+ }
1269
+ else { }
1270
+ }
1271
+ }
1272
+ class MEvento extends NodeVisitor {
1273
+ constructor() {
1274
+ super();
1275
+ this._memory = {};
1276
+ this.debug = false;
1277
+ this._functionsRegistry = {};
1245
1278
  this._functionsRegistry = Object.assign({}, MEvento._globalFunctionsRegistry);
1246
1279
  }
1247
1280
  log(message) {
@@ -1262,6 +1295,9 @@ class MEvento extends NodeVisitor {
1262
1295
  let last;
1263
1296
  for (const n of list) {
1264
1297
  last = this.visit(n);
1298
+ if (last instanceof LoopControl) {
1299
+ return last;
1300
+ }
1265
1301
  }
1266
1302
  return last;
1267
1303
  }
@@ -1289,15 +1325,6 @@ class MEvento extends NodeVisitor {
1289
1325
  }
1290
1326
  return value;
1291
1327
  }
1292
- assignProperty(owner, property, value) {
1293
- if (Array.isArray(owner)) {
1294
- owner[property] = value;
1295
- }
1296
- else if (typeof owner === 'object') {
1297
- owner[property] = value;
1298
- }
1299
- else { }
1300
- }
1301
1328
  visitExpressionStatementAST(node) {
1302
1329
  const expr = node.expression;
1303
1330
  return this.visit(expr);
@@ -1464,6 +1491,9 @@ class MEvento extends NodeVisitor {
1464
1491
  if (ret instanceof BreakBranch) {
1465
1492
  break;
1466
1493
  }
1494
+ if (ret instanceof ContinueAST) {
1495
+ continue;
1496
+ }
1467
1497
  retainer === null || retainer === void 0 ? void 0 : retainer.push(ret);
1468
1498
  }
1469
1499
  return retainer || null;
@@ -1489,6 +1519,9 @@ class MEvento extends NodeVisitor {
1489
1519
  if (ret instanceof BreakBranch) {
1490
1520
  break;
1491
1521
  }
1522
+ if (ret instanceof ContinueAST) {
1523
+ continue;
1524
+ }
1492
1525
  retainer === null || retainer === void 0 ? void 0 : retainer.push(ret);
1493
1526
  // update
1494
1527
  if (node.update instanceof LiteralAST && isNum(node.update.value)) {
@@ -1516,10 +1549,16 @@ class MEvento extends NodeVisitor {
1516
1549
  if (ret instanceof BreakBranch) {
1517
1550
  break;
1518
1551
  }
1552
+ if (ret instanceof ContinueAST) {
1553
+ continue;
1554
+ }
1519
1555
  retainer === null || retainer === void 0 ? void 0 : retainer.push(ret);
1520
1556
  }
1521
1557
  return retainer || null;
1522
1558
  }
1559
+ visitContinueAST(node) {
1560
+ return new ContinueBranch();
1561
+ }
1523
1562
  _declareForIdentifier(node, value) {
1524
1563
  if (node instanceof TupleExpression) {
1525
1564
  if (!Array.isArray(value)) {
@@ -1613,6 +1652,9 @@ class MEventoAsync extends MEvento {
1613
1652
  let last;
1614
1653
  for (const n of list) {
1615
1654
  last = yield this.visit(n);
1655
+ if (last instanceof LoopControl) {
1656
+ return last;
1657
+ }
1616
1658
  }
1617
1659
  return last;
1618
1660
  });
@@ -1828,6 +1870,9 @@ class MEventoAsync extends MEvento {
1828
1870
  if (ret instanceof BreakBranch) {
1829
1871
  break;
1830
1872
  }
1873
+ if (ret instanceof ContinueAST) {
1874
+ continue;
1875
+ }
1831
1876
  retainer === null || retainer === void 0 ? void 0 : retainer.push(ret);
1832
1877
  }
1833
1878
  return retainer;
@@ -1855,6 +1900,9 @@ class MEventoAsync extends MEvento {
1855
1900
  if (ret instanceof BreakBranch) {
1856
1901
  break;
1857
1902
  }
1903
+ if (ret instanceof ContinueAST) {
1904
+ continue;
1905
+ }
1858
1906
  retainer === null || retainer === void 0 ? void 0 : retainer.push(ret);
1859
1907
  // update
1860
1908
  if (node.update instanceof LiteralAST && isNum(node.update.value)) {
@@ -1884,6 +1932,9 @@ class MEventoAsync extends MEvento {
1884
1932
  if (ret instanceof BreakBranch) {
1885
1933
  break;
1886
1934
  }
1935
+ if (ret instanceof ContinueAST) {
1936
+ continue;
1937
+ }
1887
1938
  retainer === null || retainer === void 0 ? void 0 : retainer.push(ret);
1888
1939
  }
1889
1940
  return retainer;
@@ -1934,5 +1985,5 @@ class MEventoAsync extends MEvento {
1934
1985
  * Generated bundle index. Do not edit.
1935
1986
  */
1936
1987
 
1937
- export { AST, ArrayExpression, AssignmentExpressionAST, BinaryExpressionAST, BlockStatementAST, BreakAST, BreakBranch, CallExpressionAST, ExpressionStatementAST, ForLoopStatement, ForOfStatement, IdentifierAST, IfStatementAST, IndexAccessorAST, LexerDictionary, LiteralAST, LogicalExpressionAST, MEvento, MEventoAsync, NodeVisitor, ObjectExpression, ObjectProperty, RootAST, Token, TokenType, TupleExpression, UnaryExpressionAST, WhileLoopStatement };
1988
+ export { AST, ArrayExpression, AssignmentExpressionAST, BinaryExpressionAST, BlockStatementAST, BreakAST, BreakBranch, CallExpressionAST, ContinueAST, ContinueBranch, ExpressionStatementAST, ForLoopStatement, ForOfStatement, IdentifierAST, IfStatementAST, IndexAccessorAST, LexerDictionary, LiteralAST, LogicalExpressionAST, LoopControl, MEvento, MEventoAsync, NodeVisitor, ObjectExpression, ObjectProperty, RootAST, Token, TokenType, TupleExpression, UnaryExpressionAST, WhileLoopStatement };
1938
1989
  //# sourceMappingURL=mevento.mjs.map