Skip to content

Commit 91e6a97

Browse files
committed
Fix dot-chain corner case, fixes #195
1 parent 81feaf3 commit 91e6a97

File tree

5 files changed

+20
-2
lines changed

5 files changed

+20
-2
lines changed

gdtoolkit/formatter/expression_to_str.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,8 +178,17 @@ def expression_to_str(expression: Node) -> str:
178178

179179
def _operator_chain_based_expression_to_str(expression: Tree) -> str:
180180
operator_expr_chain = zip(expression.children[1::2], expression.children[2::2])
181+
182+
def _padding(operator):
183+
return "" if operator.value == "." else " "
184+
181185
chain = [
182-
f" {expression_to_str(operator)} {expression_to_str(expr)}"
186+
"{}{}{}{}".format(
187+
_padding(operator),
188+
expression_to_str(operator),
189+
_padding(operator),
190+
expression_to_str(expr),
191+
)
183192
for operator, expr in operator_expr_chain
184193
]
185194
first_expr = expression.children[0]
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
class X:
22
func foo(xxxxxxxxxxx):
33
var x = xxxxxxxxxxx.y.z
4-
var y = xxxxxxxxxxx.yyyyyyyyyyyy.zzzzzzzzzzz.qqqqqqqqqqqqq.wwwwwwwwww.eeeeeeeeeeee.rrrrrrrrrrrrr
4+
var y = xxxxxxxxxxx.yyyyyyyyyyyy.zzzzzzzzzzz.qqqqqqqqqqqqq.wwwwwwwwww.eeeeeeeeeeee.rrrrrrrrrrrrr.tttttt
55
var z = xxxxxxxxxxx[[1,]].y.z.x[[1,]].c

tests/formatter/input-output-pairs/attribute-expressions.out.gd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ class X:
99
. wwwwwwwwww
1010
. eeeeeeeeeeee
1111
. rrrrrrrrrrrrr
12+
. tttttt
1213
)
1314
var z = (
1415
xxxxxxxxxxx[[
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
func _start_building_placement(building_prototype, Constants):
2+
var _active_blueprint_node = (
3+
load(Constants.BUILDING_BLUEPRINTS[building_prototype.resource_path]) . instantiate()
4+
)
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
func _start_building_placement(building_prototype, Constants):
2+
var _active_blueprint_node = (
3+
load(Constants.BUILDING_BLUEPRINTS[building_prototype.resource_path]).instantiate()
4+
)

0 commit comments

Comments
 (0)