tojscript 1.0.2__tar.gz → 1.0.4__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.
@@ -1,5 +1,5 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: tojscript
3
- Version: 1.0.2
3
+ Version: 1.0.4
4
4
  Requires-Dist: colorama
5
5
  Dynamic: requires-dist
@@ -1,8 +1,7 @@
1
1
  from setuptools import setup, find_packages
2
-
3
2
  setup(
4
3
  name="tojscript",
5
- version="1.0.2",
4
+ version="1.0.4",
6
5
  packages=find_packages(),
7
6
  install_requires=["colorama"],
8
7
  entry_points={
@@ -10,4 +9,4 @@ setup(
10
9
  "toj=tojscript:main",
11
10
  ],
12
11
  },
13
- )
12
+ )
@@ -2,7 +2,9 @@ from colorama import Fore, Style, init
2
2
  init()
3
3
  import re
4
4
  import sys
5
+ import codecs
5
6
 
7
+ # 🎨 Цвета
6
8
  colors = {
7
9
  "сабз": Fore.GREEN,
8
10
  "сурх": Fore.RED,
@@ -79,6 +81,7 @@ TOJ_GLOBALS = {
79
81
  }
80
82
 
81
83
  def toj_to_python(code):
84
+ # убираем строки import tojscript
82
85
  code = re.sub(r'^\s*import\s+tojscript\s*$', '', code, flags=re.MULTILINE)
83
86
 
84
87
  translations = {
@@ -133,23 +136,45 @@ def toj_to_python(code):
133
136
  return "\n".join(new_lines)
134
137
 
135
138
  def runs(code):
139
+ """Запуск таджикского кода из строки"""
136
140
  python_code = toj_to_python(code)
137
141
  try:
138
- exec(python_code, TOJ_GLOBALS)
142
+ exec(python_code, {**TOJ_GLOBALS, **locals()})
139
143
  except Exception as e:
140
144
  print("Хато:", e)
141
145
 
142
146
  def run(filename):
147
+ """Запуск .toj или .py файла"""
143
148
  with open(filename, "r", encoding="utf-8") as f:
144
149
  code = f.read()
145
150
  python_code = toj_to_python(code)
146
151
  try:
147
- exec(python_code, TOJ_GLOBALS)
152
+ exec(python_code, {**TOJ_GLOBALS, **locals()})
148
153
  except Exception as e:
149
154
  print("Хато:", e)
150
155
 
156
+ # 🔥 Хук: если запускают .py файл с таджикским кодом
157
+ class TojImportHook:
158
+ def find_module(self, name, path=None):
159
+ if name == "tojscript":
160
+ return self
161
+ return None
162
+ def load_module(self, name):
163
+ import types
164
+ mod = types.ModuleType(name)
165
+ mod.run = run
166
+ mod.runs = runs
167
+ mod.toj_to_python = toj_to_python
168
+ sys.modules[name] = mod
169
+ return mod
170
+
171
+ sys.meta_path.insert(0, TojImportHook())
172
+
151
173
  def main():
152
174
  if len(sys.argv) > 1:
175
+ if sys.argv[1] == "--version":
176
+ print("TojScript 1.0.3")
177
+ return
153
178
  run(sys.argv[1])
154
179
  else:
155
180
  run("main.toj")
@@ -1,5 +1,5 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: tojscript
3
- Version: 1.0.2
3
+ Version: 1.0.4
4
4
  Requires-Dist: colorama
5
5
  Dynamic: requires-dist
@@ -1,4 +1,3 @@
1
- README.md
2
1
  setup.py
3
2
  tojscript/__init__.py
4
3
  tojscript.egg-info/PKG-INFO
tojscript-1.0.2/README.md DELETED
@@ -1,22 +0,0 @@
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
- ```
File without changes