Skip to content

Commit 440261b

Browse files
committed
stabilize 'gd2py' and 'gdradon'
1 parent bd33b26 commit 440261b

File tree

5 files changed

+34
-41
lines changed

5 files changed

+34
-41
lines changed

gdtoolkit/gd2py/__init__.py

Lines changed: 29 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -34,44 +34,44 @@ def _convert_block(statements: List[Tree], context: Context) -> List[str]:
3434
def _convert_statement(statement: Tree, context: Context) -> List[str]:
3535
handlers = {
3636
# class statements:
37-
"tool_stmt": _ignore,
37+
"annotation": _ignore,
3838
"pass_stmt": lambda s, c: [f"{c.indent_string}pass"],
3939
"class_var_stmt": _convert_first_child_as_statement,
40-
"var_empty": lambda s, c: [f"{c.indent_string}{s.children[0].value} = None"],
41-
"var_assigned": _convert_var_statement_with_expression,
42-
"var_typed": lambda s, c: [f"{c.indent_string}{s.children[0].value} = None"],
43-
"var_typed_assgnd": _convert_var_statement_with_expression,
44-
"var_inf": _convert_var_statement_with_expression,
45-
"extends_stmt": _ignore,
40+
"class_var_empty": lambda s, c: [
41+
f"{c.indent_string}{s.children[0].value} = None"
42+
],
43+
"class_var_assigned": _convert_var_statement_with_expression,
44+
"class_var_typed": lambda s, c: [
45+
f"{c.indent_string}{s.children[0].value} = None"
46+
],
47+
"class_var_typed_assgnd": _convert_var_statement_with_expression,
48+
"class_var_inf": _convert_var_statement_with_expression,
49+
"extends_stmt": _pass,
4650
"class_def": _convert_class_def,
4751
"func_def": _convert_func_def,
48-
"enum_def": _ignore, # TODO: implement
49-
"classname_stmt": _ignore,
50-
"classname_extends_stmt": _ignore,
51-
"signal_stmt": _ignore,
52-
"docstr_stmt": lambda s, c: [
53-
f"{c.indent_string}{s.children[0].children[0].value}"
54-
],
52+
"enum_stmt": _pass, # TODO: implement
53+
"classname_stmt": _pass,
54+
"classname_extends_stmt": _pass,
55+
"signal_stmt": _pass,
5556
"const_stmt": lambda s, c: [
5657
"{}{} = {}".format(
5758
c.indent_string,
5859
s.children[1].value,
5960
_convert_expression_to_str(s.children[-1]),
6061
)
6162
],
62-
"export_stmt": _convert_export_statement,
63-
"onready_stmt": lambda s, c: _convert_statement(s.children[-1], c),
64-
"puppet_var_stmt": _convert_first_child_as_statement,
6563
"static_func_def": _convert_first_child_as_statement,
66-
"remote_func_def": _convert_first_child_as_statement,
67-
"remotesync_func_def": _convert_first_child_as_statement,
68-
"master_func_def": _convert_first_child_as_statement,
69-
"mastersync_func_def": _convert_first_child_as_statement,
70-
"puppet_func_def": _convert_first_child_as_statement,
71-
"puppetsync_func_def": _convert_first_child_as_statement,
72-
"sync_func_def": _convert_first_child_as_statement,
7364
# func statements:
7465
"func_var_stmt": _convert_first_child_as_statement,
66+
"func_var_empty": lambda s, c: [
67+
f"{c.indent_string}{s.children[0].value} = None"
68+
],
69+
"func_var_assigned": _convert_var_statement_with_expression,
70+
"func_var_typed": lambda s, c: [
71+
f"{c.indent_string}{s.children[0].value} = None"
72+
],
73+
"func_var_typed_assgnd": _convert_var_statement_with_expression,
74+
"func_var_inf": _convert_var_statement_with_expression,
7575
"expr_stmt": _convert_first_child_as_statement,
7676
"expr": lambda s, c: [
7777
f"{c.indent_string}{_convert_expression_to_str(s.children[0])}"
@@ -106,7 +106,11 @@ def _convert_statement(statement: Tree, context: Context) -> List[str]:
106106
return handlers[statement.data](statement, context)
107107

108108

109-
def _ignore(_statement: Node, context: Context) -> List[str]:
109+
def _ignore(_statement: Node, _context: Context) -> List[str]:
110+
return []
111+
112+
113+
def _pass(_statement: Node, context: Context) -> List[str]:
110114
return [f"{context.indent_string}pass"]
111115

112116

tests/gd2py/input-output-pairs/class-level-statements.in.gd

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# misc
2-
tool
2+
@tool
33
extends Node
44
class_name ClassName
55
signal signal_name
@@ -11,19 +11,15 @@ var b = 1
1111
var c: int
1212
var d: int = 1
1313
var e := 1
14-
puppet var f = 1
15-
export(float) var aa
16-
onready var aaa
14+
var f = 1 # TODO: puppet
15+
@export(float) var aa
16+
@onready var aaa
1717

1818
# constants
1919
const A = 1
2020
const B: int = 1
2121
const C := 1
2222

23-
# docstrings
24-
"""asd"""
25-
26-
2723
# compounds
2824
class D:
2925
pass

tests/gd2py/input-output-pairs/class-level-statements.out.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
pass
33
pass
44
pass
5-
pass
65
a = None
76
b = 1
87
c = None
@@ -14,7 +13,6 @@
1413
A = 1
1514
B = 1
1615
C = 1
17-
"""asd"""
1816
class D:
1917
pass
2018
pass

tests/gd2py/test_input_output_pairs.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import os
22

33
import difflib
4-
import pytest
54

65
from gdtoolkit.gd2py import convert_code
76

@@ -18,7 +17,6 @@ def pytest_generate_tests(metafunc):
1817
)
1918

2019

21-
@pytest.mark.skip(reason="not supported yet")
2220
def test_input_output_pair(test_name):
2321
this_dir = os.path.dirname(os.path.abspath(__file__))
2422
input_file_path = os.path.join(this_dir, DATA_DIR, "{}.in.gd".format(test_name))

tests/gdradon/test_executable.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import subprocess
22

3-
import pytest
4-
53
from ..common import write_file
64

75

@@ -15,9 +13,8 @@ def test_cc_on_empty_file_succeeds(tmp_path):
1513
assert len(outcome.stderr.decode().splitlines()) == 0
1614

1715

18-
@pytest.mark.skip(reason="not supported yet")
1916
def test_cc_on_file_with_single_function_succeeds(tmp_path):
20-
dummy_file = write_file(tmp_path, "script.gd", "func foo(): pass")
17+
dummy_file = write_file(tmp_path, "script.gd", "func foo(): pass\n")
2118
outcome = subprocess.run(
2219
["gdradon", "cc", dummy_file], check=False, capture_output=True
2320
)

0 commit comments

Comments
 (0)