bahasa-simpl 1.0.15 → 1.0.17

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 (3) hide show
  1. package/README.md +3 -1
  2. package/dist/simpl.js +55 -10
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -47,6 +47,8 @@ cetak "Halo Dunia!"
47
47
  `));
48
48
  ```
49
49
 
50
+ \*Hati-hati terhadap karakter garis miring belakang ( \ ) dalam javascript string, `simpl` dapat memproses karakter \\n \\t dan \\", jadi dalam string javascript, anda harus menulisnya dua kali => \\\\n
51
+
50
52
  ## API
51
53
 
52
54
  `class Simpl(opts?: { keepMemory?: boolean })`:
@@ -58,7 +60,7 @@ cetak "Halo Dunia!"
58
60
  - Menjalankan `simpl` dan mencetak output programnya ke layar.
59
61
 
60
62
  ## Contoh `simpl`
61
- Tur lebih lengkap ada dalam [Tur Sintaks Simpl](https://github.com/faeiz-ff/simpl/blob/main/docs/tur.md)
63
+ Tur lebih lengkap ada dalam [Tur Sintaks Simpl](https://github.com/faeiz-ff/simpl/blob/main/docs/tur-sintaks.md)
62
64
  - `mesin` akar dua
63
65
  ```simpl
64
66
  mesin akar2 ==> (angka n) {
package/dist/simpl.js CHANGED
@@ -132,7 +132,7 @@ let Model$1 = class Model extends Stipe {
132
132
  if (symbol === null) {
133
133
  val.isDatum = true;
134
134
  val.type = args[i].type;
135
- } else if (args[i].type !== symbol) {
135
+ } else if (args[i].data === null) ; else if (args[i].type !== symbol) {
136
136
  v.line = callLine;
137
137
  v.error(`Argumen pembuatan objek tidak sama dengan argumen model, menemukan ${args[i].type?.description}, mengharapkan ${symbol ? symbol.description : "nihil"}`);
138
138
  }
@@ -512,6 +512,34 @@ const GLOBAL_ENV = (() => {
512
512
  env.define("baris", BarisTipe);
513
513
  env.define("mesin", MesinTipe);
514
514
 
515
+ env.define("tulisf", makeBuiltInFunc([null, barisSymbol], null, (v, [d, b]) => {
516
+ let strTemp = kePetik(v, d);
517
+ let finalized = "";
518
+ let formator = b.data.map(value=>kePetik(v, value));
519
+
520
+ for (let i = 0; i < strTemp.length; i++) {
521
+ let ch = strTemp[i];
522
+ if ( ch !== "{") finalized += ch;
523
+ else {
524
+ if (i+1 < strTemp.length && strTemp[i+1] !== "}") {
525
+ finalized += "{"; continue;
526
+ }
527
+ i++;
528
+ if (formator.length === 0) {
529
+ v.error("Baris dalam tulisFormat tidak mempunyai cukup elemen!");
530
+ }
531
+ finalized += formator.shift();
532
+ }
533
+ }
534
+ v.output.push(finalized);
535
+ return d;
536
+ }));
537
+
538
+ env.define("tulis", makeBuiltInFunc([null], null, (v, [d]) => {
539
+ v.output.push(kePetik(v, d));
540
+ return d;
541
+ }));
542
+
515
543
  env.define("jarak", makeBuiltInFunc([angkaSymbol, angkaSymbol], barisSymbol,
516
544
  (_, [from, to]) => new Value(barisSymbol,
517
545
  Array(Math.abs(Math.floor(to.data - from.data)))
@@ -872,6 +900,7 @@ class Interpreter {
872
900
  let type = callable.parameters[i][0];
873
901
 
874
902
  if (type === null) continue;
903
+ if (args[i].data !== null) continue;
875
904
  if (args[i].type !== type) {
876
905
  this.line = callLineNum;
877
906
  this.error(`Tipe argumen tidak sama dengan parameter. Menemukan ${args[i].type.description}, harusnya ${type.description}`);
@@ -1036,8 +1065,7 @@ class Interpreter {
1036
1065
 
1037
1066
  visitCetakStmt(cetakStmt) {
1038
1067
  let result = cetakStmt.expr.accept(this);
1039
- this.output.push(kePetik(this, result));
1040
-
1068
+ this.output.push(kePetik(this, result) + "\n");
1041
1069
  }
1042
1070
 
1043
1071
  visitKerjaStmt(kerjaStmt) {
@@ -1350,7 +1378,7 @@ class Lexer {
1350
1378
  this.charIndex = 0;
1351
1379
  this.lineIndex = 1;
1352
1380
  this.tokens = [];
1353
- this.errors = [];
1381
+ this.errorLine = 0;
1354
1382
  }
1355
1383
 
1356
1384
  scanTokens(text) {
@@ -1454,12 +1482,29 @@ class Lexer {
1454
1482
  }
1455
1483
 
1456
1484
  string() {
1485
+ this.errorLine = this.lineIndex;
1457
1486
  this.advance();
1458
- while (!this.isAtEnd() && this.see() !== '"') this.advance();
1459
- if (this.isAtEnd()) this.error("Petik tidak tertutup.");
1487
+ let finalString = "";
1488
+ while (!this.isAtEnd() && this.see() !== '"') {
1489
+ if (this.see() === "\\") {
1490
+ this.advance();
1491
+ if (this.isAtEnd()) break;
1492
+ switch (this.see()) {
1493
+ case "n":
1494
+ finalString += "\n"; break;
1495
+ case "t":
1496
+ finalString += "\t"; break;
1497
+ default:
1498
+ finalString += this.see(); break;
1499
+ }
1500
+ } else finalString += this.see();
1501
+ this.advance();
1502
+ }
1503
+ if (this.isAtEnd()) this.error("Petik tidak tertutup.", this.errorLine);
1460
1504
  this.advance();
1461
1505
  let lexeme = this.parseLexeme();
1462
- return new Token(LITERAL, lexeme, lexeme.slice(1, lexeme.length - 1), this.lineIndex);
1506
+ // console.log(Array.from(finalString).map(c=>c.charCodeAt(0)))
1507
+ return new Token(LITERAL, lexeme, finalString, this.lineIndex);
1463
1508
  }
1464
1509
 
1465
1510
  comment() {
@@ -1561,8 +1606,8 @@ class Lexer {
1561
1606
  this.error(`karakter tidak valid: Menemukan '${this.see()}'.`);
1562
1607
  }
1563
1608
 
1564
- error(errmsg) {
1565
- throw new SimplErrorTulisan(`Error Tulisan => ` + errmsg, this.see().line);
1609
+ error(errmsg, line = -1) {
1610
+ throw new SimplErrorTulisan(`Error Tulisan => ` + errmsg, line === -1 ? this.see().line : line);
1566
1611
  }
1567
1612
 
1568
1613
  debugPrintTokens(tokens) {
@@ -2473,7 +2518,7 @@ class Simpl {
2473
2518
  let tokens = this.lexer.scanTokens(text);
2474
2519
  let pohon = this.parser.parse(tokens);
2475
2520
  let output = this.interpreter.interpret(pohon);
2476
- return output.join("\n");
2521
+ return output.join("");
2477
2522
  } catch (err) {
2478
2523
  if (err instanceof SimplError) {
2479
2524
  const errorCode = textLines[err.line - 1];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bahasa-simpl",
3
- "version": "1.0.15",
3
+ "version": "1.0.17",
4
4
  "description": "Bahasa pemrograman mini berbasis kata bahasa Indonesia",
5
5
  "exports": {
6
6
  ".": {