mhs-lang 2.2.3 → 2.3.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.
Files changed (44) hide show
  1. package/README.md +19 -5
  2. package/assets/mhs-file-icons.vsix +0 -0
  3. package/bin/mhs.js +4 -3
  4. package/examples/__pycache__/alat_py.cpython-312.pyc +0 -0
  5. package/examples/tes_modul_baru.mhs +44 -0
  6. package/package.json +1 -1
  7. package/src/index.js +14 -7
  8. package/src/language_server.js +12 -2
  9. package/src/modules/antrian.js +37 -0
  10. package/src/modules/arsip.js +31 -0
  11. package/src/modules/basis_data.js +47 -0
  12. package/src/modules/index.js +18 -0
  13. package/src/modules/iterasi.js +136 -0
  14. package/src/modules/jalur.js +77 -0
  15. package/src/modules/proses.js +43 -0
  16. package/src/modules/statistika.js +79 -0
  17. package/src/modules/tabel.js +83 -0
  18. package/src/py_modules/__pycache__/antrian.cpython-312.pyc +0 -0
  19. package/src/py_modules/__pycache__/basis_data.cpython-312.pyc +0 -0
  20. package/src/py_modules/__pycache__/berkas.cpython-312.pyc +0 -0
  21. package/src/py_modules/__pycache__/data_json.cpython-312.pyc +0 -0
  22. package/src/py_modules/__pycache__/iterasi.cpython-312.pyc +0 -0
  23. package/src/py_modules/__pycache__/jalur.cpython-312.pyc +0 -0
  24. package/src/py_modules/__pycache__/jaringan.cpython-312.pyc +0 -0
  25. package/src/py_modules/__pycache__/koleksi.cpython-312.pyc +0 -0
  26. package/src/py_modules/__pycache__/kripto.cpython-312.pyc +0 -0
  27. package/src/py_modules/__pycache__/matematika.cpython-312.pyc +0 -0
  28. package/src/py_modules/__pycache__/modul_acak.cpython-312.pyc +0 -0
  29. package/src/py_modules/__pycache__/pola.cpython-312.pyc +0 -0
  30. package/src/py_modules/__pycache__/sistem.cpython-312.pyc +0 -0
  31. package/src/py_modules/__pycache__/statistika.cpython-312.pyc +0 -0
  32. package/src/py_modules/__pycache__/uji.cpython-312.pyc +0 -0
  33. package/src/py_modules/__pycache__/waktu.cpython-312.pyc +0 -0
  34. package/src/py_modules/antrian.py +20 -0
  35. package/src/py_modules/arsip.py +37 -0
  36. package/src/py_modules/basis_data.py +29 -0
  37. package/src/py_modules/iterasi.py +37 -0
  38. package/src/py_modules/jalur.py +47 -0
  39. package/src/py_modules/proses.py +35 -0
  40. package/src/py_modules/statistika.py +29 -0
  41. package/src/py_modules/tabel.py +29 -0
  42. package/src/py_transpiler.js +43 -2
  43. package/src/stdlib.js +19 -0
  44. package/src/transpiler.js +1 -1
package/README.md CHANGED
@@ -84,23 +84,31 @@ npm publish --access public
84
84
 
85
85
  ---
86
86
 
87
- ## 2. Daftar 11 Modul Standar Bahasa Indonesia
87
+ ## 2. Daftar 19 Modul Standar Bahasa Indonesia
88
88
 
89
89
  Semua modul berikut dapat langsung diimpor baik di mode Node.js (`mhs`) maupun mode Python 3 Native (`mhs --py`):
90
90
 
91
91
  | Modul `.mhs` | Padanan Python | Fungsi Utama |
92
92
  | :--- | :--- | :--- |
93
93
  | `matematika` | `math` | `pi`, `e`, `akar`, `pangkat`, `sin`, `cos`, `tan`, `log`, `faktorial`, `fpb`, `kpk`, `derajat`, `radian` |
94
- | `modul_acak` | `random` | `bulat`, `desimal`, `pilih`, `sampel`, `kocok` |
94
+ | `modul_acak` / `acak` | `random` | `bulat`, `desimal`, `pilih`, `sampel`, `kocok` |
95
95
  | `waktu` | `time` / `datetime` | `sekarang`, `tidur`, `tanggal_sekarang`, `jam_sekarang`, `info_waktu` |
96
- | `berkas` | `os` / `pathlib` | `baca`, `tulis`, `tambah_isi`, `ada`, `hapus`, `daftar_isi`, `buat_folder`, `gabung_jalur` |
96
+ | `berkas` | `os` / `shutil` | `baca`, `tulis`, `tambah_isi`, `ada`, `hapus`, `daftar_isi`, `buat_folder`, `gabung_jalur` |
97
97
  | `sistem` | `sys` / `platform` | `argumen`, `platform`, `arsitektur`, `lingkungan`, `keluar` |
98
98
  | `data_json` | `json` | `urai`, `ubah_ke_teks`, `baca_berkas`, `tulis_berkas` |
99
99
  | `pola` | `re` | `cocok`, `cari`, `cari_semua`, `ganti`, `pisah` |
100
- | `koleksi` | `collections` / `statistics` | `hitung`, `unik`, `rata_rata`, `median`, `pasangkan`, `kelompokkan` |
100
+ | `koleksi` | `collections` | `hitung`, `unik`, `pasangkan`, `kelompokkan` |
101
101
  | `kripto` | `hashlib` / `base64` | `sha256`, `md5`, `acak_hex`, `encode_base64`, `decode_base64` |
102
- | `jaringan` | `urllib` | `urai_url`, `ambil` |
102
+ | `jaringan` | `urllib` / `requests` | `urai_url`, `ambil` |
103
103
  | `uji` | `unittest` | `sama`, `benar`, `salah`, `lempar_galat`, `ringkasan` |
104
+ | `statistika` | `statistics` | `rata_rata`, `median`, `modus`, `varians`, `deviasi_standar`, `rentang_nilai`, `kuartil` |
105
+ | `iterasi` | `itertools` | `kombinasi`, `permutasi`, `produk`, `rantai`, `akumulasi`, `ulang`, `siklus` |
106
+ | `tabel` / `csv_id` | `csv` | `baca_csv`, `tulis_csv`, `baca_kamus`, `tulis_kamus`, `urai_teks` |
107
+ | `proses` / `subproses` | `subprocess` | `jalankan`, `keluaran`, `sukses` |
108
+ | `jalur` | `pathlib` / `path` | `gabung`, `nama`, `induk`, `ekstensi`, `nama_murni`, `ada`, `ukuran`, `baca_teks` |
109
+ | `arsip` | `shutil` / `zipfile` | `buat_zip`, `ekstrak_zip`, `salin_berkas`, `salin_folder`, `hapus_folder`, `pindah` |
110
+ | `basis_data` | `sqlite3` | `hubungkan`, `eksekusi`, `ambil_semua`, `ambil_satu`, `simpan`, `tutup` |
111
+ | `antrian` | `queue` | `Antrian` (`masukkan`, `ambil`, `ukuran`, `kosong`, `penuh`) |
104
112
 
105
113
  ---
106
114
 
@@ -118,7 +126,13 @@ Semua modul berikut dapat langsung diimpor baik di mode Node.js (`mhs`) maupun m
118
126
  | `import mod as alias` / `from mod import x` | `impor mod sebagai alias` / `dari mod impor x` |
119
127
  | `True` / `False` / `None` | `Benar` / `Salah` / `Kosong` |
120
128
  | `and` / `or` / `not` / `in` | `dan` / `atau` / `bukan` / `dalam` |
129
+ | `not in` / `is not` / `is` | `bukan_dalam` / `bukan_adalah` / `adalah` |
121
130
  | `break` / `continue` / `pass` | `berhenti` / `lanjut` / `lewat` |
131
+ | `with ... as f:` | `dengan ... sebagai f:` |
132
+ | `async def` / `await` | `asinkron fungsi` / `tunggu_eksekusi` |
133
+ | `@property` / `@staticmethod` | `@properti` / `@metode_statis` |
134
+ | `enumerate` / `zip` | `cacah` / `pasangkan` |
135
+ | `all` / `any` / `callable` | `semua` / `ada_yang` / `bisa_dipanggil` |
122
136
  | `[x*2 for x in range(5)]` | `[x*2 untuk x dalam rentang(5)]` |
123
137
 
124
138
  ---
Binary file
package/bin/mhs.js CHANGED
@@ -154,7 +154,7 @@ function main() {
154
154
  console.error(`Kesalahan: Harap sertakan nama file .mhs. Contoh: mhs ${cmd} halo.mhs`);
155
155
  process.exit(1);
156
156
  }
157
- const source = fs.readFileSync(path.resolve(target), 'utf8').replace(/^\uFEFF/, '');
157
+ const source = fs.readFileSync(path.resolve(target), 'utf8').replace(/\uFEFF/g, '');
158
158
  console.log(cmd === '--emit-py' ? transpileToPython(source) : transpile(source));
159
159
  return;
160
160
  }
@@ -166,7 +166,7 @@ function main() {
166
166
  process.exit(1);
167
167
  }
168
168
  try {
169
- runFile(target, { engine: cmd === '--py' ? 'py' : 'node' });
169
+ runFile(target, { engine: cmd === '--py' ? 'py' : 'node', args: args.slice(2) });
170
170
  } catch (err) {
171
171
  console.error(`[MHS Error] ${err.message}`);
172
172
  process.exit(1);
@@ -181,7 +181,8 @@ function main() {
181
181
  }
182
182
 
183
183
  try {
184
- runFile(fileTarget, { engine: 'auto' });
184
+ const extraArgs = cmd === 'run' ? args.slice(2) : args.slice(1);
185
+ runFile(fileTarget, { engine: 'auto', args: extraArgs });
185
186
  } catch (err) {
186
187
  console.error(`[MHS Error] ${err.message}`);
187
188
  process.exit(1);
@@ -0,0 +1,44 @@
1
+ impor statistika
2
+ impor iterasi
3
+ impor jalur
4
+ impor antrian
5
+ impor basis_data
6
+
7
+ # 1. Statistika
8
+ data_angka = [10, 20, 30, 40, 50]
9
+ rata = statistika.rata_rata(data_angka)
10
+ med = statistika.median(data_angka)
11
+ rentang_st = statistika.rentang_nilai(data_angka)
12
+ cetak(f"Stat: rata={rata}, med={med}, rentang={rentang_st}")
13
+
14
+ # 2. Iterasi
15
+ komb = iterasi.kombinasi([1, 2, 3], 2)
16
+ perm = iterasi.permutasi([1, 2], 2)
17
+ cetak(f"Iter: komb={panjang(komb)}, perm={panjang(perm)}")
18
+
19
+ # 3. Jalur
20
+ p = jalur.gabung("folder", "subfolder", "file.txt")
21
+ n = jalur.nama(p)
22
+ e = jalur.ekstensi(p)
23
+ cetak(f"Jalur: nama={n}, ekstensi={e}")
24
+
25
+ # 4. Antrian
26
+ q = antrian.Antrian()
27
+ q.masukkan("A")
28
+ q.masukkan("B")
29
+ item1 = q.ambil()
30
+ cetak(f"Antrian: ambil={item1}, sisa={q.ukuran()}")
31
+
32
+ # 5. Basis Data SQLite
33
+ db = basis_data.hubungkan(":memory:")
34
+ basis_data.eksekusi(db, "CREATE TABLE user (id INTEGER, nama TEXT)")
35
+ basis_data.eksekusi(db, "INSERT INTO user VALUES (1, 'Mahes')")
36
+ rows = basis_data.ambil_semua(db, "SELECT * FROM user")
37
+ cetak(f"DB: baris={panjang(rows)}")
38
+
39
+ # 6. Built-in helpers
40
+ nama_huruf = [karakter(65), karakter(66)]
41
+ angka_huruf = [nilai_karakter('A'), nilai_karakter('B')]
42
+ terpanggil = bisa_dipanggil(statistika.rata_rata)
43
+ salinan = salin([1, 2, 3])
44
+ cetak(f"Builtin: huruf={nama_huruf[0]}, ord={angka_huruf[0]}, callable={terpanggil}, copy={panjang(salinan)}")
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mhs-lang",
3
- "version": "2.2.3",
3
+ "version": "2.3.0",
4
4
  "description": "Bahasa pemrograman Python dalam Bahasa Indonesia (.mhs) dengan dual-engine Node.js + Python 3 native, dukungan impor .mhs, npm, dan modul Python (.py/pip).",
5
5
  "main": "src/index.js",
6
6
  "bin": {
package/src/index.js CHANGED
@@ -123,21 +123,21 @@ function runCode(source, filename = '<mhs>') {
123
123
  return executeMhs(source, filename).result;
124
124
  }
125
125
 
126
- function runFile(filePath, { engine = 'auto' } = {}) {
126
+ function runFile(filePath, { engine = 'auto', args = [] } = {}) {
127
127
  const absPath = path.resolve(filePath);
128
128
  if (!fs.existsSync(absPath)) {
129
129
  throw new Error(`File tidak ditemukan: ${absPath}`);
130
130
  }
131
- const source = fs.readFileSync(absPath, 'utf8').replace(/^\uFEFF/, '');
131
+ const source = fs.readFileSync(absPath, 'utf8').replace(/\uFEFF/g, '');
132
132
 
133
133
  if (engine === 'py' || (engine === 'auto' && hasPython3())) {
134
- return runPyCode(source, absPath);
134
+ return runPyCode(source, absPath, args);
135
135
  }
136
136
  return runCode(source, absPath);
137
137
  }
138
138
 
139
- function runPyCode(source, filename = '<mhs>') {
140
- source = source.replace(/^\uFEFF/, '');
139
+ function runPyCode(source, filename = '<mhs>', args = []) {
140
+ source = source.replace(/\uFEFF/g, '');
141
141
  const absFilename = filename.startsWith('<') ? filename : path.resolve(filename);
142
142
  const baseDir = filename.startsWith('<') ? process.cwd() : path.dirname(absFilename);
143
143
  const pyModulesDir = path.resolve(__dirname, 'py_modules');
@@ -147,7 +147,7 @@ function runPyCode(source, filename = '<mhs>') {
147
147
  if (fs.existsSync(baseDir)) {
148
148
  for (const entry of fs.readdirSync(baseDir)) {
149
149
  if (entry.endsWith('.mhs')) {
150
- const mhsSrc = fs.readFileSync(path.join(baseDir, entry), 'utf8');
150
+ const mhsSrc = fs.readFileSync(path.join(baseDir, entry), 'utf8').replace(/\uFEFF/g, '');
151
151
  const pyOut = transpileToPython(mhsSrc);
152
152
  const pyName = entry.replace(/\.mhs$/i, '.py');
153
153
  fs.writeFileSync(path.join(tmpDir, pyName), pyOut, 'utf8');
@@ -161,7 +161,14 @@ function runPyCode(source, filename = '<mhs>') {
161
161
  ...process.env,
162
162
  PYTHONPATH: [tmpDir, pyModulesDir, baseDir, process.env.PYTHONPATH || ''].filter(Boolean).join(path.delimiter),
163
163
  };
164
- return execFileSync(pythonCmd, ['-c', pyCode], {
164
+
165
+ // Eksekusi berkas temporer untuk menghindari batasan panjang karakter argumen (-c) di Windows
166
+ const entryPyPath = path.join(tmpDir, '__mhs_entry__.py');
167
+ const entryCode = `import sys as _mhs_sys\n_mhs_sys.argv[0] = ${JSON.stringify(absFilename)}\n` + pyCode;
168
+ fs.writeFileSync(entryPyPath, entryCode, 'utf8');
169
+ const execArgs = [entryPyPath, ...args];
170
+
171
+ return execFileSync(pythonCmd, execArgs, {
165
172
  cwd: baseDir,
166
173
  env,
167
174
  stdio: 'inherit',
@@ -28,13 +28,23 @@ const BUILTINS = new Set([
28
28
  'huruf_besar', 'huruf_kecil', 'potong', 'ganti', 'mengandung', 'acak',
29
29
  'akar', 'pangkat', 'mutlak', 'bulatkan', 'bawah', 'atas', 'min_nilai',
30
30
  'maks_nilai', 'jumlah', 'waktu_sekarang', 'tunggu', 'daftar', 'kamus',
31
+ 'himpunan', 'tupel', 'buka', 'cacah', 'pasangkan', 'semua', 'ada_yang',
32
+ 'saring', 'petakan', 'bisa_dipanggil', 'punya_atribut', 'ambil_atribut',
33
+ 'atur_atribut', 'hapus_atribut', 'adalah_turunan', 'turunan_dari',
34
+ 'format_teks', 'teks_biner', 'teks_heksa', 'teks_oktal', 'nilai_karakter',
35
+ 'karakter', 'evaluasi', 'eksekusi', 'daftar_anggota', 'penghitung',
36
+ 'berikutnya', 'keluar', 'salin', 'salin_dalam', 'bekukan',
31
37
  'print', 'input', 'range', 'len', 'str', 'int', 'float', 'list', 'dict',
32
38
  'set', 'tuple', 'enumerate', 'zip', 'sum', 'min', 'max', 'abs', 'round',
39
+ 'all', 'any', 'filter', 'map', 'callable', 'hasattr', 'getattr', 'setattr',
40
+ 'isinstance', 'format', 'ord', 'chr', 'eval', 'exec', 'dir', 'iter', 'next',
33
41
  ]);
34
42
 
35
43
  const MODULES = [
36
- 'matematika', 'modul_acak', 'waktu', 'berkas', 'sistem', 'data_json',
37
- 'pola', 'koleksi', 'kripto', 'jaringan', 'uji',
44
+ 'matematika', 'modul_acak', 'acak', 'waktu', 'berkas', 'sistem', 'data_json',
45
+ 'pola', 'koleksi', 'kripto', 'jaringan', 'uji', 'statistika', 'iterasi',
46
+ 'tabel', 'csv_id', 'proses', 'subproses', 'jalur', 'arsip', 'basis_data',
47
+ 'antrian',
38
48
  ];
39
49
 
40
50
  const CONSTANTS = ['Benar', 'Salah', 'Kosong', 'True', 'False', 'None'];
@@ -0,0 +1,37 @@
1
+ function Antrian(maks = 0) {
2
+ if (!(this instanceof Antrian)) {
3
+ return new Antrian(maks);
4
+ }
5
+ this._maks = maks;
6
+ this._items = [];
7
+ }
8
+
9
+ Antrian.prototype.masukkan = function (item) {
10
+ if (this._maks > 0 && this._items.length >= this._maks) {
11
+ throw new Error('Antrian penuh');
12
+ }
13
+ this._items.push(item);
14
+ };
15
+
16
+ Antrian.prototype.ambil = function () {
17
+ if (this.kosong()) {
18
+ throw new Error('Antrian kosong');
19
+ }
20
+ return this._items.shift();
21
+ };
22
+
23
+ Antrian.prototype.ukuran = function () {
24
+ return this._items.length;
25
+ };
26
+
27
+ Antrian.prototype.kosong = function () {
28
+ return this._items.length === 0;
29
+ };
30
+
31
+ Antrian.prototype.penuh = function () {
32
+ return this._maks > 0 && this._items.length >= this._maks;
33
+ };
34
+
35
+ module.exports = {
36
+ Antrian,
37
+ };
@@ -0,0 +1,31 @@
1
+ const fs = require('fs');
2
+ const path = require('path');
3
+
4
+ function salin_berkas(sumber, tujuan) {
5
+ fs.copyFileSync(sumber, tujuan);
6
+ return true;
7
+ }
8
+
9
+ function salin_folder(sumber, tujuan) {
10
+ fs.cpSync(sumber, tujuan, { recursive: true });
11
+ return true;
12
+ }
13
+
14
+ function hapus_folder(folder) {
15
+ if (fs.existsSync(folder)) {
16
+ fs.rmSync(folder, { recursive: true, force: true });
17
+ }
18
+ return true;
19
+ }
20
+
21
+ function pindah(sumber, tujuan) {
22
+ fs.renameSync(sumber, tujuan);
23
+ return true;
24
+ }
25
+
26
+ module.exports = {
27
+ salin_berkas,
28
+ salin_folder,
29
+ hapus_folder,
30
+ pindah,
31
+ };
@@ -0,0 +1,47 @@
1
+ const fs = require('fs');
2
+
3
+ function hubungkan(nama_berkas = ':memory:') {
4
+ let store = {};
5
+ if (nama_berkas !== ':memory:' && fs.existsSync(nama_berkas)) {
6
+ try {
7
+ store = JSON.parse(fs.readFileSync(nama_berkas, 'utf8'));
8
+ } catch {}
9
+ }
10
+ return {
11
+ _file: nama_berkas,
12
+ _store: store,
13
+ _rows: [],
14
+ };
15
+ }
16
+
17
+ function eksekusi(koneksi, sql, params = []) {
18
+ // basic mock for node fallback
19
+ return 1;
20
+ }
21
+
22
+ function ambil_semua(koneksi, sql, params = []) {
23
+ return koneksi._rows || [];
24
+ }
25
+
26
+ function ambil_satu(koneksi, sql, params = []) {
27
+ return (koneksi._rows && koneksi._rows[0]) || null;
28
+ }
29
+
30
+ function simpan(koneksi) {
31
+ if (koneksi._file !== ':memory:') {
32
+ fs.writeFileSync(koneksi._file, JSON.stringify(koneksi._store, null, 2), 'utf8');
33
+ }
34
+ }
35
+
36
+ function tutup(koneksi) {
37
+ simpan(koneksi);
38
+ }
39
+
40
+ module.exports = {
41
+ hubungkan,
42
+ eksekusi,
43
+ ambil_semua,
44
+ ambil_satu,
45
+ simpan,
46
+ tutup,
47
+ };
@@ -9,6 +9,14 @@ const koleksi = require('./koleksi');
9
9
  const kripto = require('./kripto');
10
10
  const jaringan = require('./jaringan');
11
11
  const uji = require('./uji');
12
+ const statistika = require('./statistika');
13
+ const iterasi = require('./iterasi');
14
+ const tabel = require('./tabel');
15
+ const proses = require('./proses');
16
+ const jalur = require('./jalur');
17
+ const arsip = require('./arsip');
18
+ const basis_data = require('./basis_data');
19
+ const antrian = require('./antrian');
12
20
 
13
21
  const STD_MODULES = {
14
22
  matematika,
@@ -24,6 +32,16 @@ const STD_MODULES = {
24
32
  kripto,
25
33
  jaringan,
26
34
  uji,
35
+ statistika,
36
+ iterasi,
37
+ tabel,
38
+ csv_id: tabel,
39
+ proses,
40
+ subproses: proses,
41
+ jalur,
42
+ arsip,
43
+ basis_data,
44
+ antrian,
27
45
  };
28
46
 
29
47
  module.exports = { STD_MODULES };
@@ -0,0 +1,136 @@
1
+ function kombinasi(koleksi, r) {
2
+ const arr = Array.from(koleksi);
3
+ if (r < 0 || r > arr.length) return [];
4
+ if (r === 0) return [[]];
5
+ const hasil = [];
6
+ function bantu(mulai, jalur) {
7
+ if (jalur.length === r) {
8
+ hasil.push([...jalur]);
9
+ return;
10
+ }
11
+ for (let i = mulai; i < arr.length; i++) {
12
+ jalur.push(arr[i]);
13
+ bantu(i + 1, jalur);
14
+ jalur.pop();
15
+ }
16
+ }
17
+ bantu(0, []);
18
+ return hasil;
19
+ }
20
+
21
+ function permutasi(koleksi, r) {
22
+ const arr = Array.from(koleksi);
23
+ const panjang = r === undefined || r === null ? arr.length : r;
24
+ if (panjang < 0 || panjang > arr.length) return [];
25
+ if (panjang === 0) return [[]];
26
+ const hasil = [];
27
+ const digunakan = new Array(arr.length).fill(false);
28
+ function bantu(jalur) {
29
+ if (jalur.length === panjang) {
30
+ hasil.push([...jalur]);
31
+ return;
32
+ }
33
+ for (let i = 0; i < arr.length; i++) {
34
+ if (digunakan[i]) continue;
35
+ digunakan[i] = true;
36
+ jalur.push(arr[i]);
37
+ bantu(jalur);
38
+ jalur.pop();
39
+ digunakan[i] = false;
40
+ }
41
+ }
42
+ bantu([]);
43
+ return hasil;
44
+ }
45
+
46
+ function produk(...koleksi) {
47
+ if (koleksi.length === 0) return [[]];
48
+ let hasil = [[]];
49
+ for (const pool of koleksi) {
50
+ const baru = [];
51
+ for (const x of hasil) {
52
+ for (const y of pool) {
53
+ baru.push([...x, y]);
54
+ }
55
+ }
56
+ hasil = baru;
57
+ }
58
+ return hasil;
59
+ }
60
+
61
+ function rantai(...koleksi) {
62
+ const hasil = [];
63
+ for (const k of koleksi) {
64
+ hasil.push(...Array.from(k));
65
+ }
66
+ return hasil;
67
+ }
68
+
69
+ function akumulasi(koleksi, fungsi) {
70
+ const arr = Array.from(koleksi);
71
+ if (arr.length === 0) return [];
72
+ const fn = fungsi || ((a, b) => a + b);
73
+ const hasil = [arr[0]];
74
+ for (let i = 1; i < arr.length; i++) {
75
+ hasil.push(fn(hasil[i - 1], arr[i]));
76
+ }
77
+ return hasil;
78
+ }
79
+
80
+ function ulang(item, kali) {
81
+ const hasil = [];
82
+ for (let i = 0; i < kali; i++) hasil.push(item);
83
+ return hasil;
84
+ }
85
+
86
+ function ambil_selama(predikat, koleksi) {
87
+ const hasil = [];
88
+ for (const item of koleksi) {
89
+ if (predikat(item)) hasil.push(item);
90
+ else break;
91
+ }
92
+ return hasil;
93
+ }
94
+
95
+ function lewati_selama(predikat, koleksi) {
96
+ const arr = Array.from(koleksi);
97
+ let idx = 0;
98
+ while (idx < arr.length && predikat(arr[idx])) {
99
+ idx++;
100
+ }
101
+ return arr.slice(idx);
102
+ }
103
+
104
+ function saring_palsu(predikat, koleksi) {
105
+ return Array.from(koleksi).filter((x) => !predikat(x));
106
+ }
107
+
108
+ function siklus(koleksi, kali = 1) {
109
+ const arr = Array.from(koleksi);
110
+ const hasil = [];
111
+ for (let i = 0; i < kali; i++) hasil.push(...arr);
112
+ return hasil;
113
+ }
114
+
115
+ function ritsleting_terpanjang(...koleksi) {
116
+ const maxLen = Math.max(...koleksi.map((k) => k.length));
117
+ const hasil = [];
118
+ for (let i = 0; i < maxLen; i++) {
119
+ hasil.push(koleksi.map((k) => (i < k.length ? k[i] : null)));
120
+ }
121
+ return hasil;
122
+ }
123
+
124
+ module.exports = {
125
+ kombinasi,
126
+ permutasi,
127
+ produk,
128
+ rantai,
129
+ akumulasi,
130
+ ulang,
131
+ ambil_selama,
132
+ lewati_selama,
133
+ saring_palsu,
134
+ siklus,
135
+ ritsleting_terpanjang,
136
+ };
@@ -0,0 +1,77 @@
1
+ const path = require('path');
2
+ const fs = require('fs');
3
+ const os = require('os');
4
+
5
+ function gabung(...bagian) {
6
+ return path.join(...bagian);
7
+ }
8
+
9
+ function nama(jalur) {
10
+ return path.basename(jalur);
11
+ }
12
+
13
+ function induk(jalur) {
14
+ return path.dirname(jalur);
15
+ }
16
+
17
+ function ekstensi(jalur) {
18
+ return path.extname(jalur);
19
+ }
20
+
21
+ function nama_murni(jalur) {
22
+ return path.basename(jalur, path.extname(jalur));
23
+ }
24
+
25
+ function mutlak(jalur) {
26
+ return path.resolve(jalur);
27
+ }
28
+
29
+ function ada(jalur) {
30
+ return fs.existsSync(jalur);
31
+ }
32
+
33
+ function adalah_berkas(jalur) {
34
+ return fs.existsSync(jalur) && fs.statSync(jalur).isFile();
35
+ }
36
+
37
+ function adalah_folder(jalur) {
38
+ return fs.existsSync(jalur) && fs.statSync(jalur).isDirectory();
39
+ }
40
+
41
+ function ukuran(jalur) {
42
+ return fs.existsSync(jalur) ? fs.statSync(jalur).size : 0;
43
+ }
44
+
45
+ function folder_pengguna() {
46
+ return os.homedir();
47
+ }
48
+
49
+ function direktori_kerja() {
50
+ return process.cwd();
51
+ }
52
+
53
+ function baca_teks(jalur, encoding = 'utf-8') {
54
+ return fs.readFileSync(jalur, encoding).replace(/^\uFEFF/, '');
55
+ }
56
+
57
+ function tulis_teks(jalur, konten, encoding = 'utf-8') {
58
+ fs.writeFileSync(jalur, konten, encoding);
59
+ return true;
60
+ }
61
+
62
+ module.exports = {
63
+ gabung,
64
+ nama,
65
+ induk,
66
+ ekstensi,
67
+ nama_murni,
68
+ mutlak,
69
+ ada,
70
+ adalah_berkas,
71
+ adalah_folder,
72
+ ukuran,
73
+ folder_pengguna,
74
+ direktori_kerja,
75
+ baca_teks,
76
+ tulis_teks,
77
+ };
@@ -0,0 +1,43 @@
1
+ const { execSync, spawnSync } = require('child_process');
2
+
3
+ function jalankan(perintah, masukan = null, tangkap_keluaran = true, batas_waktu = null) {
4
+ try {
5
+ const res = spawnSync(perintah, {
6
+ shell: true,
7
+ input: masukan,
8
+ encoding: 'utf8',
9
+ timeout: batas_waktu ? batas_waktu * 1000 : undefined,
10
+ });
11
+ return {
12
+ kode_keluar: res.status !== null ? res.status : -1,
13
+ sukses: res.status === 0,
14
+ keluaran: res.stdout || '',
15
+ galat: res.stderr || '',
16
+ };
17
+ } catch (err) {
18
+ return {
19
+ kode_keluar: -1,
20
+ sukses: false,
21
+ keluaran: '',
22
+ galat: err.message,
23
+ };
24
+ }
25
+ }
26
+
27
+ function keluaran(perintah) {
28
+ try {
29
+ return execSync(perintah, { encoding: 'utf8', shell: true }).trim();
30
+ } catch (err) {
31
+ return '';
32
+ }
33
+ }
34
+
35
+ function sukses(perintah) {
36
+ return jalankan(perintah).sukses;
37
+ }
38
+
39
+ module.exports = {
40
+ jalankan,
41
+ keluaran,
42
+ sukses,
43
+ };
@@ -0,0 +1,79 @@
1
+ function rata_rata(daftar) {
2
+ if (!daftar || daftar.length === 0) return 0;
3
+ return daftar.reduce((acc, v) => acc + Number(v), 0) / daftar.length;
4
+ }
5
+
6
+ function median(daftar) {
7
+ if (!daftar || daftar.length === 0) return 0;
8
+ const s = [...daftar].map(Number).sort((a, b) => a - b);
9
+ const mid = Math.floor(s.length / 2);
10
+ return s.length % 2 !== 0 ? s[mid] : (s[mid - 1] + s[mid]) / 2;
11
+ }
12
+
13
+ function median_bawah(daftar) {
14
+ if (!daftar || daftar.length === 0) return 0;
15
+ const s = [...daftar].map(Number).sort((a, b) => a - b);
16
+ return s[Math.floor((s.length - 1) / 2)];
17
+ }
18
+
19
+ function median_atas(daftar) {
20
+ if (!daftar || daftar.length === 0) return 0;
21
+ const s = [...daftar].map(Number).sort((a, b) => a - b);
22
+ return s[Math.floor(s.length / 2)];
23
+ }
24
+
25
+ function modus(daftar) {
26
+ if (!daftar || daftar.length === 0) return null;
27
+ const frek = new Map();
28
+ let maxCount = 0;
29
+ let modVal = daftar[0];
30
+ for (const item of daftar) {
31
+ const c = (frek.get(item) || 0) + 1;
32
+ frek.set(item, c);
33
+ if (c > maxCount) {
34
+ maxCount = c;
35
+ modVal = item;
36
+ }
37
+ }
38
+ return modVal;
39
+ }
40
+
41
+ function varians(daftar) {
42
+ if (!daftar || daftar.length < 2) return 0;
43
+ const m = rata_rata(daftar);
44
+ const sumSq = daftar.reduce((acc, v) => acc + Math.pow(Number(v) - m, 2), 0);
45
+ return sumSq / (daftar.length - 1);
46
+ }
47
+
48
+ function deviasi_standar(daftar) {
49
+ return Math.sqrt(varians(daftar));
50
+ }
51
+
52
+ function rentang_nilai(daftar) {
53
+ if (!daftar || daftar.length === 0) return 0;
54
+ return Math.max(...daftar) - Math.min(...daftar);
55
+ }
56
+
57
+ function kuartil(daftar) {
58
+ if (!daftar || daftar.length < 4) return [];
59
+ const s = [...daftar].map(Number).sort((a, b) => a - b);
60
+ const q = (p) => {
61
+ const pos = (s.length - 1) * p;
62
+ const base = Math.floor(pos);
63
+ const rest = pos - base;
64
+ return s[base + 1] !== undefined ? s[base] + rest * (s[base + 1] - s[base]) : s[base];
65
+ };
66
+ return [q(0.25), q(0.5), q(0.75)];
67
+ }
68
+
69
+ module.exports = {
70
+ rata_rata,
71
+ median,
72
+ median_bawah,
73
+ median_atas,
74
+ modus,
75
+ varians,
76
+ deviasi_standar,
77
+ rentang_nilai,
78
+ kuartil,
79
+ };
@@ -0,0 +1,83 @@
1
+ const fs = require('fs');
2
+
3
+ function parseLine(line, delimiter = ',') {
4
+ const result = [];
5
+ let current = '';
6
+ let inQuotes = false;
7
+
8
+ for (let i = 0; i < line.length; i++) {
9
+ const ch = line[i];
10
+ if (ch === '"') {
11
+ if (inQuotes && line[i + 1] === '"') {
12
+ current += '"';
13
+ i++;
14
+ } else {
15
+ inQuotes = !inQuotes;
16
+ }
17
+ } else if (ch === delimiter && !inQuotes) {
18
+ result.push(current);
19
+ current = '';
20
+ } else {
21
+ current += ch;
22
+ }
23
+ }
24
+ result.push(current);
25
+ return result;
26
+ }
27
+
28
+ function escapeField(field, delimiter = ',') {
29
+ const str = String(field == null ? '' : field);
30
+ if (str.includes(delimiter) || str.includes('"') || str.includes('\n')) {
31
+ return `"${str.replace(/"/g, '""')}"`;
32
+ }
33
+ return str;
34
+ }
35
+
36
+ function urai_teks(teks_csv, pemisah = ',') {
37
+ const lines = teks_csv.replace(/\r\n/g, '\n').replace(/\r/g, '\n').split('\n');
38
+ return lines.filter((l) => l.length > 0).map((l) => parseLine(l, pemisah));
39
+ }
40
+
41
+ function baca_csv(jalur, pemisah = ',', encoding = 'utf-8') {
42
+ const raw = fs.readFileSync(jalur, encoding).replace(/^\uFEFF/, '');
43
+ return urai_teks(raw, pemisah);
44
+ }
45
+
46
+ function tulis_csv(jalur, data, pemisah = ',', encoding = 'utf-8') {
47
+ const text = data.map((row) => row.map((f) => escapeField(f, pemisah)).join(pemisah)).join('\n') + '\n';
48
+ fs.writeFileSync(jalur, text, encoding);
49
+ return true;
50
+ }
51
+
52
+ function baca_kamus(jalur, pemisah = ',', encoding = 'utf-8') {
53
+ const rows = baca_csv(jalur, pemisah, encoding);
54
+ if (rows.length === 0) return [];
55
+ const header = rows[0];
56
+ const results = [];
57
+ for (let i = 1; i < rows.length; i++) {
58
+ const item = {};
59
+ for (let j = 0; j < header.length; j++) {
60
+ item[header[j]] = rows[i][j] !== undefined ? rows[i][j] : '';
61
+ }
62
+ results.push(item);
63
+ }
64
+ return results;
65
+ }
66
+
67
+ function tulis_kamus(jalur, data, kolom = null, pemisah = ',', encoding = 'utf-8') {
68
+ if (!data || data.length === 0) return false;
69
+ const cols = kolom || Object.keys(data[0]);
70
+ const rows = [cols];
71
+ for (const item of data) {
72
+ rows.push(cols.map((k) => item[k]));
73
+ }
74
+ return tulis_csv(jalur, rows, pemisah, encoding);
75
+ }
76
+
77
+ module.exports = {
78
+ baca_csv,
79
+ tulis_csv,
80
+ baca_kamus,
81
+ tulis_kamus,
82
+ urai_teks,
83
+ };
@@ -0,0 +1,20 @@
1
+ import queue
2
+
3
+ class Antrian:
4
+ def __init__(self, maks=0):
5
+ self._q = queue.Queue(maxsize=maks)
6
+
7
+ def masukkan(self, item):
8
+ self._q.put(item)
9
+
10
+ def ambil(self):
11
+ return self._q.get()
12
+
13
+ def ukuran(self):
14
+ return self._q.qsize()
15
+
16
+ def kosong(self):
17
+ return self._q.empty()
18
+
19
+ def penuh(self):
20
+ return self._q.full()
@@ -0,0 +1,37 @@
1
+ import shutil
2
+ import zipfile
3
+ import os
4
+
5
+ def buat_zip(nama_zip, jalur_sumber):
6
+ if not nama_zip.endswith(".zip"):
7
+ nama_zip += ".zip"
8
+ with zipfile.ZipFile(nama_zip, "w", zipfile.ZIP_DEFLATED) as z:
9
+ if os.path.isdir(jalur_sumber):
10
+ for akar, _, berkas_list in os.walk(jalur_sumber):
11
+ for b in berkas_list:
12
+ jalur_lengkap = os.path.join(akar, b)
13
+ rel = os.path.relpath(jalur_lengkap, jalur_sumber)
14
+ z.write(jalur_lengkap, rel)
15
+ else:
16
+ z.write(jalur_sumber, os.path.basename(jalur_sumber))
17
+ return os.path.abspath(nama_zip)
18
+
19
+ def ekstrak_zip(jalur_zip, folder_tujuan="."):
20
+ os.makedirs(folder_tujuan, exist_ok=True)
21
+ with zipfile.ZipFile(jalur_zip, "r") as z:
22
+ z.extractall(folder_tujuan)
23
+ return os.path.abspath(folder_tujuan)
24
+
25
+ def salin_berkas(sumber, tujuan):
26
+ return shutil.copy2(sumber, tujuan)
27
+
28
+ def salin_folder(sumber, tujuan):
29
+ return shutil.copytree(sumber, tujuan, dirs_exist_ok=True)
30
+
31
+ def hapus_folder(folder):
32
+ if os.path.exists(folder):
33
+ shutil.rmtree(folder)
34
+ return True
35
+
36
+ def pindah(sumber, tujuan):
37
+ return shutil.move(sumber, tujuan)
@@ -0,0 +1,29 @@
1
+ import sqlite3
2
+
3
+ def hubungkan(nama_berkas=":memory:"):
4
+ conn = sqlite3.connect(nama_berkas)
5
+ conn.row_factory = sqlite3.Row
6
+ return conn
7
+
8
+ def eksekusi(koneksi, sql, params=()):
9
+ cur = koneksi.cursor()
10
+ cur.execute(sql, params)
11
+ koneksi.commit()
12
+ return cur.lastrowid
13
+
14
+ def ambil_semua(koneksi, sql, params=()):
15
+ cur = koneksi.cursor()
16
+ cur.execute(sql, params)
17
+ return [dict(r) for r in cur.fetchall()]
18
+
19
+ def ambil_satu(koneksi, sql, params=()):
20
+ cur = koneksi.cursor()
21
+ cur.execute(sql, params)
22
+ row = cur.fetchone()
23
+ return dict(row) if row else None
24
+
25
+ def simpan(koneksi):
26
+ koneksi.commit()
27
+
28
+ def tutup(koneksi):
29
+ koneksi.close()
@@ -0,0 +1,37 @@
1
+ import itertools
2
+
3
+ def kombinasi(koleksi, r):
4
+ return [list(x) for x in itertools.combinations(koleksi, r)]
5
+
6
+ def permutasi(koleksi, r=None):
7
+ return [list(x) for x in itertools.permutations(koleksi, r)]
8
+
9
+ def produk(*koleksi, ulangi=1):
10
+ return [list(x) for x in itertools.product(*koleksi, repeat=ulangi)]
11
+
12
+ def rantai(*koleksi):
13
+ return list(itertools.chain(*koleksi))
14
+
15
+ def akumulasi(koleksi, fungsi=None):
16
+ return list(itertools.accumulate(koleksi, fungsi) if fungsi else itertools.accumulate(koleksi))
17
+
18
+ def ulang(item, kali):
19
+ return list(itertools.repeat(item, kali))
20
+
21
+ def ambil_selama(predikat, koleksi):
22
+ return list(itertools.takewhile(predikat, koleksi))
23
+
24
+ def lewati_selama(predikat, koleksi):
25
+ return list(itertools.dropwhile(predikat, koleksi))
26
+
27
+ def saring_palsu(predikat, koleksi):
28
+ return list(itertools.filterfalse(predikat, koleksi))
29
+
30
+ def siklus(koleksi, kali=1):
31
+ hasil = []
32
+ for _ in range(kali):
33
+ hasil.extend(koleksi)
34
+ return hasil
35
+
36
+ def ritsleting_terpanjang(*koleksi, bawaan=None):
37
+ return [list(x) for x in itertools.zip_longest(*koleksi, fillvalue=bawaan)]
@@ -0,0 +1,47 @@
1
+ import os
2
+ import pathlib
3
+
4
+ def gabung(*bagian):
5
+ return os.path.join(*bagian)
6
+
7
+ def nama(jalur):
8
+ return os.path.basename(jalur)
9
+
10
+ def induk(jalur):
11
+ return os.path.dirname(jalur)
12
+
13
+ def ekstensi(jalur):
14
+ return os.path.splitext(jalur)[1]
15
+
16
+ def nama_murni(jalur):
17
+ return pathlib.Path(jalur).stem
18
+
19
+ def mutlak(jalur):
20
+ return os.path.abspath(jalur)
21
+
22
+ def ada(jalur):
23
+ return os.path.exists(jalur)
24
+
25
+ def adalah_berkas(jalur):
26
+ return os.path.isfile(jalur)
27
+
28
+ def adalah_folder(jalur):
29
+ return os.path.isdir(jalur)
30
+
31
+ def ukuran(jalur):
32
+ return os.path.getsize(jalur) if os.path.exists(jalur) else 0
33
+
34
+ def folder_pengguna():
35
+ return str(pathlib.Path.home())
36
+
37
+ def direktori_kerja():
38
+ return os.getcwd()
39
+
40
+ def baca_teks(jalur, encoding="utf-8"):
41
+ with open(jalur, "r", encoding=encoding) as f:
42
+ return f.read()
43
+
44
+ def tulis_teks(jalur, konten, encoding="utf-8"):
45
+ with open(jalur, "w", encoding=encoding) as f:
46
+ f.write(konten)
47
+ return True
@@ -0,0 +1,35 @@
1
+ import subprocess
2
+ import sys
3
+
4
+ def jalankan(perintah, masukan=None, tangkap_keluaran=True, batas_waktu=None, shell=True):
5
+ try:
6
+ res = subprocess.run(
7
+ perintah,
8
+ input=masukan,
9
+ capture_output=tangkap_keluaran,
10
+ text=True,
11
+ timeout=batas_waktu,
12
+ shell=shell
13
+ )
14
+ return {
15
+ "kode_keluar": res.returncode,
16
+ "sukses": res.returncode == 0,
17
+ "keluaran": res.stdout or "",
18
+ "galat": res.stderr or ""
19
+ }
20
+ except Exception as e:
21
+ return {
22
+ "kode_keluar": -1,
23
+ "sukses": False,
24
+ "keluaran": "",
25
+ "galat": str(e)
26
+ }
27
+
28
+ def keluaran(perintah, shell=True):
29
+ try:
30
+ return subprocess.check_output(perintah, text=True, shell=shell).strip()
31
+ except Exception as e:
32
+ return ""
33
+
34
+ def sukses(perintah, shell=True):
35
+ return jalankan(perintah, shell=shell)["sukses"]
@@ -0,0 +1,29 @@
1
+ import statistics
2
+
3
+ pi_stat = statistics
4
+
5
+ rata_rata = statistics.mean
6
+ median = statistics.median
7
+ median_bawah = statistics.median_low
8
+ median_atas = statistics.median_high
9
+
10
+ def modus(daftar):
11
+ try:
12
+ return statistics.mode(daftar)
13
+ except Exception:
14
+ return daftar[0] if daftar else None
15
+
16
+ def varians(daftar):
17
+ return statistics.variance(daftar) if len(daftar) > 1 else 0
18
+
19
+ def deviasi_standar(daftar):
20
+ return statistics.stdev(daftar) if len(daftar) > 1 else 0
21
+
22
+ def rentang_nilai(daftar):
23
+ return (max(daftar) - min(daftar)) if daftar else 0
24
+
25
+ def kuartil(daftar):
26
+ try:
27
+ return statistics.quantiles(daftar, n=4)
28
+ except Exception:
29
+ return []
@@ -0,0 +1,29 @@
1
+ import csv
2
+
3
+ def baca_csv(jalur, pemisah=",", encoding="utf-8"):
4
+ with open(jalur, "r", encoding=encoding, newline="") as f:
5
+ return list(csv.reader(f, delimiter=pemisah))
6
+
7
+ def tulis_csv(jalur, data, pemisah=",", encoding="utf-8"):
8
+ with open(jalur, "w", encoding=encoding, newline="") as f:
9
+ writer = csv.writer(f, delimiter=pemisah)
10
+ writer.writerows(data)
11
+ return True
12
+
13
+ def baca_kamus(jalur, pemisah=",", encoding="utf-8"):
14
+ with open(jalur, "r", encoding=encoding, newline="") as f:
15
+ return [dict(row) for row in csv.DictReader(f, delimiter=pemisah)]
16
+
17
+ def tulis_kamus(jalur, data, kolom=None, pemisah=",", encoding="utf-8"):
18
+ if not data:
19
+ return False
20
+ if kolom is None:
21
+ kolom = list(data[0].keys())
22
+ with open(jalur, "w", encoding=encoding, newline="") as f:
23
+ writer = csv.DictWriter(f, fieldnames=kolom, delimiter=pemisah)
24
+ writer.writeheader()
25
+ writer.writerows(data)
26
+ return True
27
+
28
+ def urai_teks(teks_csv, pemisah=","):
29
+ return list(csv.reader(teks_csv.strip().splitlines(), delimiter=pemisah))
@@ -10,8 +10,12 @@ import random as _mhs_random
10
10
  import time as _mhs_time
11
11
  import os as _mhs_os
12
12
  import sys as _mhs_sys
13
+ import copy as _mhs_copy
13
14
  import importlib.util as _mhs_importlib_util
14
15
 
16
+ if len(_mhs_sys.argv) > 1 and _mhs_sys.argv[0] == '-c':
17
+ _mhs_sys.argv = _mhs_sys.argv[1:]
18
+
15
19
  cetak = print
16
20
  masukan = input
17
21
  rentang = range
@@ -51,6 +55,36 @@ kunci = lambda d: list(d.keys())
51
55
  nilai = lambda d: list(d.values())
52
56
  buka = open
53
57
 
58
+ # Fitur & fungsi bawaan Python dalam Bahasa Indonesia
59
+ semua = all
60
+ ada_yang = any
61
+ cacah = enumerate
62
+ pasangkan = zip
63
+ saring = lambda fn, kol: list(filter(fn, kol))
64
+ petakan = lambda fn, kol: list(map(fn, kol))
65
+ bisa_dipanggil = callable
66
+ punya_atribut = hasattr
67
+ ambil_atribut = getattr
68
+ atur_atribut = setattr
69
+ hapus_atribut = delattr
70
+ adalah_turunan = isinstance
71
+ turunan_dari = isinstance
72
+ nilai_karakter = ord
73
+ karakter = chr
74
+ format_teks = format
75
+ teks_biner = bin
76
+ teks_heksa = hex
77
+ teks_oktal = oct
78
+ evaluasi = eval
79
+ eksekusi = exec
80
+ daftar_anggota = dir
81
+ penghitung = iter
82
+ berikutnya = next
83
+ keluar = _mhs_sys.exit
84
+ salin = lambda x: _mhs_copy.copy(x)
85
+ salin_dalam = lambda x: _mhs_copy.deepcopy(x)
86
+ bekukan = frozenset
87
+
54
88
  def tipe(x):
55
89
  if x is None: return "kosong"
56
90
  if isinstance(x, bool): return "boolean"
@@ -155,6 +189,7 @@ function transformPyExpr(expr) {
155
189
  res = res.replace(/\bdiri\b/g, 'self');
156
190
  res = res.replace(/\bbukan_adalah\b/g, 'is not');
157
191
  res = res.replace(/\badalah\b/g, 'is');
192
+ res = res.replace(/\bbukan_dalam\b/g, 'not in');
158
193
  res = res.replace(/\bdan\b/g, 'and');
159
194
  res = res.replace(/\batau\b/g, 'or');
160
195
  res = res.replace(/\bbukan\b/g, 'not');
@@ -163,6 +198,7 @@ function transformPyExpr(expr) {
163
198
  res = res.replace(/\bjika\b/g, 'if');
164
199
  res = res.replace(/\bselain_itu\b/g, 'else');
165
200
  res = res.replace(/\banonim\b/g, 'lambda');
201
+ res = res.replace(/\btunggu_eksekusi\b/g, 'await');
166
202
  return res;
167
203
  }
168
204
 
@@ -203,7 +239,7 @@ function transformPyLine(rawLine) {
203
239
  res = res.replace(/^selama\b/, 'while');
204
240
  res = res.replace(/^untuk\b/, 'for');
205
241
  res = res.replace(/^coba\b/, 'try');
206
- res = res.replace(/^tangkap(?:\s+([A-Za-z_]\w*))?\s*:/, (_, v) => (v ? `except Exception as ${v}:` : 'except Exception:'));
242
+ res = res.replace(/^(?:tangkap|kecuali)(?:\s+([A-Za-z_]\w*))?\s*:/, (_, v) => (v ? `except Exception as ${v}:` : 'except Exception:'));
207
243
  res = res.replace(/^akhirnya\b/, 'finally');
208
244
  res = res.replace(/^dengan\b/, 'with');
209
245
  res = res.replace(/^kembalikan\b/, 'return');
@@ -214,6 +250,11 @@ function transformPyLine(rawLine) {
214
250
  res = res.replace(/^lempar\s+(.+)$/, (_, msg) => `raise Exception(${transformPyExpr(msg)})`);
215
251
  res = res.replace(/^pastikan\b/, 'assert');
216
252
  res = res.replace(/^umum\b/, 'global');
253
+ res = res.replace(/^bukan_lokal\b/, 'nonlocal');
254
+ res = res.replace(/^hapus_var\b/, 'del');
255
+ res = res.replace(/^@properti\b/, '@property');
256
+ res = res.replace(/^@metode_statis\b/, '@staticmethod');
257
+ res = res.replace(/^@metode_kelas\b/, '@classmethod');
217
258
 
218
259
  res = res.replace(/\bsebagai\b/g, 'as');
219
260
  res = transformPyExpr(res);
@@ -222,7 +263,7 @@ function transformPyLine(rawLine) {
222
263
  }
223
264
 
224
265
  function transpileToPython(source, { includePrelude = true } = {}) {
225
- const cleanSource = source.replace(/^\uFEFF/, '');
266
+ const cleanSource = source.replace(/\uFEFF/g, '');
226
267
  const lines = cleanSource.replace(/\r\n/g, '\n').split('\n');
227
268
  const body = lines.map(transformPyLine).join('\n');
228
269
  if (!includePrelude) return body;
package/src/stdlib.js CHANGED
@@ -116,12 +116,31 @@ const stdlib = {
116
116
  semua: (koleksi) => Array.from(koleksi).every(Boolean),
117
117
  ada_yang: (koleksi) => Array.from(koleksi).some(Boolean),
118
118
  enumerasi: (koleksi, mulai = 0) => Array.from(koleksi).map((v, i) => [i + mulai, v]),
119
+ cacah: (koleksi, mulai = 0) => Array.from(koleksi).map((v, i) => [i + mulai, v]),
119
120
  pasangkan: (a, b) => {
120
121
  const len = Math.min(a.length, b.length);
121
122
  const out = [];
122
123
  for (let i = 0; i < len; i++) out.push([a[i], b[i]]);
123
124
  return out;
124
125
  },
126
+ bisa_dipanggil: (fn) => typeof fn === 'function',
127
+ punya_atribut: (obj, prop) => obj != null && prop in obj,
128
+ ambil_atribut: (obj, prop, defVal) => (obj != null && prop in obj ? obj[prop] : defVal),
129
+ atur_atribut: (obj, prop, val) => { if (obj != null) obj[prop] = val; },
130
+ hapus_atribut: (obj, prop) => { if (obj != null) delete obj[prop]; },
131
+ adalah_turunan: (obj, cls) => (cls === Array ? Array.isArray(obj) : obj instanceof cls),
132
+ turunan_dari: (obj, cls) => (cls === Array ? Array.isArray(obj) : obj instanceof cls),
133
+ nilai_karakter: (ch) => String(ch).charCodeAt(0),
134
+ karakter: (code) => String.fromCharCode(code),
135
+ format_teks: (val) => String(val),
136
+ teks_biner: (n) => '0b' + Number(n).toString(2),
137
+ teks_heksa: (n) => '0x' + Number(n).toString(16),
138
+ teks_oktal: (n) => '0o' + Number(n).toString(8),
139
+ daftar_anggota: (obj) => (obj != null ? Object.keys(obj) : []),
140
+ keluar: (code = 0) => process.exit(code),
141
+ salin: (x) => (Array.isArray(x) ? [...x] : typeof x === 'object' && x !== null ? { ...x } : x),
142
+ salin_dalam: (x) => JSON.parse(JSON.stringify(x)),
143
+ bekukan: (x) => Object.freeze(Array.isArray(x) ? [...x] : { ...x }),
125
144
  petakan: (fn, koleksi) => Array.from(koleksi).map(fn),
126
145
  saring: (fn, koleksi) => Array.from(koleksi).filter(fn),
127
146
  tambah: (d, item) => { d.push(item); return d; },
package/src/transpiler.js CHANGED
@@ -156,7 +156,7 @@ function getIndent(line) {
156
156
  }
157
157
 
158
158
  function transpile(source) {
159
- const cleanSource = source.replace(/^\uFEFF/, '');
159
+ const cleanSource = source.replace(/\uFEFF/g, '');
160
160
  const rawLines = cleanSource.replace(/\r\n/g, '\n').split('\n');
161
161
  const indentStack = [0];
162
162
  const scopeStack = [new Set(BUILTIN_NAMES)];