codegen-2 2.1.2__py3-none-any.whl → 2.1.4__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.
- codegen/models/ast.py +5 -2
- codegen/models/expr.py +9 -16
- codegen/models/statement.py +8 -0
- {codegen_2-2.1.2.dist-info → codegen_2-2.1.4.dist-info}/METADATA +3 -2
- codegen_2-2.1.4.dist-info/RECORD +12 -0
- {codegen_2-2.1.2.dist-info → codegen_2-2.1.4.dist-info}/WHEEL +1 -1
- codegen_2-2.1.2.dist-info/RECORD +0 -12
- {codegen_2-2.1.2.dist-info → codegen_2-2.1.4.dist-info}/LICENSE +0 -0
codegen/models/ast.py
CHANGED
|
@@ -8,6 +8,7 @@ from codegen.models.statement import (
|
|
|
8
8
|
AssignStatement,
|
|
9
9
|
BlockStatement,
|
|
10
10
|
Comment,
|
|
11
|
+
DefClassStatement,
|
|
11
12
|
DefFuncStatement,
|
|
12
13
|
ElseStatement,
|
|
13
14
|
ExceptionStatement,
|
|
@@ -91,6 +92,10 @@ class AST:
|
|
|
91
92
|
)
|
|
92
93
|
return self._add_stmt(DefFuncStatement(name, [var.get_var() for var in vars]))
|
|
93
94
|
|
|
95
|
+
def class_(self, name: str):
|
|
96
|
+
"""Define a class."""
|
|
97
|
+
return self._add_stmt(DefClassStatement(name))
|
|
98
|
+
|
|
94
99
|
def expr(self, expr: Expr):
|
|
95
100
|
return self._add_stmt(SingleExprStatement(expr))
|
|
96
101
|
|
|
@@ -213,8 +218,6 @@ class AST:
|
|
|
213
218
|
return VarScope(self.id, len(self.children))
|
|
214
219
|
|
|
215
220
|
def _add_stmt(self, stmt: Statement):
|
|
216
|
-
if isinstance(stmt, NoStatement):
|
|
217
|
-
return self
|
|
218
221
|
if self._is_frozen:
|
|
219
222
|
raise Exception("The AST is frozen and cannot be modified")
|
|
220
223
|
ast = AST(self.next_child_id(), self.prog, stmt)
|
codegen/models/expr.py
CHANGED
|
@@ -13,6 +13,11 @@ class Expr(ABC):
|
|
|
13
13
|
def to_python(self):
|
|
14
14
|
raise NotImplementedError()
|
|
15
15
|
|
|
16
|
+
def to_wrapped_python(self):
|
|
17
|
+
if isinstance(self, (ExprVar, ExprConstant)):
|
|
18
|
+
return self.to_python()
|
|
19
|
+
return f"({self.to_python()})"
|
|
20
|
+
|
|
16
21
|
|
|
17
22
|
class ExceptionExpr(Expr):
|
|
18
23
|
pass
|
|
@@ -121,9 +126,7 @@ class ExprNegation(Expr):
|
|
|
121
126
|
expr: Expr
|
|
122
127
|
|
|
123
128
|
def to_python(self):
|
|
124
|
-
|
|
125
|
-
return f"not {self.expr.to_python()}"
|
|
126
|
-
return f"not ({self.expr.to_python()})"
|
|
129
|
+
return f"not {self.expr.to_wrapped_python()}"
|
|
127
130
|
|
|
128
131
|
|
|
129
132
|
class PredefinedFn:
|
|
@@ -175,17 +178,7 @@ class PredefinedFn:
|
|
|
175
178
|
item: Expr
|
|
176
179
|
|
|
177
180
|
def to_python(self):
|
|
178
|
-
|
|
179
|
-
set_py = self.set_.to_python()
|
|
180
|
-
else:
|
|
181
|
-
set_py = f"({self.set_.to_python()})"
|
|
182
|
-
|
|
183
|
-
if isinstance(self.item, (ExprVar, ExprConstant)):
|
|
184
|
-
item_py = self.item.to_python()
|
|
185
|
-
else:
|
|
186
|
-
item_py = f"({self.item.to_python()})"
|
|
187
|
-
|
|
188
|
-
return f"{item_py} in {set_py}"
|
|
181
|
+
return f"{self.item.to_wrapped_python()} in {self.set_.to_wrapped_python()}"
|
|
189
182
|
|
|
190
183
|
@dataclass
|
|
191
184
|
class list_append(Expr):
|
|
@@ -193,7 +186,7 @@ class PredefinedFn:
|
|
|
193
186
|
item: Expr
|
|
194
187
|
|
|
195
188
|
def to_python(self):
|
|
196
|
-
return f"{self.lst.
|
|
189
|
+
return f"{self.lst.to_wrapped_python()}.append({self.item.to_python()})"
|
|
197
190
|
|
|
198
191
|
@dataclass
|
|
199
192
|
class has_item(Expr):
|
|
@@ -201,7 +194,7 @@ class PredefinedFn:
|
|
|
201
194
|
item: Expr
|
|
202
195
|
|
|
203
196
|
def to_python(self):
|
|
204
|
-
return f"
|
|
197
|
+
return f"{self.item.to_wrapped_python()} in {self.collection.to_wrapped_python()}"
|
|
205
198
|
|
|
206
199
|
@dataclass
|
|
207
200
|
class base_error(ExceptionExpr):
|
codegen/models/statement.py
CHANGED
|
@@ -60,6 +60,14 @@ class DefFuncStatement(Statement):
|
|
|
60
60
|
return f"def {self.name}({', '.join([arg.get_name() for arg in self.args])}):"
|
|
61
61
|
|
|
62
62
|
|
|
63
|
+
@dataclass
|
|
64
|
+
class DefClassStatement(Statement):
|
|
65
|
+
name: str
|
|
66
|
+
|
|
67
|
+
def to_python(self):
|
|
68
|
+
return f"class {self.name}:"
|
|
69
|
+
|
|
70
|
+
|
|
63
71
|
@dataclass
|
|
64
72
|
class AssignStatement(Statement):
|
|
65
73
|
var: Var
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.3
|
|
2
2
|
Name: codegen-2
|
|
3
|
-
Version: 2.1.
|
|
3
|
+
Version: 2.1.4
|
|
4
4
|
Summary: Meta-programming
|
|
5
5
|
License: MIT
|
|
6
6
|
Author: Binh Vu
|
|
@@ -10,6 +10,7 @@ Classifier: License :: OSI Approved :: MIT License
|
|
|
10
10
|
Classifier: Programming Language :: Python :: 3
|
|
11
11
|
Classifier: Programming Language :: Python :: 3.11
|
|
12
12
|
Classifier: Programming Language :: Python :: 3.12
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
13
14
|
Description-Content-Type: text/markdown
|
|
14
15
|
|
|
15
16
|
# codegen
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
codegen/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
2
|
+
codegen/models/__init__.py,sha256=j__FrDdGOILIo9jqEDElL3YP69h0xkL2SqrMxSqgpTc,457
|
|
3
|
+
codegen/models/ast.py,sha256=rUb_LOKijxbjNDHycc4E_M1GeFs3CQ8MAbpuWNPJvuI,7892
|
|
4
|
+
codegen/models/expr.py,sha256=bGc-ZTbgGLmepPs-Zef4VP07WMfvCQb2AFeM7JDPKHc,5032
|
|
5
|
+
codegen/models/program.py,sha256=6ggzINtk1i9WeSFsiI8Qa6TiNJEafXbXwYqKoq4k_xA,4471
|
|
6
|
+
codegen/models/statement.py,sha256=_H5PWCw-zUPIX0fCHQ5iDtR9WeeL9qPW6mMOfQJSvKY,3025
|
|
7
|
+
codegen/models/types.py,sha256=Dl-wzGB1viA7EZj2CuTrZe1F133Q6ENVr_yRqxhde8M,178
|
|
8
|
+
codegen/models/var.py,sha256=3T-GEv5z6T31HfAUOJ7TTjN3WF3ejY3rfRNvrIUfLP8,1771
|
|
9
|
+
codegen_2-2.1.4.dist-info/LICENSE,sha256=Ea6itrykT9pvPGd0Kgl6FbrqdDwKswPZJmXMFVjUBqw,1064
|
|
10
|
+
codegen_2-2.1.4.dist-info/METADATA,sha256=tq9u81WlHLs9WwlSI-S4TG-rCUhOIxJKf3PQKsPQdq4,487
|
|
11
|
+
codegen_2-2.1.4.dist-info/WHEEL,sha256=XbeZDeTWKc1w7CSIyre5aMDU_-PohRwTQceYnisIYYY,88
|
|
12
|
+
codegen_2-2.1.4.dist-info/RECORD,,
|
codegen_2-2.1.2.dist-info/RECORD
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
codegen/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
2
|
-
codegen/models/__init__.py,sha256=j__FrDdGOILIo9jqEDElL3YP69h0xkL2SqrMxSqgpTc,457
|
|
3
|
-
codegen/models/ast.py,sha256=VbMWfTpHG5FHveB6lAkRGu0Ws8KwCjhQYWd37Sw0cnY,7816
|
|
4
|
-
codegen/models/expr.py,sha256=0gUcP-oBf8rAf4NKdL8idcis-Z9Wf8tjasXDTFyd7uk,5273
|
|
5
|
-
codegen/models/program.py,sha256=6ggzINtk1i9WeSFsiI8Qa6TiNJEafXbXwYqKoq4k_xA,4471
|
|
6
|
-
codegen/models/statement.py,sha256=egKy8wAutHnOqZbRFZGSASQSpjQWpFc4l9-P5mTjx-k,2899
|
|
7
|
-
codegen/models/types.py,sha256=Dl-wzGB1viA7EZj2CuTrZe1F133Q6ENVr_yRqxhde8M,178
|
|
8
|
-
codegen/models/var.py,sha256=3T-GEv5z6T31HfAUOJ7TTjN3WF3ejY3rfRNvrIUfLP8,1771
|
|
9
|
-
codegen_2-2.1.2.dist-info/LICENSE,sha256=Ea6itrykT9pvPGd0Kgl6FbrqdDwKswPZJmXMFVjUBqw,1064
|
|
10
|
-
codegen_2-2.1.2.dist-info/METADATA,sha256=mXdvUgfCRcLJabyVRNP_BOWe6n_MPGm35uG2zSG0iQ4,436
|
|
11
|
-
codegen_2-2.1.2.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
|
|
12
|
-
codegen_2-2.1.2.dist-info/RECORD,,
|
|
File without changes
|