codegen-2 2.5.2__tar.gz → 2.7.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.5.2 → codegen_2-2.7.0}/PKG-INFO +1 -1
- {codegen_2-2.5.2 → codegen_2-2.7.0}/codegen/models/ast.py +10 -5
- {codegen_2-2.5.2 → codegen_2-2.7.0}/codegen/models/expr.py +13 -0
- {codegen_2-2.5.2 → codegen_2-2.7.0}/codegen/models/statement.py +6 -3
- {codegen_2-2.5.2 → codegen_2-2.7.0}/pyproject.toml +1 -1
- {codegen_2-2.5.2 → codegen_2-2.7.0}/LICENSE +0 -0
- {codegen_2-2.5.2 → codegen_2-2.7.0}/README.md +0 -0
- {codegen_2-2.5.2 → codegen_2-2.7.0}/codegen/__init__.py +0 -0
- {codegen_2-2.5.2 → codegen_2-2.7.0}/codegen/models/__init__.py +0 -0
- {codegen_2-2.5.2 → codegen_2-2.7.0}/codegen/models/program.py +0 -0
- {codegen_2-2.5.2 → codegen_2-2.7.0}/codegen/models/types.py +0 -0
- {codegen_2-2.5.2 → codegen_2-2.7.0}/codegen/models/var.py +0 -0
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
from __future__ import annotations
|
|
2
2
|
|
|
3
3
|
from dataclasses import dataclass, field
|
|
4
|
-
from typing import TYPE_CHECKING, Any, Callable, Optional, Sequence
|
|
4
|
+
from typing import TYPE_CHECKING, Any, Callable, Literal, Optional, Sequence
|
|
5
5
|
|
|
6
6
|
from codegen.models.expr import ExceptionExpr, Expr
|
|
7
7
|
from codegen.models.statement import (
|
|
8
8
|
AssignStatement,
|
|
9
9
|
BlockStatement,
|
|
10
10
|
Comment,
|
|
11
|
+
DefClassLikeStatement,
|
|
11
12
|
DefClassStatement,
|
|
12
13
|
DefClassVarStatement,
|
|
13
14
|
DefFuncStatement,
|
|
14
|
-
DefInterfaceStatement,
|
|
15
15
|
ElseStatement,
|
|
16
16
|
ExceptionStatement,
|
|
17
17
|
ForLoopStatement,
|
|
@@ -135,9 +135,14 @@ class AST:
|
|
|
135
135
|
"""Define a class."""
|
|
136
136
|
return self._add_stmt(DefClassStatement(name, parents or []))
|
|
137
137
|
|
|
138
|
-
def
|
|
139
|
-
|
|
140
|
-
|
|
138
|
+
def class_like(
|
|
139
|
+
self,
|
|
140
|
+
keyword: Literal["interface", "enum"],
|
|
141
|
+
name: str,
|
|
142
|
+
parents: Optional[Sequence[Expr]] = None,
|
|
143
|
+
):
|
|
144
|
+
"""Define a class-like structure such as enum or interface in Typescript."""
|
|
145
|
+
return self._add_stmt(DefClassLikeStatement(keyword, name, parents or []))
|
|
141
146
|
|
|
142
147
|
def expr(self, expr: Expr):
|
|
143
148
|
return self._add_stmt(SingleExprStatement(expr))
|
|
@@ -231,6 +231,19 @@ class ExprDivision(Expr):
|
|
|
231
231
|
return f"{self.left.to_python()} / {self.right.to_python()}"
|
|
232
232
|
|
|
233
233
|
|
|
234
|
+
@dataclass
|
|
235
|
+
class ExprTernary(Expr):
|
|
236
|
+
condition: Expr
|
|
237
|
+
true_expr: Expr
|
|
238
|
+
false_expr: Expr
|
|
239
|
+
|
|
240
|
+
def to_python(self):
|
|
241
|
+
return f"{self.true_expr.to_python()} if {self.condition.to_python()} else {self.false_expr.to_python()}"
|
|
242
|
+
|
|
243
|
+
def to_typescript(self):
|
|
244
|
+
return f"{self.true_expr.to_typescript()} ? {self.condition.to_typescript()} : {self.false_expr.to_typescript()}"
|
|
245
|
+
|
|
246
|
+
|
|
234
247
|
class PredefinedFn:
|
|
235
248
|
@dataclass
|
|
236
249
|
class is_null(Expr):
|
|
@@ -3,7 +3,7 @@ from __future__ import annotations
|
|
|
3
3
|
from abc import ABC, abstractmethod
|
|
4
4
|
from dataclasses import dataclass, field
|
|
5
5
|
from multiprocessing import Value
|
|
6
|
-
from typing import Optional, Sequence
|
|
6
|
+
from typing import Literal, Optional, Sequence
|
|
7
7
|
|
|
8
8
|
from codegen.models.expr import ExceptionExpr, Expr, ExprFuncCall
|
|
9
9
|
from codegen.models.var import Var
|
|
@@ -156,7 +156,10 @@ class DefClassStatement(Statement):
|
|
|
156
156
|
|
|
157
157
|
|
|
158
158
|
@dataclass
|
|
159
|
-
class
|
|
159
|
+
class DefClassLikeStatement(Statement):
|
|
160
|
+
"""Statement to define a class or interface"""
|
|
161
|
+
|
|
162
|
+
keyword: Literal["interface", "enum"]
|
|
160
163
|
name: str
|
|
161
164
|
parents: Sequence[Expr] = field(default_factory=list)
|
|
162
165
|
|
|
@@ -169,7 +172,7 @@ class DefInterfaceStatement(Statement):
|
|
|
169
172
|
extend = f" extends {' '.join(p.to_typescript() for p in self.parents)}"
|
|
170
173
|
else:
|
|
171
174
|
extend = ""
|
|
172
|
-
return f"export
|
|
175
|
+
return f"export {self.keyword} {self.name}" + extend
|
|
173
176
|
|
|
174
177
|
|
|
175
178
|
@dataclass
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|