tojscript 1.0.0__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/PKG-INFO +5 -0
- tojscript-1.0.0/README.md +24 -0
- tojscript-1.0.0/setup.cfg +4 -0
- tojscript-1.0.0/setup.py +13 -0
- tojscript-1.0.0/tojscript/__init__(1).py +122 -0
- tojscript-1.0.0/tojscript/__init__.py +122 -0
- tojscript-1.0.0/tojscript.egg-info/PKG-INFO +5 -0
- tojscript-1.0.0/tojscript.egg-info/SOURCES.txt +10 -0
- tojscript-1.0.0/tojscript.egg-info/dependency_links.txt +1 -0
- tojscript-1.0.0/tojscript.egg-info/entry_points.txt +2 -0
- tojscript-1.0.0/tojscript.egg-info/requires.txt +1 -0
- tojscript-1.0.0/tojscript.egg-info/top_level.txt +1 -0
tojscript-1.0.0/PKG-INFO
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
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
|
+
```
|
tojscript-1.0.0/setup.py
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
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")
|
|
@@ -0,0 +1,122 @@
|
|
|
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")
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
README.md
|
|
2
|
+
setup.py
|
|
3
|
+
tojscript/__init__(1).py
|
|
4
|
+
tojscript/__init__.py
|
|
5
|
+
tojscript.egg-info/PKG-INFO
|
|
6
|
+
tojscript.egg-info/SOURCES.txt
|
|
7
|
+
tojscript.egg-info/dependency_links.txt
|
|
8
|
+
tojscript.egg-info/entry_points.txt
|
|
9
|
+
tojscript.egg-info/requires.txt
|
|
10
|
+
tojscript.egg-info/top_level.txt
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
colorama
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
tojscript
|