tojscript 1.0.0__tar.gz → 1.0.2__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.
- {tojscript-1.0.0 → tojscript-1.0.2}/PKG-INFO +1 -1
- tojscript-1.0.2/README.md +22 -0
- {tojscript-1.0.0 → tojscript-1.0.2}/setup.py +1 -1
- {tojscript-1.0.0 → tojscript-1.0.2}/tojscript/__init__.py +46 -10
- {tojscript-1.0.0 → tojscript-1.0.2}/tojscript.egg-info/PKG-INFO +1 -1
- {tojscript-1.0.0 → tojscript-1.0.2}/tojscript.egg-info/SOURCES.txt +0 -1
- tojscript-1.0.0/README.md +0 -24
- tojscript-1.0.0/tojscript/__init__(1).py +0 -122
- {tojscript-1.0.0 → tojscript-1.0.2}/setup.cfg +0 -0
- {tojscript-1.0.0 → tojscript-1.0.2}/tojscript.egg-info/dependency_links.txt +0 -0
- {tojscript-1.0.0 → tojscript-1.0.2}/tojscript.egg-info/entry_points.txt +0 -0
- {tojscript-1.0.0 → tojscript-1.0.2}/tojscript.egg-info/requires.txt +0 -0
- {tojscript-1.0.0 → tojscript-1.0.2}/tojscript.egg-info/top_level.txt +0 -0
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# TojScript 🇹🇯
|
|
2
|
+
Язык программирования на таджикском
|
|
3
|
+
|
|
4
|
+
## Установка
|
|
5
|
+
```
|
|
6
|
+
pip install tojscript
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
## Использование
|
|
10
|
+
```
|
|
11
|
+
toj main.toj
|
|
12
|
+
toj main.py
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Пример (main.toj)
|
|
16
|
+
```
|
|
17
|
+
оғоз() {
|
|
18
|
+
a = бутун(ворид())
|
|
19
|
+
b = бутун(ворид())
|
|
20
|
+
чоп(a+b)
|
|
21
|
+
}
|
|
22
|
+
```
|
|
@@ -57,61 +57,94 @@ def хурд(s): return str(s).lower()
|
|
|
57
57
|
def min_tj(*args): return min(*args)
|
|
58
58
|
def max_tj(*args): return max(*args)
|
|
59
59
|
|
|
60
|
+
_input_buffer = []
|
|
61
|
+
def toj_input(prompt=""):
|
|
62
|
+
global _input_buffer
|
|
63
|
+
while not _input_buffer:
|
|
64
|
+
line = input(prompt)
|
|
65
|
+
parts = line.split()
|
|
66
|
+
if len(parts) > 1:
|
|
67
|
+
_input_buffer = parts
|
|
68
|
+
else:
|
|
69
|
+
return line.strip()
|
|
70
|
+
return _input_buffer.pop(0)
|
|
71
|
+
|
|
72
|
+
TOJ_GLOBALS = {
|
|
73
|
+
"toj_print": toj_print, "brb": brb, "nbr": nbr,
|
|
74
|
+
"fakt": fakt, "fibonachi": fibonachi, "musb": musb,
|
|
75
|
+
"darozi": darozi, "ilova": ilova, "pok": pok,
|
|
76
|
+
"калон": калон, "хурд": хурд,
|
|
77
|
+
"min_tj": min_tj, "max_tj": max_tj,
|
|
78
|
+
"toj_input": toj_input, "input": toj_input, "print": print
|
|
79
|
+
}
|
|
80
|
+
|
|
60
81
|
def toj_to_python(code):
|
|
82
|
+
code = re.sub(r'^\s*import\s+tojscript\s*$', '', code, flags=re.MULTILINE)
|
|
83
|
+
|
|
61
84
|
translations = {
|
|
62
85
|
"агар": "if", "дигар": "else", "чоп": "toj_print",
|
|
63
|
-
"ворид": "
|
|
86
|
+
"ворид": "toj_input", "барои": "for", "дар": "in",
|
|
64
87
|
"функсия": "def", "баргардон": "return",
|
|
65
88
|
"бутун": "int", "сатр": "str",
|
|
66
89
|
"брб": "brb", "нбр": "nbr", "факт": "fakt",
|
|
67
90
|
"фибоначи": "fibonachi", "мусб": "musb",
|
|
68
91
|
"дарозӣ": "darozi", "мин": "min_tj", "макс": "max_tj",
|
|
69
92
|
}
|
|
93
|
+
|
|
70
94
|
lines = code.split("\n")
|
|
71
95
|
new_lines = []
|
|
72
96
|
indent = 0
|
|
97
|
+
|
|
73
98
|
for line in lines:
|
|
74
99
|
stripped = line.strip()
|
|
75
100
|
stripped = re.sub(r'(\w+)\.дарозӣ', r'darozi(\1)', stripped)
|
|
76
101
|
stripped = re.sub(r'(\w+)\.калон\(\)', r'калон(\1)', stripped)
|
|
77
102
|
stripped = re.sub(r'(\w+)\.хурд\(\)', r'хурд(\1)', stripped)
|
|
103
|
+
|
|
78
104
|
if not stripped:
|
|
79
105
|
continue
|
|
106
|
+
|
|
80
107
|
while stripped.startswith("}"):
|
|
81
108
|
indent = max(indent - 1, 0)
|
|
82
109
|
stripped = stripped[1:].strip()
|
|
110
|
+
|
|
83
111
|
if not stripped:
|
|
84
112
|
continue
|
|
113
|
+
|
|
85
114
|
if stripped.startswith("оғоз()"):
|
|
86
115
|
new_lines.append(" " * indent + "if True:")
|
|
87
116
|
indent += 1
|
|
88
117
|
continue
|
|
118
|
+
|
|
89
119
|
if stripped == "{":
|
|
90
120
|
indent += 1
|
|
91
121
|
continue
|
|
122
|
+
|
|
92
123
|
for toj, py in translations.items():
|
|
93
124
|
stripped = re.sub(rf'\b{toj}\s*\(', f'{py}(', stripped)
|
|
125
|
+
|
|
94
126
|
if "{" in stripped:
|
|
95
127
|
stripped = stripped.replace("{", ":").replace("::", ":")
|
|
96
128
|
new_lines.append(" " * indent + stripped)
|
|
97
129
|
indent += 1
|
|
98
130
|
else:
|
|
99
131
|
new_lines.append(" " * indent + stripped)
|
|
132
|
+
|
|
100
133
|
return "\n".join(new_lines)
|
|
101
134
|
|
|
135
|
+
def runs(code):
|
|
136
|
+
python_code = toj_to_python(code)
|
|
137
|
+
try:
|
|
138
|
+
exec(python_code, TOJ_GLOBALS)
|
|
139
|
+
except Exception as e:
|
|
140
|
+
print("Хато:", e)
|
|
141
|
+
|
|
102
142
|
def run(filename):
|
|
103
143
|
with open(filename, "r", encoding="utf-8") as f:
|
|
104
144
|
code = f.read()
|
|
105
145
|
python_code = toj_to_python(code)
|
|
106
146
|
try:
|
|
107
|
-
exec(python_code,
|
|
108
|
-
"toj_print": toj_print, "brb": brb, "nbr": nbr,
|
|
109
|
-
"fakt": fakt, "fibonachi": fibonachi, "musb": musb,
|
|
110
|
-
"darozi": darozi, "ilova": ilova, "pok": pok,
|
|
111
|
-
"калон": калон, "хурд": хурд,
|
|
112
|
-
"min_tj": min_tj, "max_tj": max_tj,
|
|
113
|
-
"input": input, "print": print
|
|
114
|
-
})
|
|
147
|
+
exec(python_code, TOJ_GLOBALS)
|
|
115
148
|
except Exception as e:
|
|
116
149
|
print("Хато:", e)
|
|
117
150
|
|
|
@@ -119,4 +152,7 @@ def main():
|
|
|
119
152
|
if len(sys.argv) > 1:
|
|
120
153
|
run(sys.argv[1])
|
|
121
154
|
else:
|
|
122
|
-
|
|
155
|
+
run("main.toj")
|
|
156
|
+
|
|
157
|
+
if __name__ == "__main__":
|
|
158
|
+
main()
|
tojscript-1.0.0/README.md
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
# TojScript 🇹🇯
|
|
2
|
-
|
|
3
|
-
Забони барномасозии тоҷикӣ / Язык программирования на таджикском
|
|
4
|
-
|
|
5
|
-
## Насб / Установка
|
|
6
|
-
|
|
7
|
-
```
|
|
8
|
-
pip install tojscript
|
|
9
|
-
```
|
|
10
|
-
|
|
11
|
-
## Истифода / Использование
|
|
12
|
-
|
|
13
|
-
```
|
|
14
|
-
toj main.toj
|
|
15
|
-
```
|
|
16
|
-
|
|
17
|
-
## Мисол / Пример (main.toj)
|
|
18
|
-
|
|
19
|
-
```
|
|
20
|
-
оғоз() {
|
|
21
|
-
чоп("Салом","/сабз/")
|
|
22
|
-
чоп("Хато","/сурх/")
|
|
23
|
-
}
|
|
24
|
-
```
|
|
@@ -1,122 +0,0 @@
|
|
|
1
|
-
from colorama import Fore, Style, init
|
|
2
|
-
init()
|
|
3
|
-
import re
|
|
4
|
-
import sys
|
|
5
|
-
|
|
6
|
-
colors = {
|
|
7
|
-
"сабз": Fore.GREEN,
|
|
8
|
-
"сурх": Fore.RED,
|
|
9
|
-
"зард": Fore.YELLOW,
|
|
10
|
-
"кабуд": Fore.BLUE,
|
|
11
|
-
"норинҷӣ": Fore.LIGHTYELLOW_EX,
|
|
12
|
-
"reset": Style.RESET_ALL
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
def toj_print(*args):
|
|
16
|
-
text = ""
|
|
17
|
-
color = ""
|
|
18
|
-
for arg in args:
|
|
19
|
-
if isinstance(arg, str):
|
|
20
|
-
clean = arg.strip("/")
|
|
21
|
-
if clean in colors:
|
|
22
|
-
color = colors[clean]
|
|
23
|
-
continue
|
|
24
|
-
text += str(arg) + " "
|
|
25
|
-
if color:
|
|
26
|
-
print(color + text.strip() + colors["reset"])
|
|
27
|
-
else:
|
|
28
|
-
print(text.strip())
|
|
29
|
-
|
|
30
|
-
def brb(a, b): return a == b
|
|
31
|
-
def nbr(a, b): return a != b
|
|
32
|
-
|
|
33
|
-
def fakt(n):
|
|
34
|
-
n = int(n)
|
|
35
|
-
if n < 0: print("Хато: адад бояд мусбат бошад"); exit()
|
|
36
|
-
result = 1
|
|
37
|
-
for i in range(1, n + 1): result *= i
|
|
38
|
-
return result
|
|
39
|
-
|
|
40
|
-
def fibonachi(n):
|
|
41
|
-
n = int(n)
|
|
42
|
-
if n <= 0: print("Хато: адад бояд > 0 бошад"); exit()
|
|
43
|
-
a, b = 0, 1
|
|
44
|
-
for _ in range(n - 1): a, b = b, a + b
|
|
45
|
-
return b
|
|
46
|
-
|
|
47
|
-
def musb(x): return abs(int(x))
|
|
48
|
-
|
|
49
|
-
def darozi(x):
|
|
50
|
-
try: return len(x)
|
|
51
|
-
except: print("Хато: дарозӣ танҳо барои сатр ё рӯйхат аст"); exit()
|
|
52
|
-
|
|
53
|
-
def ilova(arr, x): arr.append(x); return arr
|
|
54
|
-
def pok(arr, i): return arr[i]
|
|
55
|
-
def калон(s): return str(s).upper()
|
|
56
|
-
def хурд(s): return str(s).lower()
|
|
57
|
-
def min_tj(*args): return min(*args)
|
|
58
|
-
def max_tj(*args): return max(*args)
|
|
59
|
-
|
|
60
|
-
def toj_to_python(code):
|
|
61
|
-
translations = {
|
|
62
|
-
"агар": "if", "дигар": "else", "чоп": "toj_print",
|
|
63
|
-
"ворид": "input", "барои": "for", "дар": "in",
|
|
64
|
-
"функсия": "def", "баргардон": "return",
|
|
65
|
-
"бутун": "int", "сатр": "str",
|
|
66
|
-
"брб": "brb", "нбр": "nbr", "факт": "fakt",
|
|
67
|
-
"фибоначи": "fibonachi", "мусб": "musb",
|
|
68
|
-
"дарозӣ": "darozi", "мин": "min_tj", "макс": "max_tj",
|
|
69
|
-
}
|
|
70
|
-
lines = code.split("\n")
|
|
71
|
-
new_lines = []
|
|
72
|
-
indent = 0
|
|
73
|
-
for line in lines:
|
|
74
|
-
stripped = line.strip()
|
|
75
|
-
stripped = re.sub(r'(\w+)\.дарозӣ', r'darozi(\1)', stripped)
|
|
76
|
-
stripped = re.sub(r'(\w+)\.калон\(\)', r'калон(\1)', stripped)
|
|
77
|
-
stripped = re.sub(r'(\w+)\.хурд\(\)', r'хурд(\1)', stripped)
|
|
78
|
-
if not stripped:
|
|
79
|
-
continue
|
|
80
|
-
while stripped.startswith("}"):
|
|
81
|
-
indent = max(indent - 1, 0)
|
|
82
|
-
stripped = stripped[1:].strip()
|
|
83
|
-
if not stripped:
|
|
84
|
-
continue
|
|
85
|
-
if stripped.startswith("оғоз()"):
|
|
86
|
-
new_lines.append(" " * indent + "if True:")
|
|
87
|
-
indent += 1
|
|
88
|
-
continue
|
|
89
|
-
if stripped == "{":
|
|
90
|
-
indent += 1
|
|
91
|
-
continue
|
|
92
|
-
for toj, py in translations.items():
|
|
93
|
-
stripped = re.sub(rf'\b{toj}\s*\(', f'{py}(', stripped)
|
|
94
|
-
if "{" in stripped:
|
|
95
|
-
stripped = stripped.replace("{", ":").replace("::", ":")
|
|
96
|
-
new_lines.append(" " * indent + stripped)
|
|
97
|
-
indent += 1
|
|
98
|
-
else:
|
|
99
|
-
new_lines.append(" " * indent + stripped)
|
|
100
|
-
return "\n".join(new_lines)
|
|
101
|
-
|
|
102
|
-
def run(filename):
|
|
103
|
-
with open(filename, "r", encoding="utf-8") as f:
|
|
104
|
-
code = f.read()
|
|
105
|
-
python_code = toj_to_python(code)
|
|
106
|
-
try:
|
|
107
|
-
exec(python_code, {
|
|
108
|
-
"toj_print": toj_print, "brb": brb, "nbr": nbr,
|
|
109
|
-
"fakt": fakt, "fibonachi": fibonachi, "musb": musb,
|
|
110
|
-
"darozi": darozi, "ilova": ilova, "pok": pok,
|
|
111
|
-
"калон": калон, "хурд": хурд,
|
|
112
|
-
"min_tj": min_tj, "max_tj": max_tj,
|
|
113
|
-
"input": input, "print": print
|
|
114
|
-
})
|
|
115
|
-
except Exception as e:
|
|
116
|
-
print("Хато:", e)
|
|
117
|
-
|
|
118
|
-
def main():
|
|
119
|
-
if len(sys.argv) > 1:
|
|
120
|
-
run(sys.argv[1])
|
|
121
|
-
else:
|
|
122
|
-
print("Истифода: toj fayl.toj")
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|