codegen-2 2.8.1__tar.gz → 2.9.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.8.1 → codegen_2-2.9.0}/PKG-INFO +1 -1
- {codegen_2-2.8.1 → codegen_2-2.9.0}/codegen/models/expr.py +25 -3
- {codegen_2-2.8.1 → codegen_2-2.9.0}/pyproject.toml +1 -1
- {codegen_2-2.8.1 → codegen_2-2.9.0}/LICENSE +0 -0
- {codegen_2-2.8.1 → codegen_2-2.9.0}/README.md +0 -0
- {codegen_2-2.8.1 → codegen_2-2.9.0}/codegen/__init__.py +0 -0
- {codegen_2-2.8.1 → codegen_2-2.9.0}/codegen/models/__init__.py +0 -0
- {codegen_2-2.8.1 → codegen_2-2.9.0}/codegen/models/ast.py +0 -0
- {codegen_2-2.8.1 → codegen_2-2.9.0}/codegen/models/program.py +0 -0
- {codegen_2-2.8.1 → codegen_2-2.9.0}/codegen/models/statement.py +0 -0
- {codegen_2-2.8.1 → codegen_2-2.9.0}/codegen/models/types.py +0 -0
- {codegen_2-2.8.1 → codegen_2-2.9.0}/codegen/models/var.py +0 -0
|
@@ -128,6 +128,17 @@ class ExprRawPython(Expr):
|
|
|
128
128
|
return self.code
|
|
129
129
|
|
|
130
130
|
|
|
131
|
+
@dataclass
|
|
132
|
+
class ExprRawTypescript(Expr):
|
|
133
|
+
code: str
|
|
134
|
+
|
|
135
|
+
def to_python(self):
|
|
136
|
+
raise NotImplementedError("Raw Typescript cannot be converted to Python")
|
|
137
|
+
|
|
138
|
+
def to_typescript(self):
|
|
139
|
+
return self.code
|
|
140
|
+
|
|
141
|
+
|
|
131
142
|
@dataclass
|
|
132
143
|
class ExprVar(Expr): # a special identifier
|
|
133
144
|
var: Var
|
|
@@ -243,7 +254,7 @@ class ExprTernary(Expr):
|
|
|
243
254
|
return f"{self.true_expr.to_python()} if {self.condition.to_python()} else {self.false_expr.to_python()}"
|
|
244
255
|
|
|
245
256
|
def to_typescript(self):
|
|
246
|
-
return f"{self.
|
|
257
|
+
return f"{self.condition.to_typescript()} ? {self.true_expr.to_typescript()} : {self.false_expr.to_typescript()}"
|
|
247
258
|
|
|
248
259
|
|
|
249
260
|
class PredefinedFn:
|
|
@@ -350,15 +361,26 @@ class PredefinedFn:
|
|
|
350
361
|
class map_list(Expr):
|
|
351
362
|
collection: Expr
|
|
352
363
|
func: Expr
|
|
353
|
-
|
|
354
|
-
|
|
364
|
+
filter: Optional[Expr] = None
|
|
365
|
+
|
|
366
|
+
def __init__(
|
|
367
|
+
self,
|
|
368
|
+
collection: Expr,
|
|
369
|
+
func: Callable[[ExprIdent], Expr],
|
|
370
|
+
filter: Optional[Callable[[ExprIdent], Expr]] = None,
|
|
371
|
+
):
|
|
355
372
|
self.collection = collection
|
|
356
373
|
self.func = func(ExprIdent("_x"))
|
|
374
|
+
self.filter = filter(ExprIdent("_x")) if filter is not None else None
|
|
357
375
|
|
|
358
376
|
def to_python(self):
|
|
377
|
+
if self.filter is not None:
|
|
378
|
+
return f"[{self.func.to_python()} for _x in {self.collection.to_python()} if {self.filter.to_python()}]"
|
|
359
379
|
return f"[{self.func.to_python()} for _x in {self.collection.to_python()}]"
|
|
360
380
|
|
|
361
381
|
def to_typescript(self):
|
|
382
|
+
if self.filter is not None:
|
|
383
|
+
return f"{self.collection.to_typescript()}.filter((_x: any) => {self.filter.to_typescript()}).map((_x: any) => {self.func.to_typescript()})"
|
|
362
384
|
return f"{self.collection.to_typescript()}.map((_x: any) => {self.func.to_typescript()})"
|
|
363
385
|
|
|
364
386
|
@dataclass
|
|
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
|