mevento 1.4.0 → 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 {
@@ -1231,6 +1251,7 @@ class NodeVisitor extends ANodeVisitor {
1231
1251
  this.registerVisitor(ForLoopStatement, this.visitForLoopStatement);
1232
1252
  this.registerVisitor(ForOfStatement, this.visitForOfStatement);
1233
1253
  this.registerVisitor(BreakAST, this.visitBreakAST);
1254
+ this.registerVisitor(ContinueAST, this.visitContinueAST);
1234
1255
  }
1235
1256
  visit(node) {
1236
1257
  const methodName = `visit${node.constructor.name}`;
@@ -1274,6 +1295,9 @@ class MEvento extends NodeVisitor {
1274
1295
  let last;
1275
1296
  for (const n of list) {
1276
1297
  last = this.visit(n);
1298
+ if (last instanceof LoopControl) {
1299
+ return last;
1300
+ }
1277
1301
  }
1278
1302
  return last;
1279
1303
  }
@@ -1467,6 +1491,9 @@ class MEvento extends NodeVisitor {
1467
1491
  if (ret instanceof BreakBranch) {
1468
1492
  break;
1469
1493
  }
1494
+ if (ret instanceof ContinueAST) {
1495
+ continue;
1496
+ }
1470
1497
  retainer === null || retainer === void 0 ? void 0 : retainer.push(ret);
1471
1498
  }
1472
1499
  return retainer || null;
@@ -1492,6 +1519,9 @@ class MEvento extends NodeVisitor {
1492
1519
  if (ret instanceof BreakBranch) {
1493
1520
  break;
1494
1521
  }
1522
+ if (ret instanceof ContinueAST) {
1523
+ continue;
1524
+ }
1495
1525
  retainer === null || retainer === void 0 ? void 0 : retainer.push(ret);
1496
1526
  // update
1497
1527
  if (node.update instanceof LiteralAST && isNum(node.update.value)) {
@@ -1519,10 +1549,16 @@ class MEvento extends NodeVisitor {
1519
1549
  if (ret instanceof BreakBranch) {
1520
1550
  break;
1521
1551
  }
1552
+ if (ret instanceof ContinueAST) {
1553
+ continue;
1554
+ }
1522
1555
  retainer === null || retainer === void 0 ? void 0 : retainer.push(ret);
1523
1556
  }
1524
1557
  return retainer || null;
1525
1558
  }
1559
+ visitContinueAST(node) {
1560
+ return new ContinueBranch();
1561
+ }
1526
1562
  _declareForIdentifier(node, value) {
1527
1563
  if (node instanceof TupleExpression) {
1528
1564
  if (!Array.isArray(value)) {
@@ -1616,6 +1652,9 @@ class MEventoAsync extends MEvento {
1616
1652
  let last;
1617
1653
  for (const n of list) {
1618
1654
  last = yield this.visit(n);
1655
+ if (last instanceof LoopControl) {
1656
+ return last;
1657
+ }
1619
1658
  }
1620
1659
  return last;
1621
1660
  });
@@ -1831,6 +1870,9 @@ class MEventoAsync extends MEvento {
1831
1870
  if (ret instanceof BreakBranch) {
1832
1871
  break;
1833
1872
  }
1873
+ if (ret instanceof ContinueAST) {
1874
+ continue;
1875
+ }
1834
1876
  retainer === null || retainer === void 0 ? void 0 : retainer.push(ret);
1835
1877
  }
1836
1878
  return retainer;
@@ -1858,6 +1900,9 @@ class MEventoAsync extends MEvento {
1858
1900
  if (ret instanceof BreakBranch) {
1859
1901
  break;
1860
1902
  }
1903
+ if (ret instanceof ContinueAST) {
1904
+ continue;
1905
+ }
1861
1906
  retainer === null || retainer === void 0 ? void 0 : retainer.push(ret);
1862
1907
  // update
1863
1908
  if (node.update instanceof LiteralAST && isNum(node.update.value)) {
@@ -1887,6 +1932,9 @@ class MEventoAsync extends MEvento {
1887
1932
  if (ret instanceof BreakBranch) {
1888
1933
  break;
1889
1934
  }
1935
+ if (ret instanceof ContinueAST) {
1936
+ continue;
1937
+ }
1890
1938
  retainer === null || retainer === void 0 ? void 0 : retainer.push(ret);
1891
1939
  }
1892
1940
  return retainer;
@@ -1937,5 +1985,5 @@ class MEventoAsync extends MEvento {
1937
1985
  * Generated bundle index. Do not edit.
1938
1986
  */
1939
1987
 
1940
- 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 };
1941
1989
  //# sourceMappingURL=mevento.mjs.map