Skip to content

Commit 6577c68

Browse files
Add abstract function to gd2py
1 parent 4a7c10a commit 6577c68

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

gdtoolkit/gd2py/__init__.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ def _convert_statement(statement: Tree, context: Context) -> List[str]:
6464
)
6565
],
6666
"static_func_def": _convert_first_child_as_statement,
67+
"abstract_func_def": _convert_abstract_func_def,
6768
"docstr_stmt": _pass,
6869
# func statements:
6970
"func_var_stmt": _convert_first_child_as_statement,
@@ -164,6 +165,16 @@ def _convert_func_def(statement: Tree, context: Context) -> List[str]:
164165
] + _convert_block(statement.children[1:], context.create_child_context(-1))
165166

166167

168+
def _convert_abstract_func_def(statement: Tree, context: Context) -> List[str]:
169+
# Abstract functions don't have a body, so we create a function that raises NotImplementedError
170+
func_header = statement.children[0]
171+
func_name = func_header.children[0].value
172+
return [
173+
f"{context.indent_string}def {func_name}():",
174+
f"{context.indent_string} raise NotImplementedError('Abstract method not implemented')",
175+
]
176+
177+
167178
def _convert_branch_with_expression(
168179
prefix: str, statement: Tree, context: Context
169180
) -> List[str]:

0 commit comments

Comments
 (0)