@arwildo/jawascript 1.0.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.
- package/README.md +71 -0
- package/bin/jawa.js +32 -0
- package/examples/hello.jawa +17 -0
- package/package.json +34 -0
- package/src/translator.js +21 -0
package/README.md
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
# Jawa Script
|
|
2
|
+
|
|
3
|
+
> JavaScript nganggo basa Jawa.
|
|
4
|
+
|
|
5
|
+
Jawa Script adalah **source to source transpiler** kecil yang menerjemahkan file `.jawa` menjadi JavaScript, lalu mengeksekusinya dengan Node.js.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install -g jawa-script
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Usage
|
|
14
|
+
|
|
15
|
+
Buat file `hello.jawa`:
|
|
16
|
+
|
|
17
|
+
```jawa
|
|
18
|
+
ono x = 10;
|
|
19
|
+
ono y = 20;
|
|
20
|
+
|
|
21
|
+
tampilno(x + y);
|
|
22
|
+
|
|
23
|
+
yen (x < y) {
|
|
24
|
+
tampilno("x luwih cilik");
|
|
25
|
+
} yen ora {
|
|
26
|
+
tampilno("x luwih gedhe");
|
|
27
|
+
}
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
Jalankan:
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
jawa hello.jawa
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
Output:
|
|
37
|
+
|
|
38
|
+
```
|
|
39
|
+
30
|
|
40
|
+
x luwih cilik
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## Contoh
|
|
44
|
+
|
|
45
|
+
```jawa
|
|
46
|
+
ono x = 10;
|
|
47
|
+
ono y = 20;
|
|
48
|
+
|
|
49
|
+
tampilno(x + y);
|
|
50
|
+
|
|
51
|
+
yen (x < y) {
|
|
52
|
+
tampilno("x luwih cilik");
|
|
53
|
+
} yen ora {
|
|
54
|
+
tampilno("x luwih gedhe");
|
|
55
|
+
}
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
## Keyword
|
|
59
|
+
|
|
60
|
+
| Jawa | JavaScript |
|
|
61
|
+
| -------- | ----------- |
|
|
62
|
+
| ono | let |
|
|
63
|
+
| tampilno | console.log |
|
|
64
|
+
| yen | if |
|
|
65
|
+
| yen ora | else |
|
|
66
|
+
|
|
67
|
+
## Cara Kerja
|
|
68
|
+
|
|
69
|
+
File `.jawa` dibaca, keyword Jawa diganti dengan JavaScript menggunakan regex word boundary (urutan replacement penting: `yen ora` diproses sebelum `yen`), lalu dieksekusi.
|
|
70
|
+
Jawa Script adalah project eksperimen yang dibuat untuk bersenang senang dan belajar bagaimana bahasa pemrograman sederhana dapat dibuat.
|
|
71
|
+
|
package/bin/jawa.js
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import { readFileSync } from "node:fs";
|
|
4
|
+
import { translate } from "../src/translator.js";
|
|
5
|
+
|
|
6
|
+
const file = process.argv[2];
|
|
7
|
+
|
|
8
|
+
if (!file) {
|
|
9
|
+
console.log("Gunakake: jawa <file.jawa>");
|
|
10
|
+
process.exit(1);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
let source;
|
|
14
|
+
try {
|
|
15
|
+
source = readFileSync(file, "utf8");
|
|
16
|
+
} catch (err) {
|
|
17
|
+
if (err.code === "ENOENT") {
|
|
18
|
+
console.error(`File ora ditemokake: ${file}`);
|
|
19
|
+
process.exit(1);
|
|
20
|
+
}
|
|
21
|
+
console.error(`Ora bisa maca file: ${err.message}`);
|
|
22
|
+
process.exit(1);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const js = translate(source);
|
|
26
|
+
|
|
27
|
+
try {
|
|
28
|
+
new Function(js)();
|
|
29
|
+
} catch (err) {
|
|
30
|
+
console.error(`Error: ${err.message}`);
|
|
31
|
+
process.exit(1);
|
|
32
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
// Hello World ne
|
|
2
|
+
tampilno("piye kabare jagad!");
|
|
3
|
+
|
|
4
|
+
// Variable ne
|
|
5
|
+
ono x = 10;
|
|
6
|
+
ono y = 20;
|
|
7
|
+
|
|
8
|
+
// Print ne
|
|
9
|
+
tampilno(x + y);
|
|
10
|
+
|
|
11
|
+
// If statement ne, ojo lali yo mas e!
|
|
12
|
+
yen (x < y) {
|
|
13
|
+
tampilno("x luwih cilik");
|
|
14
|
+
} yen ora {
|
|
15
|
+
tampilno("x luwih gedhe");
|
|
16
|
+
}
|
|
17
|
+
|
package/package.json
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@arwildo/jawascript",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "JavaScript nganggo basa Jawa",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"bin": {
|
|
7
|
+
"jawa": "./bin/jawa.js"
|
|
8
|
+
},
|
|
9
|
+
"keywords": [
|
|
10
|
+
"jawa",
|
|
11
|
+
"javascript",
|
|
12
|
+
"programming-language",
|
|
13
|
+
"esolang",
|
|
14
|
+
"fun"
|
|
15
|
+
],
|
|
16
|
+
"license": "MIT",
|
|
17
|
+
"files": [
|
|
18
|
+
"bin",
|
|
19
|
+
"src",
|
|
20
|
+
"examples",
|
|
21
|
+
"README.md"
|
|
22
|
+
],
|
|
23
|
+
"engines": {
|
|
24
|
+
"node": ">=14"
|
|
25
|
+
},
|
|
26
|
+
"repository": {
|
|
27
|
+
"type": "git",
|
|
28
|
+
"url": "git+https://github.com/arwildo/jawascript.git"
|
|
29
|
+
},
|
|
30
|
+
"bugs": {
|
|
31
|
+
"url": "https://github.com/arwildo/jawascript/issues"
|
|
32
|
+
},
|
|
33
|
+
"homepage": "https://github.com/arwildo/jawascript#readme"
|
|
34
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
const KEYWORDS = [
|
|
2
|
+
["yen ora", "else"],
|
|
3
|
+
["yen", "if"],
|
|
4
|
+
["tampilno", "console.log"],
|
|
5
|
+
["ono", "let"],
|
|
6
|
+
];
|
|
7
|
+
|
|
8
|
+
function escapeRegex(str) {
|
|
9
|
+
return str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function translate(code) {
|
|
13
|
+
let js = code;
|
|
14
|
+
|
|
15
|
+
for (const [from, to] of KEYWORDS) {
|
|
16
|
+
const regex = new RegExp(`\\b${escapeRegex(from)}\\b`, "g");
|
|
17
|
+
js = js.replace(regex, to);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
return js;
|
|
21
|
+
}
|