bxcode-ar 1.0.0__py3-none-any.whl

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.
bxcode_ar/__init__.py ADDED
@@ -0,0 +1,8 @@
1
+ from .compiler import (
2
+ compile_code,
3
+ compile_file,
4
+ run,
5
+ run_file
6
+ )
7
+
8
+ __version__ = "1.1.0"
bxcode_ar/cli.py ADDED
@@ -0,0 +1,66 @@
1
+ import sys
2
+
3
+ from .compiler import compile_file, run_file
4
+
5
+
6
+ def main():
7
+
8
+ if len(sys.argv) < 2:
9
+
10
+ print("BXCode Arabic")
11
+
12
+ print()
13
+ print("الاستخدام:")
14
+ print(" bxcode file.bx")
15
+ print(" bxcode build file.bx")
16
+ print(" bxcode run file.bx")
17
+
18
+ return
19
+
20
+ command = sys.argv[1]
21
+
22
+ if command == "run":
23
+
24
+ if len(sys.argv) < 3:
25
+ print("حدد ملف .bx")
26
+ return
27
+
28
+ filename = sys.argv[2]
29
+
30
+ run_file(filename)
31
+
32
+ return
33
+
34
+ if command == "build":
35
+
36
+ if len(sys.argv) < 3:
37
+ print("حدد ملف .bx")
38
+ return
39
+
40
+ filename = sys.argv[2]
41
+
42
+ code = compile_file(filename)
43
+
44
+ output = filename.rsplit(".", 1)[0] + ".py"
45
+
46
+ with open(
47
+ output,
48
+ "w",
49
+ encoding="utf-8"
50
+ ) as file:
51
+
52
+ file.write(code)
53
+
54
+ print(f"تم إنشاء: {output}")
55
+
56
+ return
57
+
58
+ filename = command
59
+
60
+ code = compile_file(filename)
61
+
62
+ print(code)
63
+
64
+
65
+ if __name__ == "__main__":
66
+ main()
bxcode_ar/compiler.py ADDED
@@ -0,0 +1,131 @@
1
+ import re
2
+ import sys
3
+
4
+
5
+ KEYWORDS = {
6
+ "وإلا": "else",
7
+ "وإلا_اذا": "elif",
8
+
9
+ "لكل": "for",
10
+ "بينما": "while",
11
+
12
+ "دالة": "def",
13
+ "ارجع": "return",
14
+
15
+ "ادخل": "input",
16
+
17
+ "صح": "True",
18
+ "خطأ": "False",
19
+ "فارغ": "None",
20
+
21
+ "و": "and",
22
+ "او": "or",
23
+ "ليس": "not",
24
+ "في": "in",
25
+
26
+ "كسر": "break",
27
+ "استمر": "continue",
28
+ "مرر": "pass",
29
+ }
30
+
31
+
32
+ OPERATORS = {
33
+ "اكبر_او_يساوي": ">=",
34
+ "اصغر_او_يساوي": "<=",
35
+ "لايساوي": "!=",
36
+ "اكبر": ">",
37
+ "اصغر": "<",
38
+ "يساوي": "==",
39
+ }
40
+
41
+
42
+ def translate_print(line):
43
+ match = re.match(r'^(\s*)اطبع\((.*)\)\s*$', line)
44
+
45
+ if not match:
46
+ return None
47
+
48
+ indent = match.group(1)
49
+ value = match.group(2).strip()
50
+
51
+ return f"{indent}print({value})"
52
+
53
+
54
+ def translate_if(line):
55
+ match = re.match(
56
+ r'^(\s*)اذا\s+(.+?)\s+(اكبر_او_يساوي|اصغر_او_يساوي|لايساوي|اكبر|اصغر|يساوي)\s+(.+):\s*$',
57
+ line
58
+ )
59
+
60
+ if not match:
61
+ return None
62
+
63
+ indent = match.group(1)
64
+ left = match.group(2)
65
+ operator = match.group(3)
66
+ right = match.group(4)
67
+
68
+ return (
69
+ f"{indent}if "
70
+ f"{left} "
71
+ f"{OPERATORS[operator]} "
72
+ f"{right}:"
73
+ )
74
+
75
+
76
+ def translate_line(line):
77
+
78
+ result = translate_print(line)
79
+
80
+ if result is not None:
81
+ return result
82
+
83
+ result = translate_if(line)
84
+
85
+ if result is not None:
86
+ return result
87
+
88
+ for arabic, python in KEYWORDS.items():
89
+ line = re.sub(
90
+ rf"\b{re.escape(arabic)}\b",
91
+ python,
92
+ line
93
+ )
94
+
95
+ return line
96
+
97
+
98
+ def compile_code(code):
99
+
100
+ return "\n".join(
101
+ translate_line(line)
102
+ for line in code.splitlines()
103
+ )
104
+
105
+
106
+ def compile_file(filename):
107
+
108
+ with open(filename, "r", encoding="utf-8") as file:
109
+ return compile_code(file.read())
110
+
111
+
112
+ def run(code):
113
+
114
+ python_code = compile_code(code)
115
+
116
+ namespace = {
117
+ "__name__": "__main__"
118
+ }
119
+
120
+ exec(python_code, namespace)
121
+
122
+
123
+ def run_file(filename):
124
+
125
+ code = compile_file(filename)
126
+
127
+ namespace = {
128
+ "__name__": "__main__"
129
+ }
130
+
131
+ exec(code, namespace)
@@ -0,0 +1,9 @@
1
+ Metadata-Version: 2.4
2
+ Name: bxcode_ar
3
+ Version: 1.0.0
4
+ Summary: Arabic syntax compiler for Python
5
+ License: MIT
6
+ Requires-Python: >=3.9
7
+ Description-Content-Type: text/markdown
8
+ License-File: LICENSE
9
+ Dynamic: license-file
@@ -0,0 +1,9 @@
1
+ bxcode_ar/__init__.py,sha256=n3JzOdwy4c9LDiYY8KYmvOWflH7Caw91R1p_yNHfDAE,107
2
+ bxcode_ar/cli.py,sha256=afIBJxgmcRtJ4DvU2mQpgDGfREdx421Dyk-kpaStPP0,1083
3
+ bxcode_ar/compiler.py,sha256=jnz5GuFZFVIi9vQhy68AmemUwloCwY6e6HQqD4kd2p4,2239
4
+ bxcode_ar-1.0.0.dist-info/licenses/LICENSE,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
5
+ bxcode_ar-1.0.0.dist-info/METADATA,sha256=ZkfE1p88qZ3fc283-Z_PX1QyS8e48JUidUaZuJuTUn8,216
6
+ bxcode_ar-1.0.0.dist-info/WHEEL,sha256=YVMoNqKzERt-wjUZwJ33xBGAwnFl-4cqbYkTtWa4itE,91
7
+ bxcode_ar-1.0.0.dist-info/entry_points.txt,sha256=q4NGrPMGeXDmKjY4OPUQR7fqzHjx9AzsqSbN88qkBGU,46
8
+ bxcode_ar-1.0.0.dist-info/top_level.txt,sha256=YCPZ6DGWLHgNef2ACO2H01q_Kf7VgkknHWCZlbXo7AU,10
9
+ bxcode_ar-1.0.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (84.0.0)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ bxcode = bxcode_ar.cli:main
File without changes
@@ -0,0 +1 @@
1
+ bxcode_ar