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.
- package/esm2020/lib/mevento.mjs +78 -27
- package/fesm2015/mevento.mjs +79 -28
- package/fesm2015/mevento.mjs.map +1 -1
- package/fesm2020/mevento.mjs +78 -27
- package/fesm2020/mevento.mjs.map +1 -1
- package/lib/mevento.d.ts +32 -2
- package/package.json +1 -1
package/fesm2020/mevento.mjs
CHANGED
|
@@ -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
|
-
"
|
|
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 (
|
|
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
|
-
|
|
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
|
|
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 {
|
|
@@ -1198,19 +1218,8 @@ class ANodeVisitor {
|
|
|
1198
1218
|
}
|
|
1199
1219
|
}
|
|
1200
1220
|
class NodeVisitor extends ANodeVisitor {
|
|
1201
|
-
visit(node) {
|
|
1202
|
-
const methodName = `visit${node.constructor.name}`;
|
|
1203
|
-
// const fn = Object.getPrototypeOf(this)[methodName];
|
|
1204
|
-
const fn = this._nodesVisitors[methodName];
|
|
1205
|
-
return fn?.call(this, node);
|
|
1206
|
-
}
|
|
1207
|
-
}
|
|
1208
|
-
class MEvento extends NodeVisitor {
|
|
1209
1221
|
constructor() {
|
|
1210
1222
|
super();
|
|
1211
|
-
this._memory = {};
|
|
1212
|
-
this.debug = false;
|
|
1213
|
-
this._functionsRegistry = {};
|
|
1214
1223
|
this.registerVisitor(RootAST, this.visitRootAST);
|
|
1215
1224
|
this.registerVisitor(BlockStatementAST, this.visitBlockStatementAST);
|
|
1216
1225
|
this.registerVisitor(IdentifierAST, this.visitIdentifierAST);
|
|
@@ -1230,6 +1239,30 @@ class MEvento extends NodeVisitor {
|
|
|
1230
1239
|
this.registerVisitor(ForLoopStatement, this.visitForLoopStatement);
|
|
1231
1240
|
this.registerVisitor(ForOfStatement, this.visitForOfStatement);
|
|
1232
1241
|
this.registerVisitor(BreakAST, this.visitBreakAST);
|
|
1242
|
+
this.registerVisitor(ContinueAST, this.visitContinueAST);
|
|
1243
|
+
}
|
|
1244
|
+
visit(node) {
|
|
1245
|
+
const methodName = `visit${node.constructor.name}`;
|
|
1246
|
+
// const fn = Object.getPrototypeOf(this)[methodName];
|
|
1247
|
+
const fn = this._nodesVisitors[methodName];
|
|
1248
|
+
return fn?.call(this, node);
|
|
1249
|
+
}
|
|
1250
|
+
assignProperty(owner, property, value) {
|
|
1251
|
+
if (Array.isArray(owner)) {
|
|
1252
|
+
owner[property] = value;
|
|
1253
|
+
}
|
|
1254
|
+
else if (typeof owner === 'object') {
|
|
1255
|
+
owner[property] = value;
|
|
1256
|
+
}
|
|
1257
|
+
else { }
|
|
1258
|
+
}
|
|
1259
|
+
}
|
|
1260
|
+
class MEvento extends NodeVisitor {
|
|
1261
|
+
constructor() {
|
|
1262
|
+
super();
|
|
1263
|
+
this._memory = {};
|
|
1264
|
+
this.debug = false;
|
|
1265
|
+
this._functionsRegistry = {};
|
|
1233
1266
|
this._functionsRegistry = { ...MEvento._globalFunctionsRegistry };
|
|
1234
1267
|
}
|
|
1235
1268
|
log(message) {
|
|
@@ -1250,6 +1283,9 @@ class MEvento extends NodeVisitor {
|
|
|
1250
1283
|
let last;
|
|
1251
1284
|
for (const n of list) {
|
|
1252
1285
|
last = this.visit(n);
|
|
1286
|
+
if (last instanceof LoopControl) {
|
|
1287
|
+
return last;
|
|
1288
|
+
}
|
|
1253
1289
|
}
|
|
1254
1290
|
return last;
|
|
1255
1291
|
}
|
|
@@ -1277,15 +1313,6 @@ class MEvento extends NodeVisitor {
|
|
|
1277
1313
|
}
|
|
1278
1314
|
return value;
|
|
1279
1315
|
}
|
|
1280
|
-
assignProperty(owner, property, value) {
|
|
1281
|
-
if (Array.isArray(owner)) {
|
|
1282
|
-
owner[property] = value;
|
|
1283
|
-
}
|
|
1284
|
-
else if (typeof owner === 'object') {
|
|
1285
|
-
owner[property] = value;
|
|
1286
|
-
}
|
|
1287
|
-
else { }
|
|
1288
|
-
}
|
|
1289
1316
|
visitExpressionStatementAST(node) {
|
|
1290
1317
|
const expr = node.expression;
|
|
1291
1318
|
return this.visit(expr);
|
|
@@ -1452,6 +1479,9 @@ class MEvento extends NodeVisitor {
|
|
|
1452
1479
|
if (ret instanceof BreakBranch) {
|
|
1453
1480
|
break;
|
|
1454
1481
|
}
|
|
1482
|
+
if (ret instanceof ContinueAST) {
|
|
1483
|
+
continue;
|
|
1484
|
+
}
|
|
1455
1485
|
retainer?.push(ret);
|
|
1456
1486
|
}
|
|
1457
1487
|
return retainer || null;
|
|
@@ -1477,6 +1507,9 @@ class MEvento extends NodeVisitor {
|
|
|
1477
1507
|
if (ret instanceof BreakBranch) {
|
|
1478
1508
|
break;
|
|
1479
1509
|
}
|
|
1510
|
+
if (ret instanceof ContinueAST) {
|
|
1511
|
+
continue;
|
|
1512
|
+
}
|
|
1480
1513
|
retainer?.push(ret);
|
|
1481
1514
|
// update
|
|
1482
1515
|
if (node.update instanceof LiteralAST && isNum(node.update.value)) {
|
|
@@ -1504,10 +1537,16 @@ class MEvento extends NodeVisitor {
|
|
|
1504
1537
|
if (ret instanceof BreakBranch) {
|
|
1505
1538
|
break;
|
|
1506
1539
|
}
|
|
1540
|
+
if (ret instanceof ContinueAST) {
|
|
1541
|
+
continue;
|
|
1542
|
+
}
|
|
1507
1543
|
retainer?.push(ret);
|
|
1508
1544
|
}
|
|
1509
1545
|
return retainer || null;
|
|
1510
1546
|
}
|
|
1547
|
+
visitContinueAST(node) {
|
|
1548
|
+
return new ContinueBranch();
|
|
1549
|
+
}
|
|
1511
1550
|
_declareForIdentifier(node, value) {
|
|
1512
1551
|
if (node instanceof TupleExpression) {
|
|
1513
1552
|
if (!Array.isArray(value)) {
|
|
@@ -1598,6 +1637,9 @@ class MEventoAsync extends MEvento {
|
|
|
1598
1637
|
let last;
|
|
1599
1638
|
for (const n of list) {
|
|
1600
1639
|
last = await this.visit(n);
|
|
1640
|
+
if (last instanceof LoopControl) {
|
|
1641
|
+
return last;
|
|
1642
|
+
}
|
|
1601
1643
|
}
|
|
1602
1644
|
return last;
|
|
1603
1645
|
}
|
|
@@ -1785,6 +1827,9 @@ class MEventoAsync extends MEvento {
|
|
|
1785
1827
|
if (ret instanceof BreakBranch) {
|
|
1786
1828
|
break;
|
|
1787
1829
|
}
|
|
1830
|
+
if (ret instanceof ContinueAST) {
|
|
1831
|
+
continue;
|
|
1832
|
+
}
|
|
1788
1833
|
retainer?.push(ret);
|
|
1789
1834
|
}
|
|
1790
1835
|
return retainer;
|
|
@@ -1810,6 +1855,9 @@ class MEventoAsync extends MEvento {
|
|
|
1810
1855
|
if (ret instanceof BreakBranch) {
|
|
1811
1856
|
break;
|
|
1812
1857
|
}
|
|
1858
|
+
if (ret instanceof ContinueAST) {
|
|
1859
|
+
continue;
|
|
1860
|
+
}
|
|
1813
1861
|
retainer?.push(ret);
|
|
1814
1862
|
// update
|
|
1815
1863
|
if (node.update instanceof LiteralAST && isNum(node.update.value)) {
|
|
@@ -1837,6 +1885,9 @@ class MEventoAsync extends MEvento {
|
|
|
1837
1885
|
if (ret instanceof BreakBranch) {
|
|
1838
1886
|
break;
|
|
1839
1887
|
}
|
|
1888
|
+
if (ret instanceof ContinueAST) {
|
|
1889
|
+
continue;
|
|
1890
|
+
}
|
|
1840
1891
|
retainer?.push(ret);
|
|
1841
1892
|
}
|
|
1842
1893
|
return retainer;
|
|
@@ -1880,5 +1931,5 @@ class MEventoAsync extends MEvento {
|
|
|
1880
1931
|
* Generated bundle index. Do not edit.
|
|
1881
1932
|
*/
|
|
1882
1933
|
|
|
1883
|
-
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 };
|
|
1884
1935
|
//# sourceMappingURL=mevento.mjs.map
|