Skip to content

Commit 34d4ee6

Browse files
committed
Fix 'gd2py' amd 'gdradon' to support latest GDScript
1 parent c2340f8 commit 34d4ee6

File tree

3 files changed

+43
-0
lines changed

3 files changed

+43
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
### Changed
1010
- Removed `private-method-call` linter check due to false positives when calling `super._foo()`
1111
- Fixed support for `get_node` syntax to accommodate for `$/(...)`
12+
- Fixed `gd2py` and `gdradon` to support latest GDScript
1213
- Changed formatting of some uni-statement lambdas
1314
- Changed formatting of multi-statement, inline lambdas
1415
- Changed formatting of dot-chains containing a lambda(s)

gdtoolkit/gd2py/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ def _convert_statement(statement: Tree, context: Context) -> List[str]:
3838
"annotation": _ignore,
3939
"pass_stmt": lambda s, c: [f"{c.indent_string}pass"],
4040
"class_var_stmt": _convert_first_child_as_statement,
41+
"static_class_var_stmt": _convert_first_child_as_statement,
4142
"class_var_empty": lambda s, c: [
4243
f"{c.indent_string}{s.children[0].value} = None"
4344
],
@@ -63,6 +64,7 @@ def _convert_statement(statement: Tree, context: Context) -> List[str]:
6364
)
6465
],
6566
"static_func_def": _convert_first_child_as_statement,
67+
"docstr_stmt": _pass,
6668
# func statements:
6769
"func_var_stmt": _convert_first_child_as_statement,
6870
"func_var_empty": lambda s, c: [
@@ -87,6 +89,7 @@ def _convert_statement(statement: Tree, context: Context) -> List[str]:
8789
)
8890
],
8991
"break_stmt": lambda s, c: [f"{c.indent_string}break"],
92+
"breakpoint_stmt": lambda s, c: [f"{c.indent_string}breakpoint"],
9093
"continue_stmt": lambda s, c: [f"{c.indent_string}continue"],
9194
"if_stmt": lambda s, c: _convert_block(s.children, c),
9295
"if_branch": partial(_convert_branch_with_expression, "if"),
@@ -112,6 +115,7 @@ def _convert_statement(statement: Tree, context: Context) -> List[str]:
112115
+ _convert_block(s.children[3:], c.create_child_context(-2)),
113116
"match_stmt": _convert_match_statement,
114117
"match_branch": partial(_convert_branch_with_expression, "elif"),
118+
"guarded_match_branch": partial(_convert_branch_with_expression, "elif"),
115119
} # type: Dict[str, Callable]
116120
return handlers[statement.data](statement, context)
117121

tests/gd2py/test_conversion.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import os
2+
3+
from gdtoolkit.gd2py import convert_code
4+
5+
6+
VALID_SCRIPT_DIRS = [
7+
"../formatter/big-input-files",
8+
"../formatter/input-output-pairs",
9+
"../valid-gd-scripts",
10+
]
11+
EXCEPTIONS = [
12+
"bug_326_multistatement_lambda_corner_case.out.gd",
13+
]
14+
15+
16+
def pytest_generate_tests(metafunc):
17+
this_directory = os.path.dirname(os.path.abspath(__file__))
18+
if "gdscript_path" in metafunc.fixturenames:
19+
valid_script_paths = set()
20+
for directory_relative_path in VALID_SCRIPT_DIRS:
21+
directory_absolute_path = os.path.join(
22+
this_directory, directory_relative_path
23+
)
24+
valid_script_paths = valid_script_paths.union(
25+
set(
26+
os.path.join(directory_absolute_path, f)
27+
for f in os.listdir(directory_absolute_path)
28+
)
29+
)
30+
metafunc.parametrize("gdscript_path", valid_script_paths)
31+
32+
33+
def test_conversion_success(gdscript_path):
34+
if any(exception in gdscript_path for exception in EXCEPTIONS):
35+
return
36+
with open(gdscript_path, "r", encoding="utf-8") as file_handle:
37+
code = file_handle.read()
38+
convert_code(code)

0 commit comments

Comments
 (0)