bahasa-simpl 1.0.18 → 1.0.20
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/dist/simpl.js +42 -5
- package/package.json +1 -1
package/dist/simpl.js
CHANGED
|
@@ -259,6 +259,32 @@ const PetikTipe = (() => {
|
|
|
259
259
|
tipe.member.define("kecil", makeBuiltInFunc([petikSymbol], petikSymbol, (_, [p]) => {
|
|
260
260
|
return new Value(petikSymbol, p.data.toLowerCase())
|
|
261
261
|
}));
|
|
262
|
+
tipe.member.define("format", makeBuiltInFunc([petikSymbol, barisSymbol], petikSymbol, (v, [p, b]) => {
|
|
263
|
+
// THERES ANOTHER ONE ON TULISF MESIN GLOBAL
|
|
264
|
+
let strTemp = p.data;
|
|
265
|
+
let finalized = "";
|
|
266
|
+
let formator = b.data.map(value=>kePetik(v, value));
|
|
267
|
+
|
|
268
|
+
for (let i = 0; i < strTemp.length; i++) {
|
|
269
|
+
let ch = strTemp[i];
|
|
270
|
+
if ( ch !== "{") finalized += ch;
|
|
271
|
+
else {
|
|
272
|
+
if (i+1 < strTemp.length && strTemp[i+1] !== "}") {
|
|
273
|
+
finalized += "{"; continue;
|
|
274
|
+
}
|
|
275
|
+
i++;
|
|
276
|
+
if (formator.length === 0) {
|
|
277
|
+
v.error("Baris dalam format tidak mempunyai cukup elemen.");
|
|
278
|
+
}
|
|
279
|
+
finalized += formator.shift();
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
if (formator.length !== 0) {
|
|
283
|
+
v.error("Baris dalam format mempunyai terlalu banyak elemen.");
|
|
284
|
+
}
|
|
285
|
+
return new Value(petikSymbol, finalized);
|
|
286
|
+
|
|
287
|
+
}));
|
|
262
288
|
|
|
263
289
|
return tipe;
|
|
264
290
|
})();
|
|
@@ -513,6 +539,7 @@ const GLOBAL_ENV = (() => {
|
|
|
513
539
|
env.define("mesin", MesinTipe);
|
|
514
540
|
|
|
515
541
|
env.define("tulisf", makeBuiltInFunc([null, barisSymbol], null, (v, [d, b]) => {
|
|
542
|
+
// THERES ANOTHER ONE ON PETIK.FORMAT
|
|
516
543
|
let strTemp = kePetik(v, d);
|
|
517
544
|
let finalized = "";
|
|
518
545
|
let formator = b.data.map(value=>kePetik(v, value));
|
|
@@ -526,11 +553,14 @@ const GLOBAL_ENV = (() => {
|
|
|
526
553
|
}
|
|
527
554
|
i++;
|
|
528
555
|
if (formator.length === 0) {
|
|
529
|
-
v.error("Baris dalam
|
|
556
|
+
v.error("Baris dalam tulisf tidak mempunyai cukup elemen.");
|
|
530
557
|
}
|
|
531
558
|
finalized += formator.shift();
|
|
532
559
|
}
|
|
533
560
|
}
|
|
561
|
+
if (formator.length !== 0) {
|
|
562
|
+
v.error("Baris dalam tulisf mempunyai terlalu banyak elemen.");
|
|
563
|
+
}
|
|
534
564
|
v.output.push(finalized);
|
|
535
565
|
return d;
|
|
536
566
|
}));
|
|
@@ -802,6 +832,10 @@ class Interpreter {
|
|
|
802
832
|
visitIndexExpr(indexExpr) {
|
|
803
833
|
// a real TODO would've been to implement real iterables
|
|
804
834
|
let iterable = indexExpr.iterable.accept(this);
|
|
835
|
+
if (!iterable || iterable.data === null) {
|
|
836
|
+
this.error("Objek bernilai nihil, tidak dapat mengindeksnya.");
|
|
837
|
+
}
|
|
838
|
+
|
|
805
839
|
if (iterable.type === petikSymbol) {
|
|
806
840
|
iterable = new Value(barisSymbol, iterable.data.split("").map(str => new Value(petikSymbol, str)));
|
|
807
841
|
}
|
|
@@ -986,7 +1020,7 @@ class Interpreter {
|
|
|
986
1020
|
let opLexeme = TOKEN_STRING[op] + (left ? "" : "_UNER");
|
|
987
1021
|
let operatorFunc = type.member.get(opLexeme);
|
|
988
1022
|
if (!operatorFunc)
|
|
989
|
-
this.error(`
|
|
1023
|
+
this.error(`Operator ${opLexeme} tidak terdefinisi untuk Model ${right.type.description}.`);
|
|
990
1024
|
|
|
991
1025
|
let result = null;
|
|
992
1026
|
if (left) { // Binary
|
|
@@ -1020,19 +1054,22 @@ class Interpreter {
|
|
|
1020
1054
|
let willBeCalled = this.exprWillBeCalled;
|
|
1021
1055
|
this.exprWillBeCalled = false;
|
|
1022
1056
|
let main = memberExpr.main.accept(this);
|
|
1057
|
+
if (!main || main.data === null) {
|
|
1058
|
+
this.error("Objek bernilai nihil, tidak dapat mengaksesnya.");
|
|
1059
|
+
}
|
|
1023
1060
|
let name = memberExpr.member.token.lexeme;
|
|
1024
1061
|
this.line = memberExpr.member.token.line;
|
|
1025
1062
|
if (!main?.member || !main.member.has(name)) {
|
|
1026
1063
|
const type = this.environment.get(main.type.description);
|
|
1027
1064
|
if (!type) {
|
|
1028
|
-
this.error(`
|
|
1065
|
+
this.error(`Nama .${name} tidak ditemukan.`);
|
|
1029
1066
|
}
|
|
1030
1067
|
if (type.member?.has(name)) {
|
|
1031
1068
|
if (willBeCalled) {
|
|
1032
1069
|
this.objectStack = main;
|
|
1033
1070
|
return type.member.get(name);
|
|
1034
1071
|
}
|
|
1035
|
-
this.error(`
|
|
1072
|
+
this.error(`Akses titik . dari objek ke model harus berupa panggilan/penggunaaan mesin.`);
|
|
1036
1073
|
}
|
|
1037
1074
|
this.error(`nama .${name} tidak ditemukan dalam tipe ${main.type.description}`);
|
|
1038
1075
|
} else {
|
|
@@ -1250,7 +1287,7 @@ class Interpreter {
|
|
|
1250
1287
|
let match = lihatStmt.expr.accept(this);
|
|
1251
1288
|
let matchType = this.environment.get(match?.type?.description);
|
|
1252
1289
|
if (!matchType?.member?.has("SAMA_SAMA")) {
|
|
1253
|
-
this.error(`
|
|
1290
|
+
this.error(`Tipe ${matchType ? match.type.description : "nihil"} tidak mempunyai mesin SAMA_SAMA.`);
|
|
1254
1291
|
}
|
|
1255
1292
|
let equalFunc = matchType.member.get("SAMA_SAMA");
|
|
1256
1293
|
|