codegen-2 2.7.1__tar.gz → 2.8.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.
- {codegen_2-2.7.1 → codegen_2-2.8.0}/PKG-INFO +1 -1
- {codegen_2-2.7.1 → codegen_2-2.8.0}/codegen/models/statement.py +34 -4
- {codegen_2-2.7.1 → codegen_2-2.8.0}/pyproject.toml +1 -1
- {codegen_2-2.7.1 → codegen_2-2.8.0}/LICENSE +0 -0
- {codegen_2-2.7.1 → codegen_2-2.8.0}/README.md +0 -0
- {codegen_2-2.7.1 → codegen_2-2.8.0}/codegen/__init__.py +0 -0
- {codegen_2-2.7.1 → codegen_2-2.8.0}/codegen/models/__init__.py +0 -0
- {codegen_2-2.7.1 → codegen_2-2.8.0}/codegen/models/ast.py +0 -0
- {codegen_2-2.7.1 → codegen_2-2.8.0}/codegen/models/expr.py +0 -0
- {codegen_2-2.7.1 → codegen_2-2.8.0}/codegen/models/program.py +0 -0
- {codegen_2-2.7.1 → codegen_2-2.8.0}/codegen/models/types.py +0 -0
- {codegen_2-2.7.1 → codegen_2-2.8.0}/codegen/models/var.py +0 -0
|
@@ -100,7 +100,7 @@ class DefFuncStatement(Statement):
|
|
|
100
100
|
sig = "async " + sig
|
|
101
101
|
sig = sig + ":"
|
|
102
102
|
if self.is_static:
|
|
103
|
-
sig = "
|
|
103
|
+
sig = "@staticmethod\n" + sig
|
|
104
104
|
if self.comment != "":
|
|
105
105
|
sig = (
|
|
106
106
|
sig
|
|
@@ -185,6 +185,8 @@ class DefClassVarStatement(Statement):
|
|
|
185
185
|
type: Optional[str]
|
|
186
186
|
# value of the variable
|
|
187
187
|
value: Optional[Expr] = None
|
|
188
|
+
# whether this variable is static
|
|
189
|
+
is_static: bool = False
|
|
188
190
|
|
|
189
191
|
def to_python(self):
|
|
190
192
|
if self.type is None:
|
|
@@ -196,10 +198,20 @@ class DefClassVarStatement(Statement):
|
|
|
196
198
|
return f"{self.name}: {self.type} = {self.value.to_python()}"
|
|
197
199
|
|
|
198
200
|
def to_typescript(self):
|
|
199
|
-
|
|
201
|
+
mod = ""
|
|
202
|
+
if self.is_static:
|
|
203
|
+
mod = "static "
|
|
204
|
+
else:
|
|
205
|
+
# static variable don't require type
|
|
206
|
+
assert self.type is not None
|
|
207
|
+
if self.type is not None:
|
|
208
|
+
type = f": {self.type}"
|
|
209
|
+
else:
|
|
210
|
+
type = ""
|
|
211
|
+
|
|
200
212
|
if self.value is None:
|
|
201
|
-
return f"{self.name}
|
|
202
|
-
return f"{self.name}
|
|
213
|
+
return f"{mod}{self.name}{type};"
|
|
214
|
+
return f"{mod}{self.name}{type} = {self.value.to_typescript()};"
|
|
203
215
|
|
|
204
216
|
|
|
205
217
|
@dataclass
|
|
@@ -241,6 +253,24 @@ class ExceptionStatement(Statement):
|
|
|
241
253
|
return "raise " + self.expr.to_python()
|
|
242
254
|
|
|
243
255
|
|
|
256
|
+
@dataclass
|
|
257
|
+
class AssertionStatement(Statement):
|
|
258
|
+
expr: Expr
|
|
259
|
+
error_msg: Optional[Expr] = None
|
|
260
|
+
|
|
261
|
+
def to_python(self):
|
|
262
|
+
if self.error_msg:
|
|
263
|
+
return f"assert {self.expr.to_python()}, {self.error_msg.to_python()}"
|
|
264
|
+
return f"assert {self.expr.to_python()}"
|
|
265
|
+
|
|
266
|
+
def to_typescript(self):
|
|
267
|
+
if self.error_msg:
|
|
268
|
+
return f"if (!({self.expr.to_typescript()})) throw new Error({self.error_msg.to_typescript()});"
|
|
269
|
+
return (
|
|
270
|
+
f"if (!({self.expr.to_typescript()})) throw new Error('Assertion failed');"
|
|
271
|
+
)
|
|
272
|
+
|
|
273
|
+
|
|
244
274
|
@dataclass
|
|
245
275
|
class ForLoopStatement(Statement):
|
|
246
276
|
item: Var
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|