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.
@@ -77,6 +77,7 @@ TokenType.with = 39;
77
77
  TokenType.in = 40;
78
78
  TokenType.TILL = 41;
79
79
  TokenType.BREAK = 42;
80
+ TokenType.CONTINUE = 43;
80
81
  class Token {
81
82
  constructor(type, value, line = 1, col = 1) {
82
83
  this.type = type;
@@ -488,6 +489,7 @@ Lexer._defaultLanguage = new LexerDictionary("en", {
488
489
  "till": "till",
489
490
  "in": "in",
490
491
  "break": "break",
492
+ "continue": "continue",
491
493
  });
492
494
  Lexer.languages = [
493
495
  Lexer._defaultLanguage,
@@ -500,11 +502,12 @@ Lexer.languages = [
500
502
  "tanque": "while",
501
503
  "pour": "for",
502
504
  "avec": "with",
503
- "mon": "up",
505
+ "mont": "up",
504
506
  "desc": "down",
505
507
  "jusqua": "till",
506
508
  "dans": "in",
507
509
  "couper": "break",
510
+ "continuer": "continue",
508
511
  }),
509
512
  new LexerDictionary("bm", {
510
513
  "nii": "if",
@@ -520,6 +523,7 @@ Lexer.languages = [
520
523
  "kata": "till",
521
524
  "kono": "in",
522
525
  "tike": "break",
526
+ "ipan": "continue",
523
527
  }),
524
528
  ];
525
529
  Lexer.RESERVED = {
@@ -536,6 +540,7 @@ Lexer.RESERVED = {
536
540
  "till": Token.from(TokenType.TILL, "till"),
537
541
  "in": Token.from(TokenType.in, "in"),
538
542
  "break": Token.from(TokenType.BREAK, "break"),
543
+ "continue": Token.from(TokenType.CONTINUE, "continue"),
539
544
  };
540
545
  /**
541
546
  * Parser
@@ -742,6 +747,11 @@ class BreakAST extends AST {
742
747
  super(line, col);
743
748
  }
744
749
  }
750
+ class ContinueAST extends AST {
751
+ constructor(line, col) {
752
+ super(line, col);
753
+ }
754
+ }
745
755
  class Parser {
746
756
  constructor(lexer) {
747
757
  this.currentToken = lexer.nextToken();
@@ -976,8 +986,7 @@ class Parser {
976
986
  }
977
987
  // const body = _statements();
978
988
  const body = [this._statement()];
979
- while (this.currentToken.type === TokenType.eol ||
980
- this.currentToken.type === TokenType.semi) {
989
+ while (true) {
981
990
  this._eatSemiOrEOL();
982
991
  if (this.currentToken.type === TokenType.rbrace || this.currentToken.type === TokenType.eof) {
983
992
  // _eat(this.currentToken!.type);
@@ -1041,7 +1050,6 @@ class Parser {
1041
1050
  return new WhileLoopStatement(test, body, token, this.currentToken);
1042
1051
  }
1043
1052
  _forOfIdentifier() {
1044
- let node;
1045
1053
  switch (this.currentToken.type) {
1046
1054
  case TokenType.lparen: {
1047
1055
  // probable tuple
@@ -1121,6 +1129,9 @@ class Parser {
1121
1129
  case TokenType.BREAK:
1122
1130
  this._eat(TokenType.BREAK);
1123
1131
  return new BreakAST(this.currentToken?.line, this.currentToken?.col);
1132
+ case TokenType.CONTINUE:
1133
+ this._eat(TokenType.CONTINUE);
1134
+ return new ContinueAST(this.currentToken?.line, this.currentToken?.col);
1124
1135
  case TokenType.semi:
1125
1136
  this._eatSemi();
1126
1137
  return this._statement();
@@ -1152,7 +1163,12 @@ class Parser {
1152
1163
  this._eat(TokenType.eof);
1153
1164
  break;
1154
1165
  }
1155
- results.push(this._statement());
1166
+ if (this.currentToken.type === TokenType.lbrace) {
1167
+ results.push(this._blockStatement());
1168
+ }
1169
+ else {
1170
+ results.push(this._statement());
1171
+ }
1156
1172
  // if (this.currentToken!.type !== TokenType.eol &&
1157
1173
  // this.currentToken!.type !== TokenType.semi &&
1158
1174
  // this.currentToken!.type !== TokenType.eof) {
@@ -1184,7 +1200,11 @@ Parser._binopPrecdences = {
1184
1200
  [TokenType.div]: 40,
1185
1201
  [TokenType.mod]: 40,
1186
1202
  };
1187
- class BreakBranch {
1203
+ class LoopControl {
1204
+ }
1205
+ class BreakBranch extends LoopControl {
1206
+ }
1207
+ class ContinueBranch extends LoopControl {
1188
1208
  }
1189
1209
  // AST Wallker
1190
1210
  class ANodeVisitor {
@@ -1219,6 +1239,7 @@ class NodeVisitor extends ANodeVisitor {
1219
1239
  this.registerVisitor(ForLoopStatement, this.visitForLoopStatement);
1220
1240
  this.registerVisitor(ForOfStatement, this.visitForOfStatement);
1221
1241
  this.registerVisitor(BreakAST, this.visitBreakAST);
1242
+ this.registerVisitor(ContinueAST, this.visitContinueAST);
1222
1243
  }
1223
1244
  visit(node) {
1224
1245
  const methodName = `visit${node.constructor.name}`;
@@ -1262,6 +1283,9 @@ class MEvento extends NodeVisitor {
1262
1283
  let last;
1263
1284
  for (const n of list) {
1264
1285
  last = this.visit(n);
1286
+ if (last instanceof LoopControl) {
1287
+ return last;
1288
+ }
1265
1289
  }
1266
1290
  return last;
1267
1291
  }
@@ -1455,6 +1479,9 @@ class MEvento extends NodeVisitor {
1455
1479
  if (ret instanceof BreakBranch) {
1456
1480
  break;
1457
1481
  }
1482
+ if (ret instanceof ContinueAST) {
1483
+ continue;
1484
+ }
1458
1485
  retainer?.push(ret);
1459
1486
  }
1460
1487
  return retainer || null;
@@ -1480,6 +1507,9 @@ class MEvento extends NodeVisitor {
1480
1507
  if (ret instanceof BreakBranch) {
1481
1508
  break;
1482
1509
  }
1510
+ if (ret instanceof ContinueAST) {
1511
+ continue;
1512
+ }
1483
1513
  retainer?.push(ret);
1484
1514
  // update
1485
1515
  if (node.update instanceof LiteralAST && isNum(node.update.value)) {
@@ -1507,10 +1537,16 @@ class MEvento extends NodeVisitor {
1507
1537
  if (ret instanceof BreakBranch) {
1508
1538
  break;
1509
1539
  }
1540
+ if (ret instanceof ContinueAST) {
1541
+ continue;
1542
+ }
1510
1543
  retainer?.push(ret);
1511
1544
  }
1512
1545
  return retainer || null;
1513
1546
  }
1547
+ visitContinueAST(node) {
1548
+ return new ContinueBranch();
1549
+ }
1514
1550
  _declareForIdentifier(node, value) {
1515
1551
  if (node instanceof TupleExpression) {
1516
1552
  if (!Array.isArray(value)) {
@@ -1601,6 +1637,9 @@ class MEventoAsync extends MEvento {
1601
1637
  let last;
1602
1638
  for (const n of list) {
1603
1639
  last = await this.visit(n);
1640
+ if (last instanceof LoopControl) {
1641
+ return last;
1642
+ }
1604
1643
  }
1605
1644
  return last;
1606
1645
  }
@@ -1788,6 +1827,9 @@ class MEventoAsync extends MEvento {
1788
1827
  if (ret instanceof BreakBranch) {
1789
1828
  break;
1790
1829
  }
1830
+ if (ret instanceof ContinueAST) {
1831
+ continue;
1832
+ }
1791
1833
  retainer?.push(ret);
1792
1834
  }
1793
1835
  return retainer;
@@ -1813,6 +1855,9 @@ class MEventoAsync extends MEvento {
1813
1855
  if (ret instanceof BreakBranch) {
1814
1856
  break;
1815
1857
  }
1858
+ if (ret instanceof ContinueAST) {
1859
+ continue;
1860
+ }
1816
1861
  retainer?.push(ret);
1817
1862
  // update
1818
1863
  if (node.update instanceof LiteralAST && isNum(node.update.value)) {
@@ -1840,6 +1885,9 @@ class MEventoAsync extends MEvento {
1840
1885
  if (ret instanceof BreakBranch) {
1841
1886
  break;
1842
1887
  }
1888
+ if (ret instanceof ContinueAST) {
1889
+ continue;
1890
+ }
1843
1891
  retainer?.push(ret);
1844
1892
  }
1845
1893
  return retainer;
@@ -1883,5 +1931,5 @@ class MEventoAsync extends MEvento {
1883
1931
  * Generated bundle index. Do not edit.
1884
1932
  */
1885
1933
 
1886
- 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 };
1934
+ 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 };
1887
1935
  //# sourceMappingURL=mevento.mjs.map