@graffiticode/basis 1.5.13 → 1.5.14
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/package.json +1 -1
- package/src/compiler.js +110 -7
package/package.json
CHANGED
package/src/compiler.js
CHANGED
|
@@ -186,6 +186,15 @@ export class Checker extends Visitor {
|
|
|
186
186
|
});
|
|
187
187
|
});
|
|
188
188
|
}
|
|
189
|
+
GET(node, options, resume) {
|
|
190
|
+
this.visit(node.elts[0], options, (err1, val1) => {
|
|
191
|
+
this.visit(node.elts[1], options, (err2, val2) => {
|
|
192
|
+
const err = [].concat(err1).concat(err2);
|
|
193
|
+
const val = node;
|
|
194
|
+
resume(err, val);
|
|
195
|
+
});
|
|
196
|
+
});
|
|
197
|
+
}
|
|
189
198
|
LT(node, options, resume) {
|
|
190
199
|
this.visit(node.elts[0], options, (err1, val1) => {
|
|
191
200
|
this.visit(node.elts[1], options, (err2, val2) => {
|
|
@@ -309,6 +318,42 @@ export class Checker extends Visitor {
|
|
|
309
318
|
const val = node;
|
|
310
319
|
resume(err, val);
|
|
311
320
|
}
|
|
321
|
+
GT(node, options, resume) {
|
|
322
|
+
this.visit(node.elts[0], options, (err1, val1) => {
|
|
323
|
+
this.visit(node.elts[1], options, (err2, val2) => {
|
|
324
|
+
const err = [].concat(err1).concat(err2);
|
|
325
|
+
const val = node;
|
|
326
|
+
resume(err, val);
|
|
327
|
+
});
|
|
328
|
+
});
|
|
329
|
+
}
|
|
330
|
+
GE(node, options, resume) {
|
|
331
|
+
this.visit(node.elts[0], options, (err1, val1) => {
|
|
332
|
+
this.visit(node.elts[1], options, (err2, val2) => {
|
|
333
|
+
const err = [].concat(err1).concat(err2);
|
|
334
|
+
const val = node;
|
|
335
|
+
resume(err, val);
|
|
336
|
+
});
|
|
337
|
+
});
|
|
338
|
+
}
|
|
339
|
+
LE(node, options, resume) {
|
|
340
|
+
this.visit(node.elts[0], options, (err1, val1) => {
|
|
341
|
+
this.visit(node.elts[1], options, (err2, val2) => {
|
|
342
|
+
const err = [].concat(err1).concat(err2);
|
|
343
|
+
const val = node;
|
|
344
|
+
resume(err, val);
|
|
345
|
+
});
|
|
346
|
+
});
|
|
347
|
+
}
|
|
348
|
+
NE(node, options, resume) {
|
|
349
|
+
this.visit(node.elts[0], options, (err1, val1) => {
|
|
350
|
+
this.visit(node.elts[1], options, (err2, val2) => {
|
|
351
|
+
const err = [].concat(err1).concat(err2);
|
|
352
|
+
const val = node;
|
|
353
|
+
resume(err, val);
|
|
354
|
+
});
|
|
355
|
+
});
|
|
356
|
+
}
|
|
312
357
|
RANGE(node, options, resume) {
|
|
313
358
|
this.visit(node.elts[0], options, (err1, val1) => {
|
|
314
359
|
this.visit(node.elts[1], options, (err2, val2) => {
|
|
@@ -849,13 +894,19 @@ export class Transformer extends Visitor {
|
|
|
849
894
|
// FIXME this isn't ASYNC compatible
|
|
850
895
|
options.SYNC = true;
|
|
851
896
|
this.visit(node.elts[0], options, (e0, v0) => {
|
|
852
|
-
const
|
|
897
|
+
const type = typeof v0;
|
|
898
|
+
const val = `${v0}`;
|
|
899
|
+
console.log(
|
|
900
|
+
"CASE",
|
|
901
|
+
"type=" + type,
|
|
902
|
+
"val=" + val,
|
|
903
|
+
);
|
|
853
904
|
const expr = (
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
tag:
|
|
858
|
-
|
|
905
|
+
val === null && {tag: "NUL", elts: []} ||
|
|
906
|
+
type === "boolean" && {tag: "BOOL", elts: [val]} ||
|
|
907
|
+
type === "number" && {tag: "NUM", elts: [val]} ||
|
|
908
|
+
{tag: "STR", elts: [val]}
|
|
909
|
+
);
|
|
859
910
|
let foundMatch = false;
|
|
860
911
|
const patterns = [];
|
|
861
912
|
for (var i = 1; i < node.elts.length; i++) {
|
|
@@ -910,7 +961,7 @@ export class Transformer extends Visitor {
|
|
|
910
961
|
this.visit(node.elts[0], options, (e0, v0) => {
|
|
911
962
|
this.visit(node.elts[1], options, (e1, v1) => {
|
|
912
963
|
const err = [...e0, ...e1];
|
|
913
|
-
assert(typeof v0 === "object", "Type Error: expected v0 to be an object.");
|
|
964
|
+
assert(typeof v0 === "object", "Type Error: expected v0 to be an object. Got " + JSON.stringify(v0));
|
|
914
965
|
assert(typeof v1 === "string", "Type Error: expected v1 to be a string.");
|
|
915
966
|
const val = v0[v1];
|
|
916
967
|
resume(err, val);
|
|
@@ -966,6 +1017,58 @@ export class Transformer extends Visitor {
|
|
|
966
1017
|
});
|
|
967
1018
|
});
|
|
968
1019
|
}
|
|
1020
|
+
GT(node, options, resume) {
|
|
1021
|
+
this.visit(node.elts[0], options, (e0, v0) => {
|
|
1022
|
+
this.visit(node.elts[1], options, (e1, v1) => {
|
|
1023
|
+
const err = [].concat(e0).concat(e1);
|
|
1024
|
+
try {
|
|
1025
|
+
const val = new Decimal(v0).greaterThan(new Decimal(v1));
|
|
1026
|
+
resume(err, val);
|
|
1027
|
+
} catch (e) {
|
|
1028
|
+
resume([...err, `Error in GT operation: ${e.message}`], false);
|
|
1029
|
+
}
|
|
1030
|
+
});
|
|
1031
|
+
});
|
|
1032
|
+
}
|
|
1033
|
+
GE(node, options, resume) {
|
|
1034
|
+
this.visit(node.elts[0], options, (e0, v0) => {
|
|
1035
|
+
this.visit(node.elts[1], options, (e1, v1) => {
|
|
1036
|
+
const err = [].concat(e0).concat(e1);
|
|
1037
|
+
try {
|
|
1038
|
+
const val = new Decimal(v0).greaterThanOrEqualTo(new Decimal(v1));
|
|
1039
|
+
resume(err, val);
|
|
1040
|
+
} catch (e) {
|
|
1041
|
+
resume([...err, `Error in GE operation: ${e.message}`], false);
|
|
1042
|
+
}
|
|
1043
|
+
});
|
|
1044
|
+
});
|
|
1045
|
+
}
|
|
1046
|
+
LE(node, options, resume) {
|
|
1047
|
+
this.visit(node.elts[0], options, (e0, v0) => {
|
|
1048
|
+
this.visit(node.elts[1], options, (e1, v1) => {
|
|
1049
|
+
const err = [].concat(e0).concat(e1);
|
|
1050
|
+
try {
|
|
1051
|
+
const val = new Decimal(v0).lessThanOrEqualTo(new Decimal(v1));
|
|
1052
|
+
resume(err, val);
|
|
1053
|
+
} catch (e) {
|
|
1054
|
+
resume([...err, `Error in LE operation: ${e.message}`], false);
|
|
1055
|
+
}
|
|
1056
|
+
});
|
|
1057
|
+
});
|
|
1058
|
+
}
|
|
1059
|
+
NE(node, options, resume) {
|
|
1060
|
+
this.visit(node.elts[0], options, (e0, v0) => {
|
|
1061
|
+
this.visit(node.elts[1], options, (e1, v1) => {
|
|
1062
|
+
const err = [].concat(e0).concat(e1);
|
|
1063
|
+
try {
|
|
1064
|
+
const val = !new Decimal(v0).equals(new Decimal(v1));
|
|
1065
|
+
resume(err, val);
|
|
1066
|
+
} catch (e) {
|
|
1067
|
+
resume([...err, `Error in NE operation: ${e.message}`], false);
|
|
1068
|
+
}
|
|
1069
|
+
});
|
|
1070
|
+
});
|
|
1071
|
+
}
|
|
969
1072
|
RANGE(node, options, resume) {
|
|
970
1073
|
this.visit(node.elts[0], options, (e0, v0) => {
|
|
971
1074
|
this.visit(node.elts[1], options, (e1, v1) => {
|