codegen-2 2.1.0__py3-none-any.whl → 2.1.2__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 CHANGED
@@ -15,6 +15,7 @@ from codegen.models.statement import (
15
15
  IfStatement,
16
16
  ImportStatement,
17
17
  LineBreak,
18
+ NoStatement,
18
19
  PythonStatement,
19
20
  ReturnStatement,
20
21
  SingleExprStatement,
@@ -128,7 +129,9 @@ class AST:
128
129
  return self._add_stmt(IfStatement(condition))
129
130
 
130
131
  def else_(self):
131
- assert len(self.children) > 0 and isinstance(self.children[-1].stmt, Statement)
132
+ assert len(self.children) > 0 and isinstance(
133
+ self.children[-1].stmt, IfStatement
134
+ )
132
135
  return self._add_stmt(ElseStatement())
133
136
 
134
137
  def python_stmt(self, stmt: str) -> AST:
@@ -174,6 +177,7 @@ class AST:
174
177
  else:
175
178
  for ast in self.children:
176
179
  if ast.find_ast(id) is not None:
180
+ yield self
177
181
  yield from ast.find_ast_to(id)
178
182
  break
179
183
 
@@ -209,6 +213,8 @@ class AST:
209
213
  return VarScope(self.id, len(self.children))
210
214
 
211
215
  def _add_stmt(self, stmt: Statement):
216
+ if isinstance(stmt, NoStatement):
217
+ return self
212
218
  if self._is_frozen:
213
219
  raise Exception("The AST is frozen and cannot be modified")
214
220
  ast = AST(self.next_child_id(), self.prog, stmt)
codegen/models/expr.py CHANGED
@@ -121,7 +121,9 @@ class ExprNegation(Expr):
121
121
  expr: Expr
122
122
 
123
123
  def to_python(self):
124
- return f"not {self.expr.to_python()}"
124
+ if isinstance(self.expr, (ExprVar, ExprConstant)):
125
+ return f"not {self.expr.to_python()}"
126
+ return f"not ({self.expr.to_python()})"
125
127
 
126
128
 
127
129
  class PredefinedFn:
@@ -173,7 +175,17 @@ class PredefinedFn:
173
175
  item: Expr
174
176
 
175
177
  def to_python(self):
176
- return f"({self.item.to_python()}) in {self.set_.to_python()}"
178
+ if isinstance(self.set_, (ExprVar, ExprConstant)):
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}"
177
189
 
178
190
  @dataclass
179
191
  class list_append(Expr):
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: codegen-2
3
- Version: 2.1.0
3
+ Version: 2.1.2
4
4
  Summary: Meta-programming
5
5
  License: MIT
6
6
  Author: Binh Vu
@@ -1,12 +1,12 @@
1
1
  codegen/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
2
  codegen/models/__init__.py,sha256=j__FrDdGOILIo9jqEDElL3YP69h0xkL2SqrMxSqgpTc,457
3
- codegen/models/ast.py,sha256=0LdrbPNPNgDz2srw2n1pcqluaMydWINpd4cTUFfrhEU,7678
4
- codegen/models/expr.py,sha256=joIUNkcCuZqPN8i3xxgxjUAZZFBS0aMezPBmN0dhs-Q,4825
3
+ codegen/models/ast.py,sha256=VbMWfTpHG5FHveB6lAkRGu0Ws8KwCjhQYWd37Sw0cnY,7816
4
+ codegen/models/expr.py,sha256=0gUcP-oBf8rAf4NKdL8idcis-Z9Wf8tjasXDTFyd7uk,5273
5
5
  codegen/models/program.py,sha256=6ggzINtk1i9WeSFsiI8Qa6TiNJEafXbXwYqKoq4k_xA,4471
6
6
  codegen/models/statement.py,sha256=egKy8wAutHnOqZbRFZGSASQSpjQWpFc4l9-P5mTjx-k,2899
7
7
  codegen/models/types.py,sha256=Dl-wzGB1viA7EZj2CuTrZe1F133Q6ENVr_yRqxhde8M,178
8
8
  codegen/models/var.py,sha256=3T-GEv5z6T31HfAUOJ7TTjN3WF3ejY3rfRNvrIUfLP8,1771
9
- codegen_2-2.1.0.dist-info/LICENSE,sha256=Ea6itrykT9pvPGd0Kgl6FbrqdDwKswPZJmXMFVjUBqw,1064
10
- codegen_2-2.1.0.dist-info/METADATA,sha256=4N_6f2DjD6NYauD0ZvyCeSGIvr5aWiZUYcExMU1lBkI,436
11
- codegen_2-2.1.0.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
12
- codegen_2-2.1.0.dist-info/RECORD,,
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,,