Skip to content

Commit bd33b26

Browse files
committed
fix unique node paths handling, fixes #178
1 parent 396e5c7 commit bd33b26

File tree

8 files changed

+19
-2
lines changed

8 files changed

+19
-2
lines changed

gdtoolkit/formatter/expression_to_str.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,9 @@ def expression_to_str(expression: Node) -> str:
7777
"get_node": lambda e: f"${expression_to_str(e.children[0])}",
7878
"path": lambda e: "".join([name_token.value for name_token in e.children]),
7979
"node_path": lambda e: f"^{expression_to_str(e.children[0])}",
80+
"unique_node_path": lambda e: "".join(
81+
[expression_to_str(n) for n in e.children]
82+
),
8083
"string_name": lambda e: f"&{expression_to_str(e.children[0])}",
8184
# fake expressions:
8285
"func_args": _args_to_str,

gdtoolkit/formatter/expression_utils.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ def is_foldable(expression: Node) -> bool:
2222
"get_node",
2323
"node_path",
2424
"string_name",
25+
"unique_node_path",
2526
]
2627
and not expression.data.endswith("_pattern")
2728
)

gdtoolkit/parser/gdscript.lark

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -233,10 +233,12 @@ _simple_lambda_stmt: single_lambda_stmt (";" single_lambda_stmt)* [";"]
233233
| get_node
234234
| "^" string -> node_path
235235
| "&" string -> string_name
236+
| unique_node_path
236237
HEX.2: /-?0x[a-fA-F0-9][a-fA-F0-9_]*/
237238
BIN.2: /-?0b[01][01_]*/
238-
get_node: "$" (path | string)
239-
!path: ["%"] NAME ("/" NAME)*
239+
get_node: "$" (path | string | unique_node_path)
240+
!path: NAME ("/" NAME)*
241+
!unique_node_path: "%" path
240242
array: "[" [type_cast ("," type_cast)* [trailing_comma]] "]"
241243
trailing_comma: ","
242244
dict: "{" [c_dict_element ("," c_dict_element)* [trailing_comma]] "}"
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
extends Node
12
func foo():
23
# TODO: consider adding fake parenthesis
34
var cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc = ^"../Some/Stuff"
45
var dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd = &"xxx"
6+
var cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc = %UniqueNodeName/Xyz
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1+
extends Node
2+
3+
14
func foo():
25
# TODO: consider adding fake parenthesis
36
var cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc = ^"../Some/Stuff"
47
var dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd = &"xxx"
8+
var cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc = %UniqueNodeName/Xyz

tests/formatter/input-output-pairs/simple-atom-expressions.in.gd

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,5 @@ func foo():
1919
var e = &"xxx"
2020
var xa=$%UniqueNodeName
2121
var xb=$%UniqueNodeName/Xyz
22+
var xc=%UniqueNodeName
23+
var xd=%UniqueNodeName/Xyz

tests/formatter/input-output-pairs/simple-atom-expressions.out.gd

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,5 @@ func foo():
2020
var e = &"xxx"
2121
var xa = $%UniqueNodeName
2222
var xb = $%UniqueNodeName/Xyz
23+
var xc = %UniqueNodeName
24+
var xd = %UniqueNodeName/Xyz

tests/valid-gd-scripts/unique_node_name.gd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ extends Node
22

33
func foo():
44
var x = $%UniqueNodeName
5+
var y = %UniqueNodeName

0 commit comments

Comments
 (0)