bahasa-simpl 1.0.17 → 1.0.19

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.
Files changed (2) hide show
  1. package/dist/simpl.js +35 -4
  2. package/package.json +1 -1
package/dist/simpl.js CHANGED
@@ -259,6 +259,29 @@ 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 tulisFormat tidak mempunyai cukup elemen!");
278
+ }
279
+ finalized += formator.shift();
280
+ }
281
+ }
282
+ return new Value(petikSymbol, finalized);
283
+
284
+ }));
262
285
 
263
286
  return tipe;
264
287
  })();
@@ -513,6 +536,7 @@ const GLOBAL_ENV = (() => {
513
536
  env.define("mesin", MesinTipe);
514
537
 
515
538
  env.define("tulisf", makeBuiltInFunc([null, barisSymbol], null, (v, [d, b]) => {
539
+ // THERES ANOTHER ONE ON PETIK.FORMAT
516
540
  let strTemp = kePetik(v, d);
517
541
  let finalized = "";
518
542
  let formator = b.data.map(value=>kePetik(v, value));
@@ -802,6 +826,10 @@ class Interpreter {
802
826
  visitIndexExpr(indexExpr) {
803
827
  // a real TODO would've been to implement real iterables
804
828
  let iterable = indexExpr.iterable.accept(this);
829
+ if (!iterable || iterable.data === null) {
830
+ this.error("Objek bernilai nihil, tidak dapat mengindeksnya.");
831
+ }
832
+
805
833
  if (iterable.type === petikSymbol) {
806
834
  iterable = new Value(barisSymbol, iterable.data.split("").map(str => new Value(petikSymbol, str)));
807
835
  }
@@ -986,7 +1014,7 @@ class Interpreter {
986
1014
  let opLexeme = TOKEN_STRING[op] + (left ? "" : "_UNER");
987
1015
  let operatorFunc = type.member.get(opLexeme);
988
1016
  if (!operatorFunc)
989
- this.error(`operator ${opLexeme} tidak terdefinisi untuk Model ${right.type.description}.`);
1017
+ this.error(`Operator ${opLexeme} tidak terdefinisi untuk Model ${right.type.description}.`);
990
1018
 
991
1019
  let result = null;
992
1020
  if (left) { // Binary
@@ -1020,19 +1048,22 @@ class Interpreter {
1020
1048
  let willBeCalled = this.exprWillBeCalled;
1021
1049
  this.exprWillBeCalled = false;
1022
1050
  let main = memberExpr.main.accept(this);
1051
+ if (!main || main.data === null) {
1052
+ this.error("Objek bernilai nihil, tidak dapat mengaksesnya.");
1053
+ }
1023
1054
  let name = memberExpr.member.token.lexeme;
1024
1055
  this.line = memberExpr.member.token.line;
1025
1056
  if (!main?.member || !main.member.has(name)) {
1026
1057
  const type = this.environment.get(main.type.description);
1027
1058
  if (!type) {
1028
- this.error(`nama .${name} tidak ditemukan.`);
1059
+ this.error(`Nama .${name} tidak ditemukan.`);
1029
1060
  }
1030
1061
  if (type.member?.has(name)) {
1031
1062
  if (willBeCalled) {
1032
1063
  this.objectStack = main;
1033
1064
  return type.member.get(name);
1034
1065
  }
1035
- this.error(`akses titik . dari objek ke model harus berupa panggilan/penggunaaan mesin.`);
1066
+ this.error(`Akses titik . dari objek ke model harus berupa panggilan/penggunaaan mesin.`);
1036
1067
  }
1037
1068
  this.error(`nama .${name} tidak ditemukan dalam tipe ${main.type.description}`);
1038
1069
  } else {
@@ -1250,7 +1281,7 @@ class Interpreter {
1250
1281
  let match = lihatStmt.expr.accept(this);
1251
1282
  let matchType = this.environment.get(match?.type?.description);
1252
1283
  if (!matchType?.member?.has("SAMA_SAMA")) {
1253
- this.error(`tipe ${matchType ? match.type.description : "nihil"} tidak mempunyai mesin SAMA_SAMA.`);
1284
+ this.error(`Tipe ${matchType ? match.type.description : "nihil"} tidak mempunyai mesin SAMA_SAMA.`);
1254
1285
  }
1255
1286
  let equalFunc = matchType.member.get("SAMA_SAMA");
1256
1287
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bahasa-simpl",
3
- "version": "1.0.17",
3
+ "version": "1.0.19",
4
4
  "description": "Bahasa pemrograman mini berbasis kata bahasa Indonesia",
5
5
  "exports": {
6
6
  ".": {