indonesian_script 0.1.10__tar.gz
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.
- indonesian_script-0.1.10/PKG-INFO +117 -0
- indonesian_script-0.1.10/README.md +91 -0
- indonesian_script-0.1.10/indonesian_script/Interpreter/AST_node/__init__.py +2 -0
- indonesian_script-0.1.10/indonesian_script/Interpreter/AST_node/ast_nodes.py +267 -0
- indonesian_script-0.1.10/indonesian_script/Interpreter/Builtins/KEYWORD.py +96 -0
- indonesian_script-0.1.10/indonesian_script/Interpreter/Builtins/TYPES.py +28 -0
- indonesian_script-0.1.10/indonesian_script/Interpreter/Builtins/__init__.py +2 -0
- indonesian_script-0.1.10/indonesian_script/Interpreter/Builtins/builtins.py +140 -0
- indonesian_script-0.1.10/indonesian_script/Interpreter/__init__.py +4 -0
- indonesian_script-0.1.10/indonesian_script/Interpreter/interpreter.py +988 -0
- indonesian_script-0.1.10/indonesian_script/Interpreter/transformer.py +560 -0
- indonesian_script-0.1.10/indonesian_script/__init__.py +12 -0
- indonesian_script-0.1.10/indonesian_script/__main__.py +11 -0
- indonesian_script-0.1.10/indonesian_script/cli/__init__.py +2 -0
- indonesian_script-0.1.10/indonesian_script/cli/main.py +196 -0
- indonesian_script-0.1.10/indonesian_script/main.py +143 -0
- indonesian_script-0.1.10/indonesian_script.egg-info/PKG-INFO +117 -0
- indonesian_script-0.1.10/indonesian_script.egg-info/SOURCES.txt +22 -0
- indonesian_script-0.1.10/indonesian_script.egg-info/dependency_links.txt +1 -0
- indonesian_script-0.1.10/indonesian_script.egg-info/entry_points.txt +2 -0
- indonesian_script-0.1.10/indonesian_script.egg-info/requires.txt +3 -0
- indonesian_script-0.1.10/indonesian_script.egg-info/top_level.txt +1 -0
- indonesian_script-0.1.10/setup.cfg +4 -0
- indonesian_script-0.1.10/setup.py +37 -0
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: indonesian_script
|
|
3
|
+
Version: 0.1.10
|
|
4
|
+
Summary: A programming language designed to make life easier for the Indonesian people
|
|
5
|
+
Home-page: https://github.com/yourusername/is
|
|
6
|
+
Author: Elang muhammad
|
|
7
|
+
Author-email: elangmahammad888@gmail.com
|
|
8
|
+
Classifier: Programming Language :: Python :: 3
|
|
9
|
+
Classifier: Development Status :: 4 - Beta
|
|
10
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
11
|
+
Classifier: Operating System :: OS Independent
|
|
12
|
+
Requires-Python: >=3.8
|
|
13
|
+
Description-Content-Type: text/markdown
|
|
14
|
+
Requires-Dist: lark-parser>=0.12.0
|
|
15
|
+
Requires-Dist: regex>=2026.1.15
|
|
16
|
+
Requires-Dist: colorama>=0.4.6
|
|
17
|
+
Dynamic: author
|
|
18
|
+
Dynamic: author-email
|
|
19
|
+
Dynamic: classifier
|
|
20
|
+
Dynamic: description
|
|
21
|
+
Dynamic: description-content-type
|
|
22
|
+
Dynamic: home-page
|
|
23
|
+
Dynamic: requires-dist
|
|
24
|
+
Dynamic: requires-python
|
|
25
|
+
Dynamic: summary
|
|
26
|
+
|
|
27
|
+
# Indonesian Script
|
|
28
|
+
|
|
29
|
+
Bahasa pemrograman dalam Bahasa Indonesia - Programming language in Indonesian
|
|
30
|
+
|
|
31
|
+
## Instalasi
|
|
32
|
+
|
|
33
|
+
### Yang dibutuhkan
|
|
34
|
+
|
|
35
|
+
```txt
|
|
36
|
+
python>=3.12
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
### Dan jalankan
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
git clone https://github.com/Elang-elang/is.git
|
|
43
|
+
cd is
|
|
44
|
+
./instalasi
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
## Penggunaan CLI
|
|
48
|
+
|
|
49
|
+
### Menjalankan file
|
|
50
|
+
|
|
51
|
+
```bash
|
|
52
|
+
is run program.is
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
### Melihat AST (Abstract Syntax Tree)
|
|
56
|
+
|
|
57
|
+
```bash
|
|
58
|
+
is ast program.is
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
### Mode REPL interaktif
|
|
62
|
+
|
|
63
|
+
```bash
|
|
64
|
+
is repl
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
### Melihat versi
|
|
68
|
+
|
|
69
|
+
```bash
|
|
70
|
+
is version
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
### Contoh Kode
|
|
74
|
+
|
|
75
|
+
```is
|
|
76
|
+
// hello.is
|
|
77
|
+
tuliskan "Halo, Dunia!"; // untuk primitif node
|
|
78
|
+
tampilkan("Halo, Dunia!"); // untuk modern node
|
|
79
|
+
|
|
80
|
+
teks nama = "Budi";
|
|
81
|
+
angka umur = 25;
|
|
82
|
+
|
|
83
|
+
jika (umur >= 18) maka {
|
|
84
|
+
tuliskan(nama + " sudah dewasa");
|
|
85
|
+
} namun tidak {
|
|
86
|
+
tuliskan(nama + " masih anak-anak");
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
angka faktorial(angka n) {
|
|
90
|
+
jika (n <= 1) maka {
|
|
91
|
+
kembalikan 1;
|
|
92
|
+
}
|
|
93
|
+
kembalikan n * faktorial(n - 1);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
tampilkan("Faktorial 5 = " + faktorial(5));
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
## Fitur
|
|
100
|
+
|
|
101
|
+
· ✅ Variabel (var_decl, final_decl, def_decl)
|
|
102
|
+
· ✅ Tipe data: teks, angka, desimal, boolean, daftar, kamus
|
|
103
|
+
· ✅ Operator aritmatika dan logika
|
|
104
|
+
· ✅ Control flow: jika, selama, untuk
|
|
105
|
+
· ✅ Function dengan return dan throw
|
|
106
|
+
· ✅ Lambda expression
|
|
107
|
+
· ✅ Array dan Dictionary
|
|
108
|
+
· ✅ Pointer (& dan *)
|
|
109
|
+
· ✅ Try-catch-finally
|
|
110
|
+
· ✅ Input/Output (tuliskan, bacalah)
|
|
111
|
+
· ✅ REPL interaktif
|
|
112
|
+
|
|
113
|
+
## Lisensi
|
|
114
|
+
|
|
115
|
+
[MIT](./indonesian_script/License)
|
|
116
|
+
|
|
117
|
+
```
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
# Indonesian Script
|
|
2
|
+
|
|
3
|
+
Bahasa pemrograman dalam Bahasa Indonesia - Programming language in Indonesian
|
|
4
|
+
|
|
5
|
+
## Instalasi
|
|
6
|
+
|
|
7
|
+
### Yang dibutuhkan
|
|
8
|
+
|
|
9
|
+
```txt
|
|
10
|
+
python>=3.12
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
### Dan jalankan
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
git clone https://github.com/Elang-elang/is.git
|
|
17
|
+
cd is
|
|
18
|
+
./instalasi
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Penggunaan CLI
|
|
22
|
+
|
|
23
|
+
### Menjalankan file
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
is run program.is
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
### Melihat AST (Abstract Syntax Tree)
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
is ast program.is
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
### Mode REPL interaktif
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
is repl
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
### Melihat versi
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
is version
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
### Contoh Kode
|
|
48
|
+
|
|
49
|
+
```is
|
|
50
|
+
// hello.is
|
|
51
|
+
tuliskan "Halo, Dunia!"; // untuk primitif node
|
|
52
|
+
tampilkan("Halo, Dunia!"); // untuk modern node
|
|
53
|
+
|
|
54
|
+
teks nama = "Budi";
|
|
55
|
+
angka umur = 25;
|
|
56
|
+
|
|
57
|
+
jika (umur >= 18) maka {
|
|
58
|
+
tuliskan(nama + " sudah dewasa");
|
|
59
|
+
} namun tidak {
|
|
60
|
+
tuliskan(nama + " masih anak-anak");
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
angka faktorial(angka n) {
|
|
64
|
+
jika (n <= 1) maka {
|
|
65
|
+
kembalikan 1;
|
|
66
|
+
}
|
|
67
|
+
kembalikan n * faktorial(n - 1);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
tampilkan("Faktorial 5 = " + faktorial(5));
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
## Fitur
|
|
74
|
+
|
|
75
|
+
· ✅ Variabel (var_decl, final_decl, def_decl)
|
|
76
|
+
· ✅ Tipe data: teks, angka, desimal, boolean, daftar, kamus
|
|
77
|
+
· ✅ Operator aritmatika dan logika
|
|
78
|
+
· ✅ Control flow: jika, selama, untuk
|
|
79
|
+
· ✅ Function dengan return dan throw
|
|
80
|
+
· ✅ Lambda expression
|
|
81
|
+
· ✅ Array dan Dictionary
|
|
82
|
+
· ✅ Pointer (& dan *)
|
|
83
|
+
· ✅ Try-catch-finally
|
|
84
|
+
· ✅ Input/Output (tuliskan, bacalah)
|
|
85
|
+
· ✅ REPL interaktif
|
|
86
|
+
|
|
87
|
+
## Lisensi
|
|
88
|
+
|
|
89
|
+
[MIT](./indonesian_script/License)
|
|
90
|
+
|
|
91
|
+
```
|
|
@@ -0,0 +1,267 @@
|
|
|
1
|
+
# ast_nodes.py
|
|
2
|
+
from dataclasses import dataclass, field
|
|
3
|
+
from typing import Any, Dict, Tuple, List, Optional, Union
|
|
4
|
+
|
|
5
|
+
class Node:
|
|
6
|
+
"""Base class for all AST nodes."""
|
|
7
|
+
pass
|
|
8
|
+
|
|
9
|
+
# --- Program & Blocks ---
|
|
10
|
+
@dataclass
|
|
11
|
+
class Program(Node):
|
|
12
|
+
statements: Optional[List['Statement']]
|
|
13
|
+
|
|
14
|
+
@dataclass
|
|
15
|
+
class Block(Node):
|
|
16
|
+
statements: Optional[List['Statement']]
|
|
17
|
+
|
|
18
|
+
# --- Statements ---
|
|
19
|
+
class Statement(Node):
|
|
20
|
+
pass
|
|
21
|
+
|
|
22
|
+
@dataclass
|
|
23
|
+
class VarDecl(Statement):
|
|
24
|
+
type_ann: 'Type'
|
|
25
|
+
name: str
|
|
26
|
+
value: Optional['Expression']
|
|
27
|
+
|
|
28
|
+
@dataclass
|
|
29
|
+
class FinalDecl(Statement):
|
|
30
|
+
type_ann: 'Type'
|
|
31
|
+
name: str
|
|
32
|
+
value: 'Expression'
|
|
33
|
+
|
|
34
|
+
@dataclass
|
|
35
|
+
class DefDecl(Statement):
|
|
36
|
+
type_ann: 'Type'
|
|
37
|
+
name: str
|
|
38
|
+
|
|
39
|
+
@dataclass
|
|
40
|
+
class AliasDecl(Statement):
|
|
41
|
+
alias: str
|
|
42
|
+
target: str
|
|
43
|
+
|
|
44
|
+
@dataclass
|
|
45
|
+
class Redecl(Statement):
|
|
46
|
+
name: str
|
|
47
|
+
value: 'Expression'
|
|
48
|
+
|
|
49
|
+
@dataclass
|
|
50
|
+
class PointerDecl(Statement):
|
|
51
|
+
name: str
|
|
52
|
+
target: str
|
|
53
|
+
|
|
54
|
+
@dataclass
|
|
55
|
+
class UnpointerDecl(Statement):
|
|
56
|
+
name: str
|
|
57
|
+
target: str
|
|
58
|
+
|
|
59
|
+
@dataclass
|
|
60
|
+
class WriteStmt(Statement):
|
|
61
|
+
target: str
|
|
62
|
+
|
|
63
|
+
@dataclass
|
|
64
|
+
class ReadStmt(Statement):
|
|
65
|
+
expr: 'Expression'
|
|
66
|
+
|
|
67
|
+
@dataclass
|
|
68
|
+
class CtrlFlow(Statement):
|
|
69
|
+
pass
|
|
70
|
+
|
|
71
|
+
@dataclass
|
|
72
|
+
class IfCtrl(CtrlFlow):
|
|
73
|
+
if_stmt: 'IfStmt'
|
|
74
|
+
elif_stmt: Optional[List['ElifStmt']]
|
|
75
|
+
else_stmt: Optional['ElseStmt']
|
|
76
|
+
|
|
77
|
+
@dataclass
|
|
78
|
+
class IfStmt(CtrlFlow):
|
|
79
|
+
condition: 'Expression'
|
|
80
|
+
body: Block
|
|
81
|
+
|
|
82
|
+
@dataclass
|
|
83
|
+
class ElifStmt(CtrlFlow):
|
|
84
|
+
condition: 'Expression'
|
|
85
|
+
body: Block
|
|
86
|
+
|
|
87
|
+
@dataclass
|
|
88
|
+
class ElseStmt(CtrlFlow):
|
|
89
|
+
body: Block
|
|
90
|
+
|
|
91
|
+
@dataclass
|
|
92
|
+
class WhileStmt(CtrlFlow):
|
|
93
|
+
condition: 'Expression'
|
|
94
|
+
body: Block
|
|
95
|
+
|
|
96
|
+
@dataclass
|
|
97
|
+
class ForStmt(CtrlFlow):
|
|
98
|
+
expr: 'ForExpr'
|
|
99
|
+
body: Block
|
|
100
|
+
|
|
101
|
+
@dataclass
|
|
102
|
+
class ForExpr(CtrlFlow):
|
|
103
|
+
name: str
|
|
104
|
+
target: List[Any]
|
|
105
|
+
|
|
106
|
+
@dataclass
|
|
107
|
+
class TryCtrl(CtrlFlow):
|
|
108
|
+
try_stmt: 'TryStmt'
|
|
109
|
+
catch_stmt: 'CatchStmt'
|
|
110
|
+
finnaly_stmt: Optional['FinnalyStmt']
|
|
111
|
+
|
|
112
|
+
@dataclass
|
|
113
|
+
class TryStmt(CtrlFlow):
|
|
114
|
+
body: Block
|
|
115
|
+
|
|
116
|
+
@dataclass
|
|
117
|
+
class CatchStmt(CtrlFlow):
|
|
118
|
+
name: str
|
|
119
|
+
body: Block
|
|
120
|
+
|
|
121
|
+
@dataclass
|
|
122
|
+
class FinallyStmt(CtrlFlow):
|
|
123
|
+
body: Block
|
|
124
|
+
|
|
125
|
+
# --- Expressions ---
|
|
126
|
+
class Expression(Node):
|
|
127
|
+
pass
|
|
128
|
+
|
|
129
|
+
@dataclass
|
|
130
|
+
class BinaryOp(Expression):
|
|
131
|
+
op: str # '+', '-', '*', '/', '%', '==', '!=', '>=', '>', '<=', '<', 'dan', 'atau', 'dalam', 'tidak dalam'
|
|
132
|
+
left: Expression
|
|
133
|
+
right: Expression
|
|
134
|
+
|
|
135
|
+
@dataclass
|
|
136
|
+
class UnaryOp(Expression):
|
|
137
|
+
op: str # 'tidak'
|
|
138
|
+
expr: Expression
|
|
139
|
+
|
|
140
|
+
@dataclass
|
|
141
|
+
class Literal(Expression):
|
|
142
|
+
value: Any
|
|
143
|
+
|
|
144
|
+
@dataclass
|
|
145
|
+
class Variable(Expression):
|
|
146
|
+
name: str
|
|
147
|
+
value: Any = None
|
|
148
|
+
|
|
149
|
+
@dataclass
|
|
150
|
+
class GetAttr(Expression):
|
|
151
|
+
obj: Expression
|
|
152
|
+
attr: str
|
|
153
|
+
|
|
154
|
+
@dataclass
|
|
155
|
+
class GetIndex(Expression):
|
|
156
|
+
obj: Expression
|
|
157
|
+
index: Expression
|
|
158
|
+
|
|
159
|
+
@dataclass
|
|
160
|
+
class CallFunc(Expression):
|
|
161
|
+
func: Expression
|
|
162
|
+
params: 'CallParameter'
|
|
163
|
+
|
|
164
|
+
@dataclass
|
|
165
|
+
class CallParameter(Expression):
|
|
166
|
+
args: List['CallArgument']
|
|
167
|
+
|
|
168
|
+
@dataclass
|
|
169
|
+
class CallArgument(Expression):
|
|
170
|
+
name: Optional[str]
|
|
171
|
+
value: Expression
|
|
172
|
+
|
|
173
|
+
@dataclass
|
|
174
|
+
class LambdaFunc(Expression):
|
|
175
|
+
params: 'Parameter'
|
|
176
|
+
expr: Expression
|
|
177
|
+
|
|
178
|
+
@dataclass
|
|
179
|
+
class TypeOf(Expression):
|
|
180
|
+
var: Variable
|
|
181
|
+
|
|
182
|
+
@dataclass
|
|
183
|
+
class IsStmt(Expression): # sebenarnya ini expression boolean
|
|
184
|
+
left: str
|
|
185
|
+
right: str
|
|
186
|
+
negated: bool = False
|
|
187
|
+
|
|
188
|
+
|
|
189
|
+
# --- Functions ---
|
|
190
|
+
class FunctionNode(Node):
|
|
191
|
+
"Untuk attribute dan kerangka function"
|
|
192
|
+
pass
|
|
193
|
+
|
|
194
|
+
@dataclass
|
|
195
|
+
class Function(FunctionNode):
|
|
196
|
+
type_ann: 'Type'
|
|
197
|
+
name: str
|
|
198
|
+
params: 'Parameter'
|
|
199
|
+
inner: 'Block'
|
|
200
|
+
|
|
201
|
+
@dataclass
|
|
202
|
+
class Parameter(FunctionNode):
|
|
203
|
+
args: List['Argument']
|
|
204
|
+
|
|
205
|
+
@dataclass
|
|
206
|
+
class Generic(FunctionNode):
|
|
207
|
+
args: Optional[List['Argument']]
|
|
208
|
+
|
|
209
|
+
@dataclass
|
|
210
|
+
class Argument(FunctionNode):
|
|
211
|
+
type_ann: 'Type'
|
|
212
|
+
name: str
|
|
213
|
+
value: Optional[Expression] = None
|
|
214
|
+
|
|
215
|
+
@dataclass
|
|
216
|
+
class Return(Expression):
|
|
217
|
+
expr: Expression
|
|
218
|
+
|
|
219
|
+
@dataclass
|
|
220
|
+
class Throw(Expression):
|
|
221
|
+
name: str
|
|
222
|
+
expr: Expression
|
|
223
|
+
|
|
224
|
+
# --- Module ---
|
|
225
|
+
class Module(Node):
|
|
226
|
+
"""Dataclass terkait module"""
|
|
227
|
+
pass
|
|
228
|
+
|
|
229
|
+
@dataclass
|
|
230
|
+
class Export(Module):
|
|
231
|
+
exports: List['ExportArgument']
|
|
232
|
+
|
|
233
|
+
@dataclass
|
|
234
|
+
class ExportArgument(Module):
|
|
235
|
+
name: Variable
|
|
236
|
+
alias: Optional[str]
|
|
237
|
+
|
|
238
|
+
@dataclass
|
|
239
|
+
class Import(Module):
|
|
240
|
+
imports: List['ImportArgument']
|
|
241
|
+
from_path: 'PathID'
|
|
242
|
+
|
|
243
|
+
@dataclass
|
|
244
|
+
class ImportArgument(Module):
|
|
245
|
+
name: str
|
|
246
|
+
alias: Optional[str]
|
|
247
|
+
|
|
248
|
+
@dataclass
|
|
249
|
+
class PathID(Module):
|
|
250
|
+
path: List['PathArg']
|
|
251
|
+
|
|
252
|
+
@dataclass
|
|
253
|
+
class PathArg(Module):
|
|
254
|
+
arg: str
|
|
255
|
+
|
|
256
|
+
# --- Types ---
|
|
257
|
+
class Type(Node):
|
|
258
|
+
pass
|
|
259
|
+
|
|
260
|
+
@dataclass
|
|
261
|
+
class BasicType(Type):
|
|
262
|
+
name: str # 'teks', 'angka', dll.
|
|
263
|
+
|
|
264
|
+
@dataclass
|
|
265
|
+
class ArrayType(Type):
|
|
266
|
+
length: int # 0 untuk dinamis
|
|
267
|
+
element_type: Type
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
from decimal import Decimal
|
|
2
|
+
|
|
3
|
+
class kekosongan(object):
|
|
4
|
+
def __call__(cls, isi=''):
|
|
5
|
+
return not bool(isi)
|
|
6
|
+
def __repr__(self):
|
|
7
|
+
return '<tipe \'kekosongan\'>'
|
|
8
|
+
|
|
9
|
+
@staticmethod
|
|
10
|
+
def __instancecheck__(instance, /):
|
|
11
|
+
return isinstance(instance, kekosongan)
|
|
12
|
+
|
|
13
|
+
class kosong(kekosongan):
|
|
14
|
+
def __init__(self):
|
|
15
|
+
pass
|
|
16
|
+
def __repr__(self):
|
|
17
|
+
return 'kosong'
|
|
18
|
+
def __str__(self):
|
|
19
|
+
return ''
|
|
20
|
+
def __int__(self):
|
|
21
|
+
return 0
|
|
22
|
+
def __float__(self):
|
|
23
|
+
return 0.0
|
|
24
|
+
def __bool__(self):
|
|
25
|
+
return False
|
|
26
|
+
def __eq__(self, value, /):
|
|
27
|
+
return bool(kosong == value) or bool(None == value)
|
|
28
|
+
def __ne__(self, value, /):
|
|
29
|
+
return not self.__eq__(value)
|
|
30
|
+
|
|
31
|
+
class tipe(type):
|
|
32
|
+
"tipe utama"
|
|
33
|
+
pass
|
|
34
|
+
|
|
35
|
+
class teks(tipe, str):
|
|
36
|
+
"string"
|
|
37
|
+
pass
|
|
38
|
+
|
|
39
|
+
class desimal(tipe, Decimal):
|
|
40
|
+
pass
|
|
41
|
+
|
|
42
|
+
class angka(tipe, int):
|
|
43
|
+
pass
|
|
44
|
+
|
|
45
|
+
class kondisi(tipe):
|
|
46
|
+
"boolean"
|
|
47
|
+
__value__ = benar
|
|
48
|
+
def __call__(cls, value=benar):
|
|
49
|
+
if value:
|
|
50
|
+
return benar
|
|
51
|
+
else:
|
|
52
|
+
return salah
|
|
53
|
+
|
|
54
|
+
@staticmethod
|
|
55
|
+
def __instancecheck__(instance, /):
|
|
56
|
+
return isinstance(kondisi, instance)
|
|
57
|
+
|
|
58
|
+
def __repr__(self):
|
|
59
|
+
return "<tipe 'kondisi'>"
|
|
60
|
+
|
|
61
|
+
class salah:
|
|
62
|
+
def __init__(self):
|
|
63
|
+
pass
|
|
64
|
+
def __repr__(self):
|
|
65
|
+
return 'salah'
|
|
66
|
+
def __str__(self):
|
|
67
|
+
return 'benar'
|
|
68
|
+
def __int__(self):
|
|
69
|
+
return 0
|
|
70
|
+
def __float__(self):
|
|
71
|
+
return 0.0
|
|
72
|
+
def __bool__(self):
|
|
73
|
+
return False
|
|
74
|
+
def __eq__(self, value, /):
|
|
75
|
+
return bool(salah == value) or bool(False == value)
|
|
76
|
+
def __ne__(self, value, /):
|
|
77
|
+
return not self.__eq__(value)
|
|
78
|
+
|
|
79
|
+
class benar:
|
|
80
|
+
def __init__(self):
|
|
81
|
+
pass
|
|
82
|
+
def __repr__(self):
|
|
83
|
+
return 'benar'
|
|
84
|
+
def __str__(self):
|
|
85
|
+
return 'benar'
|
|
86
|
+
def __int__(self):
|
|
87
|
+
return 1
|
|
88
|
+
def __float__(self):
|
|
89
|
+
return 1.0
|
|
90
|
+
def __bool__(self):
|
|
91
|
+
return True
|
|
92
|
+
def __eq__(self, value, /):
|
|
93
|
+
return bool(benar == value) or bool(True == value)
|
|
94
|
+
def __ne__(self, value, /):
|
|
95
|
+
return not self.__eq__(value)
|
|
96
|
+
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
|
|
2
|
+
class teks(str):
|
|
3
|
+
def __init__(self, chrs='', /):
|
|
4
|
+
self._chrs = str(chrs)
|
|
5
|
+
|
|
6
|
+
def kapitalkan(self, /):
|
|
7
|
+
return self._chrs.capitalize()
|
|
8
|
+
|
|
9
|
+
def simpul(self, /):
|
|
10
|
+
return self._chrs.casefold()
|
|
11
|
+
|
|
12
|
+
def ditengah(self, panjang, pengisi=' ', /):
|
|
13
|
+
return self._chrs.center(panjang, pengisi)
|
|
14
|
+
|
|
15
|
+
def hitung(self, args, /):
|
|
16
|
+
if isinstance(args, str):
|
|
17
|
+
return self._chrs.count(args)
|
|
18
|
+
elif isinstance(args, (list, set, tuple)):
|
|
19
|
+
result = []
|
|
20
|
+
for arg in args:
|
|
21
|
+
if not isinstance(arg, str):
|
|
22
|
+
raise TypeError(f"must be str, not {type(arg).__name__}")
|
|
23
|
+
result.append(self._chrs(arg))
|
|
24
|
+
return result
|
|
25
|
+
else:
|
|
26
|
+
raise TypeError(f"must be str, not {type(arg).__name__}")
|
|
27
|
+
|
|
28
|
+
def diakhiri(self, )
|